Wednesday, June 29, 2011

Re: Curious int/float/division/math 'gotcha' in py (discussion)

Thanks for explaining this Geoff. My math is somewhat basic, so it's always good to learn new things like this.

On 29 Jun 2011 08:00, "Geoff Kuenning" <geoff@cs.hmc.edu> wrote:
>
>
> On Jun 29, 1:37 am, Tom Evans <tevans...@googlemail.com> wrote:
>> Damn, this was the bit I meant to comment upon - hard and fast rules
>> are dangerous. Integral types are distinctly different to floating
>> point types, and you should be aware of which one you are using and
>> why. You definitely should not be using floats when you require
>> integral mathematics, or reliable accounting since 1.0 is only an
>> approximation to 1.
>>
>> Cheers
>>
>> Tom
>>
>> >>> 1.0 * 10000000000000000000000000000
>>
>> 9.9999999999999996e+27
>
> Actually, 1.0 is NOT an approximation to 1. It is precisely 1. All
> integral values up to 2^53-1 can be represented exactly. So can many
> rational fractions (roughly, those in which the denominator is a power
> of two and the numerator and denominator don't differ by a really big
> ratio).
>
> The reason the above example fails isn't the 1.0, it's because the
> second number (10^28) is bigger than 2^53, so IT can't be represented
> exactly.
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment