Comments (4)
Thank you for your report. I'll check and fix it asap.
from bigdecimal.
@nmingotti
This is a limitation of the current implementation of bigdecimal.
The reason why the result of the latter case is Infinity is that bigdecimal just returns Infinity for a positive integral exponent whose internal type is T_BIGNUM
.
In 32-bit platforms, sizeof(long)
is 4, so BigDecimal#**
just returns Infinity because 1_000_000_000_0
is internally a bignum.
I want to and have a plan to remove this limitation, but it isn't scheduled yet.
The corresponding code location is here:
https://github.com/ruby/bigdecimal/blob/master/ext/bigdecimal/bigdecimal.c#L2507-L2516
from bigdecimal.
@mrkn ok, thank for checking out !
In the meanwhile, If it is possible and not to tedious to implement, could you rise an exception when the exponent goes out of the supported range ?
This would be useful, getting Infinity as final result is confusing.
from bigdecimal.
@nmingotti Setting the exception mode, you can get FloatDomainError in that cases:
[2] pry(main)> BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, true)
=> 1
[3] pry(main)> n = 1_000_000_000_0
=> 10000000000
[4] pry(main)> BigDecimal(2) ** n
FloatDomainError: Computation results to 'Infinity'
from (pry):4:in `**'
[5] pry(main)>
from bigdecimal.
Related Issues (20)
- Add the new property to obtain the number of digits after the decimal point
- bignum too big to convert into `long' (RangeError) HOT 4
- Bugs when DECDIG == uint16_t
- BUG: BigDecimal#precision returns a wrong result when the number consists of single DECDIG
- Method BigDecimal: precision too large. (ArgumentError) HOT 2
- Method BigDecimal: 0 digits algorithm HOT 2
- Accept a Float value in BigDecimal#div when a precision is given HOT 2
- BigDecimal should accept a Float value without a precision
- BigDecimal#quo should accept a precision argument
- "ERROR(VpDivd): space for remainder too small" for certain division HOT 3
- Exponential growth in precision causing memory usage to spike as of 3.1.2 HOT 5
- ERROR(VpDivd): space for remainder too small
- BigDecimal#round raises FloatDomainError regardless of exception mode HOT 2
- Comparison failure: 9.8.abs <= BigDecimal('9.8') => false HOT 4
- Inconsistent max precision affecting dump&load result HOT 4
- Inconsistency between Bigdecimal 3.0.x and 3.1.x HOT 4
- BigDecimal#n_significant_digits and #precision do not return the correct value HOT 1
- I would expect BigDecimal#divmod to return type [Int, BigDecimal] (like Integer#divmod, Float#divmod)
- mode(BigDecimal::EXCEPTION_ALL,true) did not throw an exception when bigdecimal#exponent overflowed HOT 1
- Integrate JRuby implementation into the gem
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bigdecimal.