Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)

Grant Edwards grante at visi.com
Mon Aug 4 00:57:10 CEST 2008


On 2008-08-03, Larry Bates <larry.bates at websafe.com`> wrote:

>> However, it appears that when n in 1/n is a power of two, the decimal 
>> does not get 'thrown off'. How might I make Python recognise 0.2 as 0.2 
>> and not 0.20000000000000001?
>> 
>> This discrepancy is very minor, but it makes the whole n-th root 
>> calculator inaccurate. :\
>
> What are they teaching in computer science classes these days?

When I was an undergrad the only courses that dealt with FP
issues were classes on numerical analysis.  I don't even know
if numerical analysis classes were required for CS majors.  I
think most of us in that class were engineering majors.

-- 
Grant Edwards                   grante             Yow! I wish I was a
                                  at               sex-starved manicurist
                               visi.com            found dead in the Bronx!!



More information about the Python-list mailing list