TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: GEORGE WHITE
from: ALAN CLIFFORD
date: 1998-02-27 02:10:00
subject: What`S Happening Here?

Hello George
Replying to a message of George White to Alan Clifford:
 GW>>> According to the rules the two longs should be promoted to float
 GW>>> before the calculation, the calculation made and then the result
 GW>>> cast back to long (which discards any fractional part).
 AC>> Aren't the two longs multiplied first before the result is
 AC>> promoted?  Promoted to what?  The two manuals I've got
 AC>> disagree.  Mix Power C says floats are promoted to double.
 AC>> Turbo C manual says that float stays float.
 GW> As I read it all promotions occur before the calculation is made.
 GW> bicbw (and if I am I'm sure to be corrected).
Using Turbo, I get the following results for the code below.  If everything 
was promoted, resultf would be the same as resultfi.  An interesting result 
from 30000 * 30000 though.
resulti -17664
resultf -17664.000000
resultfi 2700000000.000000
#include 
int main(void) {
int a = 30000, b = 30000, multii = 3, resulti;
float multif = 3.0, resultf, resultfi;
resulti = a * b * multii;
resultf = a * b * multif;
resultfi = (float)a * b * multif;
printf("resulti %d\n", resulti);
printf("resultf %f\n", resultf);
printf("resultfi %f\n", resultfi);
return 0;
}
Alan
"Computers do bite"
--- FleetStreet 1.14 NR
---------------
* Origin: Alan's Point on Donor/2 (2:440/4.6)

SOURCE: echomail via exec-pc

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™.