We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
BigDecimal::INFINITY.round shouldn't cause FloatDomainError when BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY) == 0 but it raises the error.
BigDecimal::INFINITY.round
FloatDomainError
BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY) == 0
$ ruby -rbigdecimal -e "BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, false); BigDecimal::INFINITY.round" -e:1:in `round': Computation results in 'Infinity' (FloatDomainError) from -e:1:in `<main>'
The text was updated successfully, but these errors were encountered:
> BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, false); BigDecimal::INFINITY.round(1) # => Infinity
#round
If n is specified and negative, at least that many digits to the left of the decimal point will be 0 in the result, and return value will be an Integer. https://ruby-doc.org/stdlib-3.0.3/libdoc/bigdecimal/rdoc/BigDecimal.html#method-i-round
bigdecimal/ext/bigdecimal/bigdecimal.c
Lines 2316 to 2318 in 1cb0950
BigDecimal_to_i
always=1
Line 1062 in 1cb0950
mode
I believe it's an expected behaviour. All we could do is add a small note in the docs to be more explicit. WDYT @mrkn ?
Sorry, something went wrong.
Same happens for NaN, looks like another side effect of the same case:
NaN
irb(main):029:0> BigDecimal('NaN').round(1) => NaN irb(main):031:0> BigDecimal('NaN').round(0) (irb):31:in `round`: Computation results to 'NaN'(Not a Number) (FloatDomainError) irb(main):032:0> BigDecimal('NaN').round(-1) (irb):32:in `round`: Computation results to 'NaN'(Not a Number) (FloatDomainError)
No branches or pull requests
BigDecimal::INFINITY.round
shouldn't causeFloatDomainError
whenBigDecimal.mode(BigDecimal::EXCEPTION_INFINITY) == 0
but it raises the error.The text was updated successfully, but these errors were encountered: