Article View: gnu.gcc.help
Article #51675Re: Floating point differences
From: Michael T.Y. McNamara
Date: Tue, 20 Apr 1993 21:42
Date: Tue, 20 Apr 1993 21:42
76 lines
3779 bytes
3779 bytes
In article <1qmla6INNb25@fmsrl7.srl.ford.com> hugh@slee01.srl.ford.com writes: |I wrote: |: We have an application here that does a lot of floating point |: calculations. We have noticed differences in results between gcc and |: other compilers. i.e. cc on Sun, Borland C on PC, and MS C on PC give |: identical results. Only gcc on Sun differs. Does gcc do something | |I think I know the problem. It has to do with differences in the |treatment of floats in traditional and ANSI C. | ... |Here is the epsilon output run on Sun with three different |compiler/switch combinations: | | slee06% cc -o epsilon epsilon.c | slee06% epsilon | Epsilon machine (avec variable intermediaire) : 1.19209e-07 | Epsilon machine (sans variable intermediaire) : 2.22045e-16 | | slee06% gcc -o epsilon epsilon.c | slee06% epsilon | Epsilon machine (avec variable intermediaire) : 1.19209e-07 | Epsilon machine (sans variable intermediaire) : 1.19209e-07 | | slee06% gcc -traditional -o epsilon epsilon.c | slee06% epsilon | Epsilon machine (avec variable intermediaire) : 1.19209e-07 | Epsilon machine (sans variable intermediaire) : 2.22045e-16 | |The epsilon values from gcc's float.h are: | | #define FLT_EPSILON ((float)1.19209290e-07) | #define DBL_EPSILON 2.2204460492503131e-16 | |As expected, cc appears to be doing double precision arithmetic. The |intermediate variable is truncating to float. The first run of gcc has |identical results with or without the intermediate variable. This |indicates it is not promoting float to double for arithmetic |operations. The second run of gcc, with the -traditional compiler |flag, gives the same result as for cc. Even though the gcc manual page |gives no indication of this, -traditional must be causing gcc to treat |float arithmetic the same way as cc does. | |The Borland compiler gave | | Epsilon machine (avec variable intermediaire) : 1.19209e-07 | Epsilon machine (sans variable intermediaire) : 1.0842e-19 | |Summing things up, it looks like everybody but gcc is promoting floats |to double. | |We tried compiling our application with gcc -traditional and the |results matched those of cc. Sun's Solaris 2.1 SPARCompilers 2.0.1 gives: oceanus> cc epsilon.c ; a.out Epsilon machine (avec variable intermediaire) : 1.19209e-07 Epsilon machine (sans variable intermediaire) : 2.22045e-16 oceanus> cc -Xs epsilon.c ; a.out Epsilon machine (avec variable intermediaire) : 1.19209e-07 Epsilon machine (sans variable intermediaire) : 2.22045e-16 oceanus> cc -Xa epsilon.c ; a.out Epsilon machine (avec variable intermediaire) : 1.19209e-07 Epsilon machine (sans variable intermediaire) : 1.19209e-07 So it seems gcc is entirely consistant with other C compilers, albeit it's default is ANSI, where as other compilers default to K&R. (in regards to float promotion) -- __ ______ Michael T.Y. McNamara -o| \_____| |------ 1+(415) 965-3312 C H R O N O L O G I C --|__/ | | 1+(415) 965-2705 FAX --------. Simulation -----------|> |------ mac@chronologic.com
Technical Details
Message-ID:
<1993Apr20.214250.6800@chronologic.com>Path:
arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!usc!sdd.hp.com!sgiblab!news.kpc.com!kpc!chrnlgc!macReferences:
<1qhbioINN55a@fmsrl7.srl.ford.com> <1qmla6INNb25@fmsrl7.srl.ford.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,e3259ca760e1e814 X-Google-Attributes: gid11318c,public X-Google-ArrivalTime: 1993-04-21 00:32:46 PST Newsgroups: gnu.gcc.help Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!usc!sdd.hp.com!sgiblab!news.kpc.com!kpc!chrnlgc!mac From: mac@chronologic.com (Michael T.Y. McNamara) Subject: Re: Floating point differences Message-ID: <1993Apr20.214250.6800@chronologic.com> Organization: Chronologic Simulation References: <1qhbioINN55a@fmsrl7.srl.ford.com> <1qmla6INNb25@fmsrl7.srl.ford.com> Date: Tue, 20 Apr 1993 21:42:50 GMT Lines: 76