Comments (12)
Updated bundler and now I have to go inspect every BigDecimal in my codebase for BREAKING changes!!! Not ok.
from bigdecimal.
No, it should. BigDecimal("foo")
now raises an ArgumentError just like Integer("foo")
had always done. If you want invalid input to be coerced to zero, use "foo".to_d
just like you would use "foo".to_i
.
from bigdecimal.
disagree. Math functions should not raise exceptions. If Integer raises exceptions, that should be fixed also.
from bigdecimal.
The ability to raise is very useful when dealing with external input. The old behaviour is coercing to zero from BigDecimal.new
meant in our app we had no idea if a zero came from actually valid input or not, requiring a workaround (Float(input)
) before passing it to BigDecimal.
The behaviour you need is still there, just find & replace.
from bigdecimal.
The ability to raise is also insanely annoying when your code continually breaks because every minor library call didn't like your unformatted input, and caused a halt. It's a bug not a feature.
from bigdecimal.
@Tectract
BigDecimal just follows the behaviors of core numeric classes such as Integer and Float.
If you want to discuss them, you should go to https://bugs.ruby-lang.org/.
By the way,
If Integer raises exceptions, that should be fixed also.
How do you fix this?
1 / 0 #=> ZeroDivisionError (divided by 0)
from bigdecimal.
Updated bundler and now I have to go inspect every BigDecimal in my codebase for BREAKING changes!!! Not ok.
If you don't want to use the latest bigdecimal, you can specify the old version in your Gemfile.
Thanks.
from bigdecimal.
The ability to raise is very useful when dealing with external input. The old behaviour is coercing to zero from BigDecimal.new meant in our app we had no idea if a zero came from actually valid input or not, requiring a workaround (Float(input)) before passing it to BigDecimal.
Correct.
The ability to raise is also insanely annoying when your code continually breaks because every minor library call didn't like your unformatted input, and caused a halt. It's a bug not a feature.
What if a result is calculated wrong with an invalid input? How are you going to know that is caused by such input? Then how you'll deal with the wrong result, when the input was lost at the timing of notice of the error?
from bigdecimal.
Should be re-opened. BigDecimal should never throw errors.
What if a result is calculated wrong with an invalid input?
NaN should be output in such a case.
If you don't want to use the latest bigdecimal, you can specify the old version in your Gemfile.
Referring to an old version because a BUG was introduced in the new version is not a solution.
from bigdecimal.
How do you fix this?
1 / 0 #=> ZeroDivisionError (divided by 0)
NaN or infinity. Simple.
from bigdecimal.
I request this issue should be re-opened, until this discussion is finalized:
https://bugs.ruby-lang.org/issues/14587
from bigdecimal.
We are not going to re-open this. Raising an exception is perfectly reasonable in Ruby. Every language has a different paradigm and not respecting the language's design like above is absurd. See how different Golang is from Ruby. It simply doesn't make sense to add the exception me mechanism to Golang, or to remove it from Ruby.
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.