FIND YOUR NEXT FEW LINES

Results for “ratio”

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

305 snippets foundClear filters
C++Filesystem operations

Calculate a lexical relative path

C++: lexically_relative compares path components without requiring the paths to exist.

C++✓ Tested
CSmall algorithms & bit operations

Calculate a small factorial iteratively

C: Multiply a bounded sequence using an unsigned accumulator.

C✓ Tested
CSmall algorithms & bit operations

Calculate an average without integer division truncation

C: Accumulate into double and divide by the nonzero number of readings.

C✓ Tested
PythonIteration & sequences

Calculate cumulative totals

Python: Use accumulate to retain the running sum after each input.

Python✓ Tested
CSmall algorithms & bit operations

Calculate the greatest common divisor

C: Euclid’s algorithm repeatedly replaces a pair with the divisor and remainder.

C✓ Tested
Bash ScriptsArray operations

Check exact array membership

Bash Scripts: Compare each element literally instead of searching a concatenated string.

Bash Scripts✓ Tested
RustNumbers & durations

Check whether a floating-point value is finite

Check whether a floating-point value is finite in a complete Rust program using the standard library.

Rust✓ Tested
C++Ordering & set operations

Check whether a range is already sorted

C++: is_sorted reports ordering without modifying the input.

C++✓ Tested
RustNumbers & durations

Clamp a number to a valid interval

Clamp a number to a valid interval in a complete Rust program using the standard library.

Rust✓ Tested
JavaScriptPromises & iteration protocols

Clean up a generator after an early break

JavaScript: Breaking a for-of loop closes a generator and runs its finally block.

JavaScript✓ Tested
TypeScriptPromises & iteration protocols

Clean up a generator after an early break

TypeScript: Breaking a for-of loop closes a generator and runs its finally block.

TypeScript✓ Tested
PythonFile operations & archives

Clean up a temporary directory automatically

Python: Use TemporaryDirectory as a context manager so cleanup also happens after exceptions.

Python✓ Tested