delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/04/23:26:33

From: leathm AT solwarra DOT gbrmpa DOT gov DOT au (Leath Muller)
Message-Id: <199703050418.OAA18694@solwarra.gbrmpa.gov.au>
Subject: Re: Floating Point???
To: ron DOT t DOT lewis AT softtech DOT brisnet DOT org DOT au (Ron T Lewis)
Date: Wed, 5 Mar 1997 14:18:53 +1000 (EST)
Cc: djgpp AT delorie DOT com
In-Reply-To: <4b5_9703051119@softtech.brisnet.org.au> from "Ron T Lewis" at Mar 5, 97 09:45:16 am

> int main()
> {
> float a;
> a=4.00/5.00;
> printf("float = %.12f\n",a);
> return(1);
> }
> Ans = 0.800000011921
 
> The correct answer should be 0.800000000000 but he gets these extroneous 
> numbers tacked on the end???

just for the record, I just tried this on the sparc Sun here and got the
same answer, so its a fault of FP precision (IEEE)... :)  The problem is
he is using floats which don't have 12 decimal places of precision. If
he wants more precision, he should use doubles - then he will get the
right answer... (I just tried... :)

Leathal.

- Raw text -


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