bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SEQ BUG


From: John Cowan
Subject: Re: SEQ BUG
Date: Thu, 7 Jun 2007 16:07:56 -0400
User-agent: Mutt/1.5.13 (2006-08-11)

Patrick Amstutz scripsit:

> $ echo `seq 0.0 0.1 0.8`
> 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8
> $ echo `seq 0.0 0.1 0.9`
> 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8

Welcome to floating-point roundoff errors.  The decimal constant 0.1
cannot be exactly represented as a floating-point number on modern
hardware, so 0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1 is actually greater
than 0.9; consequently, 0.9 is not printed.

You should never iterate using floating-point fractions for this reason.

-- 
Where the wombat has walked,            John Cowan <address@hidden>
it will inevitably walk again.          http://www.ccil.org/~cowan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]