Skip to content

Commit 3246075

Browse files
committed
1 parent a4a07dc commit 3246075

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

typed-racket-test/external/tr-random-testing.rkt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
(define (safe-arithmetic-shift a b)
2626
(if (> b 100000) b (arithmetic-shift a b)))
2727

28+
;; expt with large exact exponents can produce numbers with trillions of digits,
29+
;; e.g. (expt 2 (expt -19 11)) tries to compute 2^(-116490258898219)
30+
(define (safe-expt a b)
31+
(if (> (abs b) 10000) b (expt a b)))
32+
2833
(define-language tr-arith
2934
[n real]
3035
;; randomly generate F, not E, because literal numbers self-evaluate
@@ -151,9 +156,9 @@
151156
(sinh E*)
152157
(cosh E*)
153158
(tanh E*)
154-
(expt E* E*)]
159+
(safe-expt E* E*)]
155160
[INEQ < <= >= >]
156-
[R n (+ R R) (- R R) (* R R) (expt R R)]
161+
[R n (+ R R) (- R R) (* R R) (safe-expt R R)]
157162
[C (let ([x R] [y R]) (if (INEQ x y) x #f))
158163
(let ([x R] [y R]) (if (INEQ x y) #f x))
159164
(let ([x R] [y R]) (if (INEQ x y) y #f))

0 commit comments

Comments
 (0)