On 5/11/10, Roger Pack <rogerpack2005 / gmail.com> wrote:
>
>> 1). Just because BigDecimal has what seems like better behavior in
>> some cases compared to a binary float, it has just as many problems in
>> other cases.
>>
>>    (BigDecimal("1") / BigDecimal("3")).to_s
>>  => "0.333333333333333333333333333333333333E0"
>>
>>    Both binary and decimal floats have an infinite number of real
>> numbers which they can't express exactly.
>
> Good point.
> Maybe a good default would be Rational then?
>
>>> Rational(1,3)
> => (1/3)

Rational can't represent irrationals or transcendentals exactly. More
to the point, it has the same problems as BigDecimal: it's slow and
intermediate results can end up taking up lots of memory (unless
rounded).

I do wish there was a syntax for literal BigDecimals, Rationals,
Imaginaries, and Complex numbers, tho.

>> And extended example which might make the point a bit better:
>> ((BigDecimal("1") / BigDecimal("3"))*BigDecimal("3")).to_s
>> => "0.999999999999999999999999999999999999E0"
>
> That one seemed to work ok.  Was your point that it is limited to 36
> decimals by default?

The correct answer would have been "1.0".