# Acos behaves differently on #s \> 1.0 in TR?

**URL:** <https://racket.discourse.group/t/acos-behaves-differently-on-s-1-0-in-tr/3453>\
**Category:** General\
**Created:** [December 29, 2024, 3:14am UTC](https://racket.discourse.group/t/acos-behaves-differently-on-s-1-0-in-tr/3453 "2024-12-29T03:14:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [December 29, 2024, 3:14am UTC](https://racket.discourse.group/t/acos-behaves-differently-on-s-1-0-in-tr/3453/1 "2024-12-29T03:14:23Z")

</div>

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) ).

---

<div class="post-metadata">

**Author:** ![shawnw](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/shawnw/32/1031_2.png) [@shawnw](https://racket.discourse.group/u/shawnw)\
**Post date:** [December 29, 2024, 4:33am UTC](https://racket.discourse.group/t/acos-behaves-differently-on-s-1-0-in-tr/3453/2 "2024-12-29T04:33:01Z")

</div>

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:

```scheme
> (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

```

---

<div class="post-metadata">

**Author:** ![usao](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/usao/32/1375_2.png) [@usao](https://racket.discourse.group/u/usao)\
**Post date:** [December 29, 2024, 7:18am UTC](https://racket.discourse.group/t/acos-behaves-differently-on-s-1-0-in-tr/3453/3 "2024-12-29T07:18:45Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![samth](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/samth/32/3_2.png) [@samth](https://racket.discourse.group/u/samth)\
**Post date:** [December 31, 2024, 12:05am UTC](https://racket.discourse.group/t/acos-behaves-differently-on-s-1-0-in-tr/3453/4 "2024-12-31T00:05:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [December 31, 2024, 1:03pm UTC](https://racket.discourse.group/t/acos-behaves-differently-on-s-1-0-in-tr/3453/5 "2024-12-31T13:03:39Z")

</div>

Many thanks, I've opened [acos unsound in TR · Issue #1423 · racket/typed-racket · GitHub](https://github.com/racket/typed-racket/issues/1423) to help keep track of this.
