From: merch-redmine@... Date: 2020-11-24T18:25:48+00:00 Subject: [ruby-core:101051] [Ruby master Bug#17264] BigDecimal exponentiation cannot be used with #** method Issue #17264 has been updated by jeremyevans0 (Jeremy Evans). Assignee set to mrkn (Kenta Murata) Status changed from Open to Assigned karatedog (F�ldes L�szl�) wrote: > My suggestion is the #** method and #power method should work the same way or the #** method retired. The methods actually do operate the same way. `#**` is basically: ```ruby def **(other) power(other) end ``` So the issue is basically the precision for `power` when given one argument is not high enough, at least for fractional powers. I've submitted a pull request to increase the precision, but the downside is it makes the power calculations much slower: https://github.com/ruby/bigdecimal/pull/171. It is up to @mrkn whether the benefits of increasing the precision are worth the performance decrease. ---------------------------------------- Bug #17264: BigDecimal exponentiation cannot be used with #** method https://bugs.ruby-lang.org/issues/17264#change-88723 * Author: karatedog (F�ldes L�szl�) * Status: Assigned * Priority: Normal * Assignee: mrkn (Kenta Murata) * ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- As stated in Bug #17214 (https://bugs.ruby-lang.org/issues/17214) when exponentiating a BigDdecimal number even when using small numbers, a precision argument must be passed to the operation or the operation will return wrong result, 2222 and 3.5 not being 'huge' numbers: ``` ruby (BigDecimal("2222",10000) ** BigDecimal("3.5",10000)).to_i # => 517135311000 ``` However the #** method cannot be passed a precision argument and as seen above it will return wrong values for small numbers even if the BigDecimal numbers themselves have a large precision argument. Therefore this operation can only be valid if used with the #power method and provided with a larger precision argument: ``` ruby BigDecimal(2222).power(3.5, 15).to_i #=> 517135308457 ``` My suggestion is the #** method and #power method should work the same way or the #** method retired. -- https://bugs.ruby-lang.org/ Unsubscribe: