From e8202b7fa3e612b97058445677aa2862f1a68c3a Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Wed, 13 May 2020 15:14:30 -0400 Subject: [PATCH] Change `tanh` to produce inexact values when approximating near 0. Since the approximation is that (tanh x) = x for small x, previously (tanh 1/10000000000000000000) produced an `exact?` answer, even though this is an approximation. Found by Typed Racket random testing: http://drdr.racket-lang.org/54493/racket/share/pkgs/typed-racket-test/tr-random-testing.rkt --- pkgs/racket-test-core/tests/racket/math.rktl | 1 + racket/collects/racket/math.rkt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/racket-test-core/tests/racket/math.rktl b/pkgs/racket-test-core/tests/racket/math.rktl index fce2674b71..85e1bf459e 100644 --- a/pkgs/racket-test-core/tests/racket/math.rktl +++ b/pkgs/racket-test-core/tests/racket/math.rktl @@ -329,6 +329,7 @@ (test 0 tanh 0) (test #t double=? tanh+1 (tanh 1)) (test 1.0 tanh 20) +(test #t flonum? (tanh (inexact->exact 1/100000000000))) #reader "maybe-single.rkt" (begin diff --git a/racket/collects/racket/math.rkt b/racket/collects/racket/math.rkt index 2f470151ad..50a0919ddc 100644 --- a/racket/collects/racket/math.rkt +++ b/racket/collects/racket/math.rkt @@ -73,7 +73,7 @@ [(real? z) (let loop ([z z]) (cond [(z . < . 0) (- (loop (- z)))] - [(z . < . 1.29047841397589243466D-08) z] + [(z . < . 1.29047841397589243466D-08) (exact->inexact z)] [(z . < . 0.54930614433405484570D+00) (define p0 -0.16134119023996228053D+04) (define p1 -0.99225929672236083313D+02)