# Author rhettinger mark.dickinson, rhettinger, steven.daprano, tim.peters 2021-11-25.00:37:05 -1.0 Yes <1637800625.26.0.490135737793.issue45876@roundup.psfhosted.org>
Content
```> Here's a reference for this use of round-to-odd:
> https://www.lri.fr/~melquion/doc/05-imacs17_1-expose.pdf

Thanks Mark.  It looks like I'll be getting a little education over the Thanksgiving holiday :-)

Shown below is the code that I'm thinking of using to test for correct rounding.  Is this the right way to do it?

# Verify correct rounding.  Find exact values for half the distance
# to the two adjacent representable floats.  The unrounded function
# input should fall between the exact squares of those values.

for i in range(10_000_000):
numerator: int = randrange(10 ** randrange(40)) + 1
denonimator: int = randrange(10 ** randrange(40)) + 1
x: Fraction = Fraction(numerator, denonimator)

root: float = sqrt_frac(numerator, denonimator)

r_up: float = math.nextafter(root, math.inf)
half_way_up: Fraction = (Fraction(root) + Fraction(r_up)) / 2
half_way_up_squared: Fraction = half_way_up ** 2

r_down: float = math.nextafter(root, -math.inf)
half_way_down: Fraction = (Fraction(root) + Fraction(r_down)) / 2
half_way_down_squared: Fraction = half_way_down ** 2

assert r_down < root < r_up
assert half_way_down_squared <= x <= half_way_up_squared```
History
Date User Action Args
2021-11-25 00:37:05rhettingersetrecipients: + rhettinger, tim.peters, mark.dickinson, steven.daprano
2021-11-25 00:37:05rhettingersetmessageid: <1637800625.26.0.490135737793.issue45876@roundup.psfhosted.org>