delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/08/01/14:15:29

From: Horst Kraemer <horst DOT kraemer AT gmx DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: modf BROKEN ??
Date: Tue, 01 Aug 2000 19:37:54 +0200
Lines: 20
Message-ID: <mrrcossdr6n0c4oq3mfcblt7d0vtbbposk@4ax.com>
References: <crdcosk167oh81vpnjfqeg1bnls5qqg9ld AT 4ax DOT com>
NNTP-Posting-Host: a11e2.pppool.de (213.6.17.226)
Mime-Version: 1.0
X-Trace: fu-berlin.de 965151443 6010865 213.6.17.226 (16 [27606])
X-Newsreader: Forte Agent 1.8/32.548 trialware
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Mon, 31 Jul 2000 22:37:40 -0400, Radical NetSurfer
<radsmail AT juno DOT com> wrote:

> Why does the following program INCORRECTLY display
> the fractional part?

It does display CORRECTLY the fractional part.

The problem is that you think that adding up 20 times the floating
point value 0.1 will yield exactly 2.0. The number 0.1 isn't exactly
representable as a binary floating point number. Adding up the "wrong"
binary value associated to '0.1' will increase the representation
error.

Using FP numbers as contrl variable in a loop is almost always an
error.

Regards
Horst

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019