Related articles |
---|
Floating point constant question mahlke@crhc.uiuc.edu (Scott Mahlke) (1994-03-28) |
Re: Floating point constant question joe@sanskrit.ho.att.com (1994-03-29) |
Re: Floating point constant question chase@Think.COM (1994-03-29) |
Re: Floating point constant question bill@amber.csd.harris.com (1994-03-29) |
Re: Floating point constant question maydan@mti.mti.sgi.com (1994-03-29) |
Re: Floating point constant question hbaker@netcom.com (1994-03-30) |
Re: Floating point constant question conte@ece.scarolina.edu (1994-03-30) |
Re: Floating point constant question chase@Think.COM (1994-03-30) |
[2 later articles] |
Newsgroups: | comp.compilers |
From: | joe@sanskrit.ho.att.com (Joe Orost 908- 946-1115) |
Keywords: | arithmetic, optimize |
Organization: | AT&T |
References: | 94-03-157 |
Date: | Tue, 29 Mar 1994 12:16:07 GMT |
Scott Mahlke <mahlke@crhc.uiuc.edu> writes:
>I have a question regarding the following compiler optimization:
>
> x = y / 500.0; ===> x = y * 0.002;
> ...
>Is this or similar optimizations dealing with FP constants ever legal? Do
>any compilers out there do optimizations such as this? Thanks.
It's only a valid replacement if you don't affect the accuracy of the
calculation. For cases where you are dividing by a power of 2, it is
always safe. This is the rule I apply to the compilers I write.
In IEEE single precision, 500.0 is exact (43fa0000), while 0.002 is
actually represented by 0.00200000009499490261077880859375 (3b03126f). On
the other hand, both 512.0 and 0.001953125 are exact.
regards,
joe
--
Full Name: Joseph M. Orost
EMail: joe@babel.ho.att.com, attmail!orost
Organization: AT&T Bell Laboratories
SurfaceMail: 943 Holmdel Rd.; Cruz Plaza; Holmdel, NJ 07733
Phone: +1 (908) 946-1115
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.