Dyadic helpers for executable IEEE32 arithmetic.
This file contains the integer/rational scaffolding used to describe binary significands, exponents, and exact dyadic values before rounding to IEEE32.
Instances For
Instances For
Round n / 2^shift to nearest, ties-to-even.
This is the primitive "shift + rounding" operation we use when shrinking a mantissa back down to a fixed bit width. It is the same tie-breaking policy as IEEE round-to-nearest-even.
Instances For
Decode a finite binary32 into an exact dyadic value.
Returns none for NaN/Inf.
Instances For
Rounding back to binary32 #
The general pattern for the finite ops in this file is:
- decode float32(s) to an exact intermediate representation (
Dyadicfor+ - * fma sqrt, rationals for/), - compute the exact result in that intermediate representation,
- round once to float32 using round-to-nearest, ties-to-even.
Round an exact dyadic value to binary32 (ties-to-even).
This function implements:
- overflow to ±Inf,
- gradual underflow into subnormals (down to exponent
-149), - underflow-to-zero below
2^-150(half the minimum subnormal, where ties-to-even chooses 0), - mantissa rounding to the 24-bit precision of binary32 normal numbers.
Instances For
Exact dyadic arithmetic (finite core) #
Dyadic is closed under + and * (at the exact level). We use these helpers before rounding
back to float32.
Exact dyadic addition.
We align exponents by shifting the mantissa of the operand with the larger exponent, add signed integers, and then return an exact dyadic (no rounding yet).
Instances For
Exact rationals for division #
For division we compute an exact rational num/den (with den > 0) and then round it to binary32
using round-to-nearest, ties-to-even.
Round num/den to nearest, ties-to-even (assumes den > 0).
Instances For
Test whether num/den < 2^k without converting to reals.
Instances For
Test whether num/den ≥ 2^k without converting to reals.
Instances For
Compute ⌊log₂(num/den)⌋ as an Int (assumes num > 0 and den > 0).
We start from the initial estimate log2(num) - log2(den) and then adjust by checking against
powers of two.
Instances For
Round an exact rational num/den to binary32 (ties-to-even).
This is the division analogue of roundDyadicToIEEE32: it uses the same exponent thresholds and
the same final mantissa rounding policy.