i = i * f *vs* i *= f (Not a bug)

bet at ecsvax.UUCP bet at ecsvax.UUCP
Mon Apr 16 07:03:13 AEST 1984


What we have here is a type conversion problem. When i = i * f is evaulated,
the "i" on the right side of the assignment is promoted to float, the
expression is evaluated, and the result is converted back to integer for
the assignment. When i *= f is evaluated, the right side of the assignment
operator is evaluated, just as before: it is the float. It is then converted
to integer for the assignment operation: 0.2 goes to 0 in any reasonable
conversion. BEWARE incautious mixed types: they ALWAYS ALWAYS ALWAYS bite
back. C is perhaps as benign as any environment I know. Look at PL/I for
crissakes. If ANY numeric value gets converted to fixed decimal, you stand a
good chance of getting badly burnt. Literal numeric constants (as I recall)
default to fixed decimal. OUCH!!!
					Bennett Todd
					...{decvax,ihnp4,akgua}!mcnc!ecvax!bet



More information about the Comp.lang.c mailing list