[ruby-core:108304] [Ruby master Bug#18677] BigDecimal#power (**) returns FloatDomainError when passing an infinite parameter
From:
"mrkn (Kenta Murata)" <noreply@...>
Date:
2022-04-20 02:04:05 UTC
List:
ruby-core #108304
Issue #18677 has been updated by mrkn (Kenta Murata).
I made a patch at https://github.com/ruby/bigdecimal/pull/227.
Note that the last case `-1 ** BigDecimal::INFINITY` should cause `Math::DomainError`.
----------------------------------------
Bug #18677: BigDecimal#power (**) returns FloatDomainError when passing an infinite parameter
https://bugs.ruby-lang.org/issues/18677#change-97323
* Author: dorianmariefr (Dorian Mari辿)
* Status: Assigned
* Priority: Normal
* Assignee: mrkn (Kenta Murata)
* ruby -v: ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-darwin21]
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Example:
```ruby
> BigDecimal(10) ** BigDecimal("Infinity")
FloatDomainError: Computation results in 'Infinity'
```
Maybe:
```ruby
require "bigdecimal/util"
class BigDecimal < Numeric
def **(other)
if other.infinite? == 1
if self > 1
BigDecimal::INFINITY
elsif self == 1
self
elsif self >= 0
BigDecimal(0)
else
power(other)
end
else
power(other)
end
end
end
def puts_and_eval(string)
puts string
p eval(string)
end
puts_and_eval "10 ** BigDecimal::INFINITY"
puts_and_eval "1 ** BigDecimal::INFINITY"
puts_and_eval "0.1 ** BigDecimal::INFINITY"
puts_and_eval "0 ** BigDecimal::INFINITY"
puts_and_eval "-1 ** BigDecimal::INFINITY"
```
Seems like ruby is doing very different things from math though
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>