Results for “numbers”
Small, practical examples. Search by task or narrow things down below.
Reject NaN and infinite numeric inputs
Python: Use isfinite before computations that require an ordinary finite float.
Python✓ Tested
Round a decimal using an explicit midpoint rule
C#: Use decimal literals for decimal arithmetic and choose the midpoint rounding behavior.
C#✓ Tested
Round and format a decimal value
Round and format a decimal value in a complete Rust program using the standard library.
Rust✓ Tested
Round decimal amounts explicitly
Python: Build Decimal values from strings and choose a rounding rule explicitly.
Python✓ Tested
Saturate arithmetic at the type boundary
Saturate arithmetic at the type boundary in a complete Rust program using the standard library.
Rust✓ Tested
Select the largest values without sorting everything
Python: Use heapq.nlargest when only a small prefix of the ranking is required.
Python✓ Tested
Subtract durations without underflow
Subtract durations without underflow in a complete Rust program using the standard library.
Rust✓ Tested
Use a nonnegative remainder for cyclic indexing
Use a nonnegative remainder for cyclic indexing in a complete Rust program using the standard library.
Rust✓ Tested
Validate a finite numeric value without coercion
JavaScript: Number.isFinite rejects numeric strings as well as NaN and infinity.
JavaScript✓ Tested
Validate a finite numeric value without coercion
TypeScript: Number.isFinite rejects numeric strings as well as NaN and infinity.
TypeScript✓ Tested
Add days to a date
Parse an ISO date and add calendar days using Java LocalDate.
Java✓ Tested
Allocate a zeroed array
Check calloc, use the allocation, and release it in C.
C✓ Tested