fix `expt' on small negative number and large positive odd

The pow() function apparently gets it wrong on some platforms.

Closes PR 13391
This commit is contained in:
Matthew Flatt 2013-01-01 12:31:24 -07:00
parent 974350472c
commit 07d5a9e385
3 changed files with 15 additions and 1 deletions

View File

@ -406,6 +406,7 @@
(define focus-here? #f)
(define/override (on-focus? on?)
(unless on? (on-menu-click))
(on-focus-child on?)
(cond
[on?

View File

@ -548,6 +548,10 @@
(test (- (expt 5 29)) min (- (expt 5 29)) (expt 5 27))
(test (- (expt 5 29)) min (- (expt 5 27)) (- (expt 5 29)))
(test (- (expt 5 29)) min (- (expt 5 29)) (- (expt 5 27)))
(test 0.0 expt -0.1 10000000000000.0)
(test -0.0 expt -0.1 10000000000001.0)
(test 0.0 expt -0.0 10000000000000.0)
(test -0.0 expt -0.0 10000000000001.0)
(err/rt-test (max 0 'a))
(err/rt-test (min 0 'a))

View File

@ -2729,7 +2729,16 @@ static double sch_pow(double x, double y)
return scheme_infinity_val;
}
} else {
return protected_pow(x, y);
double r;
r = protected_pow(x, y);
if ((r == 0.0) && !minus_zero_p(r)) {
/* check large odd power of a small negative number,
which some libraries get wrong for some reason */
if ((x < 0) && (fmod(y, 2.0) == 1.0)) {
r = scheme_floating_point_nzero;
}
}
return r;
}
}
#endif