Project

General

Profile

Actions

Bug #17264

closed

BigDecimal exponentiation cannot be used with #** method

Added by karatedog (Földes László) about 4 years ago. Updated almost 4 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]
[ruby-core:<unknown>]

Description

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:

(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:

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0