Skip to content

Conversation

@gus-massa
Copy link
Contributor

In expressions like (+ -inf.0 x), where x is known to be real, it's not possible to transform it into (fl+ -inf.0 (real->flonum x)) in case x is a bignum that is transformed into +inf.0.

The problem with this incorrect transformation the result is+nan.0 instead of -inf.0. So I added more restrictions to check before this transformation is applied.


Backstory: I was brute-force-testing div, mod, and a few more similar primitives, with combinations of two numbers from a long list of interesting tricky numbers. Then I decided to add + and - to the list of primitives to test. I found that

(+ -inf.0 #e1e1000)

had a different result when cptypes was applied before cp0.

((eval '(lambda () (+ -inf.0 #e1e1000))))  ;==> -inf.0

((eval (parameterize ([run-cp0 (lambda (cp0 x)
                                  (cp0 (#3%$cptypes x)))])
                     (expand/optimize '(lambda () (+ -inf.0 #e1e1000))))))  ;==> +nan.0

Avoid transforming an expression like `(+ -inf.0 x)`, where
`x` is known to be real, into `(fl+ -inf.0 (real->flonum x))`
in case `x` is a bignum that would be converted into `+inf.0`.

With this incorrect tranformation the result is
`+nan.0` instead of `-inf.0`.

The compiler avoid transforming an expression like \scheme{(+ -inf.0 x)} where
\scheme{x} is known to be real, into \scheme{(fl+ -inf.0 (real->flonum x))}
in case \scheme{x} is a bignum that is tranformed into \scheme{+inf.0}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"avoid" -> "avoids", maybe a comma before "where", and "tranformed" (missing an "s") -> "converted" or maybe "would be converted"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Also fixed the commit message that had similar problems.

@mflatt mflatt merged commit ce978f1 into cisco:main Feb 3, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants