delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/06/07:47:48

Date: Mon, 6 Apr 1998 14:47:25 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Spider <hmspider AT hotmail DOT com DOT no DOT spam>
cc: djgpp AT delorie DOT com
Subject: Re: poor fp precision
In-Reply-To: <35289C54.7FED@hotmail.com.no.spam>
Message-ID: <Pine.SUN.3.91.980406144101.10432B-100000@is>
MIME-Version: 1.0

On Mon, 6 Apr 1998, Spider wrote:

> 2.390000        238.999987  
>                 ^^^^^^^^^^
> Isnīt this very poor????? I mean, if floats have a 6 decimals precision,
> one would expect an error less than exp(-6), right??

Wrong.  A float has 6 (actually, 6.5) *significant* digits.  That is, the 
3 digits before the decimal and 3 digits after it, in your case.  
Anything after that is more than a float can handle.  Use double if you 
have some *real* floating point math to do.

> no fp emulation (I use a i486DX2)!!! Is fp calculation that bad with
> djgpp?

It's not bad, it's what IEEE standard requires.

>  Doesn't it implement arithmetics with a (double) cast? 

You are mixing the arithmetics with the way fp variables are *stored*.  
x87 FPUs do their arithmetics in 10-byte (80-bit) quantities.  But when 
those values are stored, they lose the extra bits beyond what the 4-byte 
float can hold.  If you want all the precision you can get, declare the 
variables "long double" (that's 80-bit-wide).  But just "double" (64 bit) 
is usually enough.

- Raw text -


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