BigDecimal#to_f breaks for numbers too small to be representable in Float
BigDecimal numbers too small to be representable in Float are incorrectly converted to +/-Infinity instead of 0.0 (or -0.0). Things seem to broke down when exponent is about -308.
with 307, ok¶
with 308, broken but signedness is correct¶
with 350 not even signedness is correct¶
Workaround: resort to BigDecimal#to_s and Float(.)¶
#1 Updated by Nobuyoshi Nakada over 4 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r36854.
Adriano, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
bigdecimal.c: check underflow
- ext/bigdecimal/bigdecimal.c (BigDecimal_to_f): check underflow since strtod() sets errno to ERANGE at underflow too. [Bug #6944]