3 ms·
Correct me if I'm wrong, but couldn't the same bug exist in the BigDecimal to double conversion? It has to turn a precise value into an approximate double usin
by tedunangst 16y ago
Correct me if I'm wrong, but couldn't the same bug exist in the BigDecimal to double conversion? It has to turn a precise value into an approximate double using a similar algorithm, no?
return base.scaleByPowerOfTen(exponent).doubleValue();
- headius 16y agoI don't believe so; the conversion to imprecise doesn't follow the same logic that the String to double does. But I don't know what logic it does follow, nor if there's other bugs there :) In any case, for the original value and variations I tested, the workaround does function properly.
- jonshea 16y agoMy understanding is that you are correct. I believe that BigDecimal.doubleValue() does the conversion by (wait for it…) converting to a string and parsing with Double.parseDouble(). Real quick: scala> val y y: java.math.BigDecimal = 2.2250738585072012E-308 scala> y.doubleValue() Hangs This is one of those “harder than it looks” problems.
- headius 16y agoYeah, I went back to my code and realized there was a precision problem I had to fix for numbers approaching 64-bit minimum. Once I fixed that issue, it went back to hanging again :( I updated the post, and I'm looking for new alternatives now.
- fedd 16y agomaybe its okay to lose some precision as everybody knows that doubles are already inaccurate? :) http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems http://en.wikipedia.org/wiki/Floating_point#Accuracy_problem...
- fedd 16y agoedit: i mean: normalize(!), check if it is textually the bad magic number, then either use builtin conversion or use your solution. a? :)