Actions
Bug #20881
openComplex#** returns discontinuous results in Fixnum and Bignum exponents
ruby -v:
ruby 3.4.0dev (2024-10-18T02:35:00Z master 9a98b70a50) +PRISM [x86_64-linux]
Description
Complex#**
performs the straightforward calculation when the exponent is Fixnum, but performs the computation in the polar coordinate system when the exponent is Bignum. Therefore, errors accumulate in the former case and not in the latter.
(Complex.polar(1, 1) ** 100000000000000).abs #=> 1.0033483420677842
(Complex.polar(1, 1) ** 1000000000000000).abs #=> 1.0339924646874608
(Complex.polar(1, 1) ** 10000000000000000).abs #=> 1.3969270854305682
(Complex.polar(1, 1) ** 100000000000000000).abs #=> 28.29680363011009
(Complex.polar(1, 1) ** 1000000000000000000).abs #=> 329134804659039.0
# ↑ Fixnum
# ↓ Bignum
(Complex.polar(1, 1) ** 10000000000000000000).abs #=> 1.0 (w/ warning: in a**b, b may be too big)
(Complex.polar(1, 1) ** 100000000000000000000).abs #=> 0.9999999999999999 (w/ warning: in a**b, b may be too big)
(Complex.polar(1, 1) ** 1000000000000000000000).abs #=> 1.0 (w/ warning: in a**b, b may be too big)
It may be good to always calculate them in the polar coordinate. I found this issue when addressing #20811.
Actions
Like0
Like0Like0