fix directed rounding for sqrt

This commit is contained in:
Fredrik Johansson
2007-10-02 16:54:29 +00:00
parent e3a2c42aea
commit b9ec9a7e75
2 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -616,7 +616,7 @@ def fsqrt(s, prec=STANDARD_PREC, rounding=ROUND_HALF_EVEN):
else:
man = _sqrt_fixed2(man, prec2)
return normalize(man, (exp+shift-prec2)//2, prec, ROUND_HALF_EVEN)
return normalize(man, (exp+shift-prec2)//2, prec, rounding)
def fhypot(x, y, prec=STANDARD_PREC, rounding=ROUND_HALF_EVEN):
+12
View File
@@ -229,6 +229,18 @@ def test_exact_sqrts():
assert sqrt(mpf((a*a, 2*i))) == mpf((a, i))
assert sqrt(mpf((a*a, -2*i))) == mpf((a, -i))
def test_sqrt_rounding():
for i in [2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15]:
for dps in [7, 15, 83, 106, 2000]:
mpf.dps = dps
mpf.round_down()
assert (mpf(i)**0.5)**2 < i
mpf.round_up()
assert (mpf(i)**0.5)**2 > i
mpf.dps = 15
mpf.round_default()
#----------------------------------------------------------------------------
# Type comparison