This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Single precision
Peter Barada <pbarada@mail.wm.sps.mot.com> writes:
> >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...
There's a flag to let you do this, -fsingle-precision-constant.
--
- Geoffrey Keating <geoffk@geoffk.org>