Exact rational scaling by powers of two #
Binary formats repeatedly need the same small collection of exact operations: locate a positive rational between consecutive powers of two, move a binary exponent into a numerator or denominator, and compare a signed rational with a dyadic without constructing an enormous shifted integer.
These operations belong to the exact numerical layer rather than to any one floating-point format. IEEE interchange, P3109, posits, and application-defined binary quantizers may therefore share them without importing one another's encoding or exceptional-value policy.
Test numerator / denominator < 2^exponent for a positive denominator, using integers.
Instances For
Nonnegative exponents shift the denominator in the strict comparison.
A natural exponent shifts the denominator in the strict comparison.
Negative exponents shift the numerator in the strict comparison.
Test numerator / denominator ≥ 2^exponent for a positive denominator, using integers.
Instances For
Nonnegative exponents shift the denominator in the non-strict comparison.
A natural exponent shifts the denominator in the non-strict comparison.
Negative exponents shift the numerator in the non-strict comparison.
Compute ⌊log₂(numerator / denominator)⌋.
The intended mathematical preconditions are positive numerator and denominator. Keeping the kernel total makes it convenient inside executable quantizers; proofs establish the preconditions where logarithmic bounds are used.
Instances For
Represent (numerator / denominator) * 2^exponent as a ratio of natural numbers.
Positive exponents shift the numerator and negative exponents shift the denominator. No division or approximation occurs.
Instances For
Scaling by a nonnegative exponent shifts only the numerator.
Scaling by a natural exponent shifts only the numerator.
Scaling by 2^0 leaves both sides of the exact quotient unchanged.
Scaling by a negative exponent shifts only the denominator.
A nonzero numerator remains nonzero after exact binary scaling.
A nonzero denominator remains nonzero after exact binary scaling.
Compare (numerator / denominator) * 2^exponent, with the supplied sign, against a dyadic.
A zero denominator returns none. After multiplying the denominator by the dyadic significand,
a leading-position test often decides the result. Only equal leading positions require exponent
alignment; that shift is then bounded by the integer operand widths.