Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ttrdc.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!mgnetp!ltuxa!ttrdc!levy From: levy@ttrdc.UUCP (Daniel R. Levy) Newsgroups: net.lang.c Subject: Re: C Floating point arithmetic Message-ID: <618@ttrdc.UUCP> Date: Wed, 4-Dec-85 18:24:40 EST Article-I.D.: ttrdc.618 Posted: Wed Dec 4 18:24:40 1985 Date-Received: Fri, 6-Dec-85 06:30:54 EST References: <1087@lll-crg.ARpA> <4647@alice.UUCP> Organization: AT&T, Computer Systems Division, Skokie, IL Lines: 60 In article <4647@alice.UUCP>, ark@alice.UucP (Andrew Koenig) writes: >> float a,b; >> >> a = b + 1.0; /* Gets done in double because 1.0 is a double. >> Gag me with a spoon. */ > >Nah, gets done in single because the compiler realizes that 1.0 has >the same representation in single and double, and therefore that >the result of the addition will be the same. On a 3B20S running Sys5 Release 2: $ cat fabc.c main() { float a,b; a = b + 1.0; } $ cc -c -O fabc.c $ dis fabc.o **** DISASSEMBLER **** disassembly for fabc.o section .text main() 0: 7a02 save &0x0,&0x2 2: c870 a04e 0000 movsd 0x4(%fp),%r0 8: c908 0000 018e 0000 faddd2 $0x18,%r0 <==DOUBLE 10: c96e 0000 a000 movds %r0,0x0(%fp) 16: 7b00 ret &0x0 $ cat fabf.f real a,b a = b + 1.0 end $ f77 -c -O fabf.f fabf.f: MAIN: $ dis fabf.o **** DISASSEMBLER **** disassembly for fabf.o section .text 0: 7a00 save &0x0,&0x0 2: 114b addw2 &0x4,%sp 4: 800b br +0xb <1c> 6: ca08 0000 0208 0000 028e 0000 fadds3 $0x20,$0x28,%r0 <==SINGLE 12: 5108 0000 0240 movw %r0,$0x24 18: a100 7b00 ret &0x0 1c: 900c br -0xc <6> 1e: dede nop -- ------------------------------- Disclaimer: The views contained herein are | dan levy | yvel nad | my own and are not at all those of my em- | an engihacker @ | ployer or the administrator of any computer | at&t computer systems division | upon which I may hack. | skokie, illinois | -------------------------------- Path: ..!ihnp4!ttrdc!levy