justinethier / cyclone

:cyclone: A brand-new compiler that allows practical application development using R7RS Scheme. We provide modern features and a stable system capable of generating fast native binaries.
http://justinethier.github.io/cyclone/
MIT License
823 stars 42 forks source link

`exact` applied to NaNs and infinites returns `-2147483648` #510

Closed jpellegrini closed 11 months ago

jpellegrini commented 1 year ago

Hi! Maybe it would be nice to signal an error instead?

(exact +inf.0) => -2147483648
(exact +nan.0) => -2147483648

otherwise, weird things like the following will happen...

(integer? (exact +inf.0)) => #t        ; a finite infinity!
justinethier commented 1 year ago

Thanks for the report! I agree this would be a better behavior.

We could also do a better job computing exact for large double's. These should be converted to bignums if they are outside the fixnum range.

jpellegrini commented 1 year ago

We could also do a better job computing exact for large double's. These should be converted to bignums if they are outside the fixnum range.

That would be great!

Also, since you mentioned, I see that Cyclone has a bignum? predicate, but not fixnum?. Maybe it would be nice to have the latter too?

justinethier commented 1 year ago

There is a fixnum? procedure, though it is a bit buried in SRFI 143 rather than always being included in the REPL environment: https://github.com/justinethier/cyclone/blob/master/docs/api/srfi/143.md

jpellegrini commented 1 year ago

There is a fixnum? procedure, though it is a bit buried in SRFI 143 rather than always being included in the REPL environment: https://github.com/justinethier/cyclone/blob/master/docs/api/srfi/143.md

Isn't it convenient / useful enough to have in the REPL environment? (Not really complaining -- it it's there, it's good enough already!)

justinethier commented 11 months ago

Added code to signal an error when exact receives a NAN or infinite value.

Also tightened up support for other types of edge cases involving doubles, bignums, and complex numbers.

jpellegrini commented 11 months ago

Yes, I've just tested and it works fine here! Thanks! I guess this PR can be closed...