| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | C/Set++ |
Hi Chris,
On Chris Mcbrien to All:
CM> float temp=26.4;
CM> My system tells me the value is 2.639996E+01.
Borland (1.0) says: 2.63999996185303e+01
IBM Cset 2.01 says: 2.63999996185303e+01
Watcom Fortran 9.5: 2.63999996185303E+01
They all agree. Isn't that nice! So it is originated by your system, not
your compiler. If you would have been using doubles, you would have been
obtaining a better result: 2.64000000000000e+01 or in 40 digits:
2.6399999999999998580000000000000000e+01
The problem is the sheer number: 26.4. This can be written as 32 * (33 /
40). Unfortunately 33/40 can not be written as a fraction p/q where p is
integer and q is a power of 2.
The solution for your problem is well known: if you compare one temperature
T with your criterion temp (26.4) it will be never the same, so ask whether
it is nearly the same.
if (abs(1-T/temp) < 1.E-6)
stop;
else
continue;
if 1 ppm is still to large, use 1 ppb (1.E-9).
A rather crude trick, a 4 byte floating point has a mantissa of 23 bits, so
it is relatively accurate to roughly 2^-23 appx. 1.E-7. An 8 byte floating
point has a mantissa of 52 bits, roughly 2^-52, so it is relatively
accurate to appx 1.E-16. The figures 26.4 in float and double confirm these
crude estimations.
73 es cuagn,
Henk
--- The-Box Point 0.15+ PC
* Origin: Lobster BBS voor programmeurs 0104271432 (2:286/300.1)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: 286/3 10 280/0 801 24/24 396/1 3615/50 229/2 12/2442 @PATH: 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™.