TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Chris Mcbrien
from: Daniel Doran
date: 1994-10-12 18:27:00
subject: C/set++

CHRIS MCBRIEN had something deep to write about C/Set++


CM> My system tells me the value is 2.639996E+01.  Now that's not a
CM> huge difference, I admit, but it's enough to really screw up my
CM> program.

Considering that a float is only 32 bits long, and only 23 or 24 (I
can't remember which, and am too lazy to look it up) are used to
represent the mantissa, you only have about 7 digits of accuracy.  If
you need more, use a double instead of a float.  This isn't a flaw of
OS/2, but because 26.4 cannot be exactly represented by a float.  It
can't be exactly represented by a double, either, but the error is
less. See example below:

#include 
main(){
float temp=26.4;
double dtm=26.4;
printf("\nfloat: %25.10f  %25.10e\n",temp,temp);
printf("\ndouble:%25.10lf  %25.10le\n",dtm,dtm);
}

result: (Note, this was a dos program, not OS/2, but both use the same
math)
 float:             26.3999996185          2.6399999619e+001

 double:            26.4000000000          2.6400000000e+001

 * KWQ/2 1.2g * So easy, a child can do it. Child sold seperately


--- QScan v1.12b / 01-0093

* Origin: (1:381/123)
SEEN-BY: 12/2442 54/54 620/243 624/50 632/348 640/820 690/660 711/409 410 413
SEEN-BY: 711/430 807 808 809 934 942 949 712/353 623 713/888 800/1
@PATH: 381/123 900 3615/50 229/2 12/2442 711/409 54/54 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.