delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/06/10:25:42

Date: Thu, 6 Jan 2000 13:04:22 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Niklas Pettersson <npedt97 AT student DOT vxu DOT se>
cc: djgpp AT delorie DOT com
Subject: Re: DJGPP BUG!!!!!!! ???
In-Reply-To: <851o9m$h4t$1@news.lth.se>
Message-ID: <Pine.SUN.3.91.1000106130014.20692A-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: dj-admin AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Thu, 6 Jan 2000, Niklas Pettersson wrote:

> I think I have found an error in DJGPP...

No, it's not a bug in DJGPP.

> 0.1   0
> ..
> ..
> 0.9   0
> 1.0   1
> ...
> 
> but 1.0 gets converted to 0!!!!

The problem is that 0.1 doesn't have an exact binary representation, so 
it is converted to a number that is slightly less than 0.1.  Therefore, 
10 times that number is slightly less than 1.0.  Printing that number 
with %f rounds the value to 1.0, but assigning it to an int *truncates* 
rather than rounds, and you get 0.

I suggest to read some introductory book about numerical computations, it 
should explain this somewhere on page 3 or thereabouts...

- Raw text -


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