The rounding of the doubles of the model #
Ratpoints.Double.ofRatio and Ratpoints.Double.ofDyadic, the doubles nearest to ±n / d and to
±m 2 ^ e, which strtod and the conversions of the model compute, are never a NaN
(Ratpoints.Double.isNaN_ofRatio, Ratpoints.Double.isNaN_ofDyadic), and a finite result is a
faithful rounding: the number lies strictly between the neighbours nextDown x and nextUp x of
the result x (Ratpoints.Double.lt_nextUp_and_nextDown_lt_ofRatio,
Ratpoints.Double.lt_nextUp_and_nextDown_lt_ofDyadic), so that no double other than x lies
between x and the number. This is what the program needs of strtod: the end of a search
interval that it moves outward to a double from the double that strtod reads lands on the
nearest double on its side. The successor of the double of a height bound 1 ≤ H < 2 ^ 63 is
finite and above H (Ratpoints.Double.isFinite_ofInt64_and_lt_toRat_nextUp), which gives the
bound h of the default search interval [-h, h]
(Ratpoints.Double.isFinite_and_le_toRat_ofInt64_nextUp).
The proof goes through the significand M and the exponent q of its last place that both
functions round to, M 2 ^ q within half a unit 2 ^ (q - 1) of the number
(Ratpoints.Double.ofRatio_rounding, Ratpoints.Double.ofDyadic_rounding), and the last step that
both take, the carry at 2 ^ 53 and the bits of the double (Ratpoints.Double.ofSignificand and
Ratpoints.Double.assemble of the model, the fields of the result by
Ratpoints.Double.fields_assemble), whose neighbours have the values of the magnitudes next to that
of the result, in units of 2 ^ (-1074) (Ratpoints.Double.magnitudeUnits_fields_succ,
Ratpoints.Double.lt_nextUp_and_nextDown_lt).
Main definitions #
Ratpoints.Double.roundDiv,Ratpoints.Double.ratioExponent,Ratpoints.Double.ratioPair,Ratpoints.Double.ratioLast: the rounding of a quotient and the exponents ofRatpoints.Double.ofRatio.
Main statements #
Ratpoints.Double.lt_nextUp_and_nextDown_lt_ofRatio,Ratpoints.Double.lt_nextUp_and_nextDown_lt_ofDyadic: the faithful rounding.Ratpoints.Double.isNaN_ofRatio,Ratpoints.Double.isNaN_ofDyadic: no NaN.Ratpoints.Double.isFinite_and_le_toRat_ofInt64_nextUp: the double of1 ≤ H < 2 ^ 63, moved up to the next double when it is below2 ^ 63and its conversion to alongbelowH, is finite and at leastH.
The neighbours of a finite double #
The units of 2 ^ (-1074) between the values of the consecutive magnitudes with the
exponent field E and the fraction F and the next: 2 ^ (E - 1) for E ≥ 1, and 1 for
E = 0, also where the fraction carries into the exponent.
A positive rational number v strictly between the values of the magnitudes k - 1 and
k + 1 next to the magnitude k of a finite double x, in units of 2 ^ (-1074), lies, with
the sign of x, strictly between the values of nextDown x and nextUp x.
Finite, infinite and neighbouring doubles #
The last step of ofRatio and ofDyadic #
The magnitudes next to an assembled double #
The value of the magnitude below that of a normal double M 2 ^ q: half a unit 2 ^ q lower
at the bottom of a binade (M = 2 ^ 52, above the least exponent), a unit lower otherwise.
A subnormal or zero x = ±M 2 ^ (-1074) (M < 2 ^ 52) and a positive v within less than
2 ^ (-1074) of M 2 ^ (-1074): the neighbours of x lie on either side of ±v.
A normal x = ±M 2 ^ q (2 ^ 52 ≤ M < 2 ^ 53) and a positive v below (M + 1) 2 ^ q and
above the value of the magnitude below that of x: the neighbours of x lie on either side of
±v.
Faithful rounding of a significand #
The double of a significand M ≤ 2 ^ 53 rounded from a positive v to within half a unit of
the exponent q ≥ -1074 of its last place, with v ≥ 2 ^ (q + 52) when q is not the least
exponent, is a faithful rounding of ±v when it is finite.
Rounding to the nearest integer #
a / b rounded to the nearest integer, ties to even, as Ratpoints.Double.ofRatio rounds
the quotient of a and b ≠ 0: the remainder r decides, rounding up when 2 r > b and when
2 r = b and the quotient is odd.
Equations
Instances For
ofRatio #
The exponent E with 2 ^ E ≤ n / d < 2 ^ (E + 1) that Ratpoints.Double.ofRatio finds
from the lengths of n and d in bits and one comparison
(Ratpoints.Double.ratioExponent_bounds).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The exponent of the last place of the double that Ratpoints.Double.ofRatio rounds n / d
to: Ratpoints.Double.ratioExponent n d - 52, and -1074 for the subnormals.
Equations
- Ratpoints.Double.ratioLast n d = max (Ratpoints.Double.ratioExponent n d - 52) (-1074)
Instances For
The significand M and the exponent q of its last place that Ratpoints.Double.ofRatio
rounds n / d to: M ≤ 2 ^ 53, q ≥ -1074, M 2 ^ q within half a unit 2 ^ (q - 1) of
n / d, and n / d ≥ 2 ^ (q + 52) when q is not the least exponent.
Ratpoints.Double.ofRatio rounds faithfully: when it is finite, ±n / d lies strictly
between the neighbours of the result.
ofDyadic #
The significand M and the exponent q of its last place that Ratpoints.Double.ofDyadic
rounds m 2 ^ e to: M ≤ 2 ^ 53, q ≥ -1074, M 2 ^ q within half a unit 2 ^ (q - 1) of
m 2 ^ e, and m 2 ^ e ≥ 2 ^ (q + 52) when q is not the least exponent.
Ratpoints.Double.ofDyadic rounds faithfully: when it is finite, ±m 2 ^ e lies strictly
between the neighbours of the result.
The double of the height bound #
The double of 1 ≤ H < 2 ^ 63 is finite, with the sign bit clear, and the next double is finite
and above H.
The double of 1 ≤ H < 2 ^ 63, moved up to the next double when it is below 2 ^ 63 and its
conversion to a long is below H, is finite and at least H: the bound h of the default
search interval [-h, h] of Ratpoints.searchIntervals, and Ratpoints.Cli.heightEnd.