This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Single precision
- From: "Chris Croswhite" <ccroswhite at get2chip dot com>
- To: <pbarada at mail dot wm dot sps dot mot dot com>
- Cc: <tm_gccmail at mail dot kloo dot net>, <ccroswhite at get2chip dot com>, <gcc at gcc dot gnu dot org>
- Date: Thu, 9 Jan 2003 14:14:11 -0800 (PST)
- Subject: Re: Single precision
- References: <200301092203.h09M3Dl19432@hyper.wm.sps.mot.com>
- Reply-to: ccroswhite at get2chip dot com
Thanks for the help.
Chris
Peter Barada said:
>
>>A better solution is probably to #define double float immediately after
>>including any header files.
>
> If so, then cast all the floating point constants so the compiler will
> use them as single precision constants instead of their default of
> double precision which will then cause the float to get promoted to a
> double and *then* operate on the constant. Unless you case the
> constants, the code will end up slower. As an example:
>
> #define double float
> double float_abs(double a, double b)
> {
> if (a >= (double)0.0)
> return a;
> else
> return -a;
> }
>
> If the zero wasn't case to double(which via the #define is really a
> float, then the comparison will be done in dboule precision *after* 'a'
> is converted from single precision to double.
>
> Hope this helps...
>
> --
> Peter Barada
> Peter.Barada@motorola.com Wizard
> 781-852-2768 (direct) WaveMark Solutions(wholly owned by Motorola)
> 781-270-0193 (fax)