On 24 December 2010 17:29, Marnen Laibow-Koser <lists@ruby-forum.com> wrote:
> Colin Law wrote in post #970523:
>> On 24 December 2010 16:36, Marnen Laibow-Koser <lists@ruby-forum.com>
>> wrote:
>>>> BigDecimal and for things that are not decimal then use Float and
>>>> determine the errors if it is important.
>>>
>>> That's basically what I've been saying, except for "decimal" substitute
>>> "rational". However, there's not always an a priori way to determine if
>>> a given field will need to store irrational numbers.
>>
>> I am not quite sure that is that is the same as "never, ever use
>> Floats for arithmetic" :)
>
> Oh, now I see the difference. Even if I store something as a Float, I'd
> probably use BigDecimal for arithmetic. I simply don't believe that
> Float arithmetic has any place at all in a wise programmer's repertoire.
> Consider it the 21st-century goto, if you like. :)
>
>>
>> Also as we have seen for rational numbers like 1/3 BigDecimal is no
>> better than float, except that it is possible to specify a smaller or
>> larger precision than that which float supplies,
>
> That makes it better than Float right there. Also, you don't accumulate
> any *more* error.
The more I think about it the more I think that the ruby
implementation of BigDecimal is flawed. BigDecimal('1') /
BigDecimal('3') should be stored as a rational (ie as two values, 1
and 3 to be divided). Otherwise it seems to me that it is not 'proper'
BigDecimal. I have been unable to find documentation that fully
defines what the result of 1/3 should be.
Colin
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment