-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is signum(NAN) === 1 conform IEEE? #10
Comments
I believe it should return NaN. I'm not aware of any definition around this by IEEE, but it seems like all other implementations return NaN. |
I have found this |
That is the library we're using. 😊 I don't see any mention of sign in the docs though. The only mention of sign in the source is in these functions: /* 0 if dec is positive, 1 if dec is negative */
ALWAYS_INLINE uint8_t
mpd_sign(const mpd_t *dec)
{
return dec->flags & MPD_NEG;
}
/* 1 if dec is positive, -1 if dec is negative */
ALWAYS_INLINE int
mpd_arith_sign(const mpd_t *dec)
{
return 1 - 2 * mpd_isnegative(dec);
} It makes sense that NaN returns NaN because it is not zero, not positive, and not negative. Throwing an exception seems strange though - the caller should handle the NaN according to its domain. |
I know, but i can't understand this: "result is set to NaN and INT_MAX is returned." If signum return NAN - it can be a problem, because function signature is" ->signum(): int", but NAN is not int. Or i mistake? |
That is the
You are absolutely right, which makes it tricky. We have some options here because the 2.0 branch is just about ready to go. A) Change the return type to I'm leaning towards B because there is value in being able to rely on an integer return value, and it seems extremely unlikely that querying the sign of NaN is intended. If that is the case, the caller can catch the exception and do nothing with it. This puts the responsibility on the caller/domain to handle NaN, rather than the library. Something like this:
|
I'm not expert in decimal math, but option "B" seems best for PHP-way. |
This has been fixed in b1e0162 and released as v1.2.0 ✨ Throws |
Have a question.
->signum(NAN) returns 1.
Is this correct and conform IEEE? Or, maybe, must throw an exception?
The text was updated successfully, but these errors were encountered: