typed-racket icon indicating copy to clipboard operation
typed-racket copied to clipboard

random numeric testing failures

Open samth opened this issue 4 years ago • 3 comments

  • (exp (make-rectangular 1.7976931348623153e+308 0.0))
  • http://drdr.racket-lang.org/55871/cs/racket/share/pkgs/typed-racket-test/tr-random-testing.rkt
  • http://drdr.racket-lang.org/56100/cs/racket/share/pkgs/typed-racket-test/tr-random-testing.rkt
  • http://drdr.racket-lang.org/56136/cs/racket/share/pkgs/typed-racket-test/tr-random-testing.rkt
  • http://drdr.racket-lang.org/56154/cs/racket/share/pkgs/typed-racket-test/tr-random-testing.rkt (2 here)
  • http://drdr.racket-lang.org/56432/racket/share/pkgs/typed-racket-test/tr-random-testing.rkt

samth avatar Feb 11 '21 18:02 samth

About the last one (6)

I found a minimized version:

> (/ (min 0.0 0))
- : Real [more precisely: Nonpositive-Real]
+inf.0

I think the problem is in https://github.com/racket/typed-racket/blob/6ea20bec8d41e1a188d7f831c35423293a89c98e/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt#L1234 because 0.0 is a -NonPosReal, but +inf.0 isn't.

gus-massa avatar Oct 10 '21 13:10 gus-massa

About the second example in the second to last case (5b)

I found a minimized version:

(- (expt 10 309) +inf.0)        ;==> +nan.0 in typed  but -inf.0 in untyped

The problem is that in some optimization step (expt 10 309) is converted to a flonum, in this case +inf.0 so the expression is equivalent to (- +inf.0 +inf.0). I don't have any clue where the error is, but it's possible to construct similar examples with other operation, so my guess it's a shared code.

Note that the problem disappears replacing 309 with 307, because 1e307 is a normal flonum.

#lang typed/racket

(exact->inexact (expt 10 309))  ;==> +inf.0 (correct)
(- (expt 10 309) +inf.0)        ;==> +nan.0
(- (- (expt 10 309)) -inf.0)    ;==> +nan.0
(+ (expt 10 309) -inf.0)        ;==> +nan.0
(+ (- (expt 10 309)) +inf.0)    ;==> +nan.0
(* (expt 10 309) 0.0)           ;==> +nan.0
(/ +inf.0 (expt 10 309))        ;==> +nan.0
(/ (expt 10 309) 1.0)           ;==> +inf.0

(newline)

(exact->inexact (expt 10 307))  ;==> 1e+307
(- (expt 10 307) +inf.0)        ;==> -inf.0
(- (- (expt 10 307)) -inf.0)    ;==> +inf.0
(+ (expt 10 307) -inf.0)        ;==> -inf.0
(+ (- (expt 10 307)) +inf.0)    ;==> +inf.0
(* (expt 10 307) 0.0)           ;==>    0.0
(/ +inf.0 (expt 10 307))        ;==> +inf.0
(/ (expt 10 307) 1.0)           ;==> 1e+307

gus-massa avatar Oct 11 '21 02:10 gus-massa

Again (5b) again:

The problem is that (- (expt 10 307) +inf.0) is transformed to (unsafe-fl- (->fl (expt 10 307)) +inf.0). My guess is that https://github.com/racket/typed-racket/blob/master/typed-racket-lib/typed-racket/optimizer/float.rkt#L126-L146 need also special cases for infinity.

gus-massa avatar Oct 12 '21 21:10 gus-massa