delorie.com/archives/browse.cgi | search |
From: | Sean Melody <s-melody AT STOP DOT SPAMMERS DOT nwu DOT edu> |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | Re: A nice trap! |
Date: | Sun, 31 May 1998 20:33:08 -0500 |
Organization: | Northwestern University, Evanston, IL, US |
Lines: | 27 |
Message-ID: | <357204D4.4E1893D2@STOP.SPAMMERS.nwu.edu> |
References: | <199805311442 DOT KAA17864 AT delorie DOT com> |
NNTP-Posting-Host: | hin082083.res-hall.nwu.edu |
Mime-Version: | 1.0 |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Always nice to see an author slap the idiots around ;) Go DJ. Sean Melody DJ Delorie wrote: > > > void main( void) > > { > > float f; > > f = 55 / 77; > > printf( "%f", f); > > } > > /* and please mail me YOUR results */ > > It does exactly what I expect: it prints 0. If you expect anything > else, you don't understand how C works. When you do this: > > f = 55 / 77; > > The compiler evaluates the 55/77 part first - the division of two > *integers*. Integer division returns an integer result (0). *Then* > it's converted to a floating point number (0.0) in order to store it. > > If you want the compiler to divide floating point numbers, you have to > tell it to do that: > > f = 55.0 / 77.0;
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |