Acos behaves differently on #s > 1.0 in TR?

In Typed Racket, the acos function appears to guarantee a Flonum result, and returns +0.nan for numbers larger than 1.0. This is different from Racket and Rhombus, that return a complex number. Is this difference documented? I went down a funny rabbit hole this afternoon when I ported a piece of code to TR to find a numerical error, managed to get it to type-check, then assumed that there must be some kind of bug in Rhombus. (Turned out the real problem was acos(1.0000002) ).

I bet Typed Racket turns acos on a Flonum into flacos under the hood. Pass it an explicitly created Float-Complex or cast to Number and you get the same type back, however:

> (acos 1.0000002+0.0i) ; literal number
- : Float-Complex
0.0-0.0006324555213263025i
> (acos (make-rectangular 1.0000002 0.0)) ; created at runtime
- : Float-Complex
0.0-0.0006324555213263025i
> (acos (cast 1.0000002 Number)) ; doesn't work with assert, or a cast to Float-Complex
- : Number
0.0+0.0006324555213263025i

Both the type and the optimization seem to be wrong. The case (Flonum -> Flonum) is wrong for flonums outside the range [-1.0, 1.0], and the optimization is wrong because unsafe-flacos shouldn’t be used. This makes the following program unsound:

#lang typed/racket/base #:no-optimize
(ann (acos 1.5) Flonum) ; result is 0.0+0.9624236501192069i, not a flonum

Yeah this looks like a clear bug (or bugs).

Many thanks, I've opened acos unsound in TR · Issue #1423 · racket/typed-racket · GitHub to help keep track of this.