FIND YOUR NEXT FEW LINES

Results for “numbers”

Small, practical examples. Search by task or narrow things down below.

80 snippets foundClear filters
PythonNumbers & calculations

Reject NaN and infinite numeric inputs

Python: Use isfinite before computations that require an ordinary finite float.

Python✓ Tested
C#Dates & precise numbers

Round a decimal using an explicit midpoint rule

C#: Use decimal literals for decimal arithmetic and choose the midpoint rounding behavior.

C#✓ Tested
RustNumbers & durations

Round and format a decimal value

Round and format a decimal value in a complete Rust program using the standard library.

Rust✓ Tested
PythonNumbers & calculations

Round decimal amounts explicitly

Python: Build Decimal values from strings and choose a rounding rule explicitly.

Python✓ Tested
RustNumbers & durations

Saturate arithmetic at the type boundary

Saturate arithmetic at the type boundary in a complete Rust program using the standard library.

Rust✓ Tested
PythonNumbers & calculations

Select the largest values without sorting everything

Python: Use heapq.nlargest when only a small prefix of the ranking is required.

Python✓ Tested
RustNumbers & durations

Subtract durations without underflow

Subtract durations without underflow in a complete Rust program using the standard library.

Rust✓ Tested
RustNumbers & durations

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
JavaScriptNumbers & numeric validation

Validate a finite numeric value without coercion

JavaScript: Number.isFinite rejects numeric strings as well as NaN and infinity.

JavaScript✓ Tested
TypeScriptNumbers & numeric validation

Validate a finite numeric value without coercion

TypeScript: Number.isFinite rejects numeric strings as well as NaN and infinity.

TypeScript✓ Tested
JavaNumbers & dates

Add days to a date

Parse an ISO date and add calendar days using Java LocalDate.

Java✓ Tested
CNumbers & memory

Allocate a zeroed array

Check calloc, use the allocation, and release it in C.

C✓ Tested