cisco / ChezScheme

Chez Scheme
Apache License 2.0
6.97k stars 983 forks source link

Fixnum overflows with fxabs #713

Closed anttih closed 1 year ago

anttih commented 1 year ago

Fixnum overflows when called with (most-nagative-fixnum):

> (fxabs (most-negative-fixnum))
Exception in fxabs: fixnum overflow computing (fxabs -1152921504606846976)

This seems like a bug to me because fxabs doesn't take as argument a value that should be a valid fixnum.

melted commented 1 year ago

I think it's reasonable behavior, there is no positive fixnum of the same magnitude as most-negative-fixnum, so the error message is correct. It would be worse to return a bignum, in which case you'd have to check the type of the output of fxabs before using it in further fixnum operations.

gus-massa commented 1 year ago

All the fxsomethingfunctions raise an error in these cases like (fx+ (most-positive-fixnum) 1).

anttih commented 1 year ago

It's more obvious to me that normal operations (like addition) overflow. I was just a bit surprised that there is no valid positive fixnum for the most-negative-fixnum. But there is probably a good reason for this. Thanks!