Skip to content
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

$decimal->toInt() for -INF, INF, NAN give not correct result (zero) #11

Closed
FoxKeys opened this issue Feb 6, 2019 · 4 comments
Closed

Comments

@FoxKeys
Copy link

FoxKeys commented Feb 6, 2019

Hello again.

I have found that $decimal->toInt() return 0 for -INF, INF and NAN.
I suppose, this is wrong. OverflowException seems to be correct for +-INF. And another exception (Invalid_Operation?) for NAN

@rtheunissen
Copy link
Contributor

rtheunissen commented Feb 6, 2019

This is intended, as it matches PHP behaviour.

See: https://3v4l.org/oLkmS

Ref: https://github.com/php-decimal/ext-decimal/blob/master/php_decimal.c#L780

@rtheunissen
Copy link
Contributor

Leaving this open because I am not convinced that matching PHP behaviour is the right way to go here. Thanks for bringing this up. 👍

@FoxKeys
Copy link
Author

FoxKeys commented Feb 6, 2019

I think PHP-way looks not relevant int this case.

You throw OverflowException if the value is greater than PHP_INT_MAX (this seems ok). But, +INF is greater than PHP_INT_MAX. Therefore, +INF must give overfloaw too. Same for -INF, i suppose.

@rtheunissen
Copy link
Contributor

This has been fixed in b1e0162 and released as v1.2.0 ✨

Throws RuntimeException for INF, -INF and NAN.

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

No branches or pull requests

2 participants