Results for “Numeric parsing & calculations”
Small, practical examples. Search by task or narrow things down below.
Compare small floating-point results with a tolerance
C: Use an absolute difference threshold for this known bounded magnitude.
C✓ Tested
Compute a two-dimensional vector length
C: hypot avoids unnecessary intermediate overflow compared with squaring both inputs directly.
C✓ Tested
Detect integer addition overflow
Java: Math.addExact throws rather than silently wrapping on overflow.
Java✓ Tested
Display an integer as unsigned
Java: Use unsigned conversion methods when interpreting a fixed-width bit pattern.
Java✓ Tested
Divide decimal values with controlled precision
Java: Choose both scale and rounding for a quotient that does not terminate in base ten.
Java✓ Tested
Divide negative integers with floor rounding
Java: floorDiv and floorMod provide consistent floor-based quotient and remainder.
Java✓ Tested
Find the greatest common divisor
Java: BigInteger.gcd calculates an exact nonnegative common divisor.
Java✓ Tested
Parse an integer in another base
Java: Supply an explicit radix to Integer.parseInt.
Java✓ Tested
Parse an unsigned hexadecimal integer
C: Use an explicit base and check both range and full consumption.
C✓ Tested
Reject NaN and infinite values
C: isfinite detects whether a floating-point value is an ordinary finite number.
C✓ Tested
Reject nonfinite floating-point values
Java: Double.isFinite excludes both infinity and NaN.
Java✓ Tested
Round a decimal with an explicit rule
Java: Construct BigDecimal from text to avoid importing a binary floating-point approximation.
Java✓ Tested