Results for “Precise numeric calculations”
Small, practical examples. Search by task or narrow things down below.
Calculate beyond the long integer range
Java: Use BigInteger when a fixed-width primitive type would overflow.
Java✓ Tested
Compare floating-point results with a tolerance
Java: For this bounded example, compare the absolute difference against a chosen error threshold.
Java✓ 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
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
Calculate each group’s numeric spread
SQL: Subtract MIN from MAX to report the difference between extremes.
SQL✓ Tested
Calculate each group’s numeric spread
SQL Server: Subtract MIN from MAX to report the difference between extremes.
SQL Server✓ Tested