Related articles |
---|
[10 earlier articles] |
Re: Why is using single-precision slower than using double-precision trobey@taos.arc.unm.edu (1994-11-23) |
Re: Why is using single-precision slower than using double-precision kenneta@hubcap.clemson.edu (1994-11-23) |
Re: Why is using single-precision slower than using double-precision dik@cwi.nl (1994-11-24) |
Re: Why is using single-precision slower than using double-precision davidc@panix.com (David B. Chorlian) (1994-11-24) |
Re: Why is using single-precision slower than using double-precision roedy@BIX.com (1994-11-30) |
Re: Why is using single-precision slower than using double-precision tgl@netcom.com (1994-11-30) |
Re: Why is using single-precision slower than using double-precision hebert@prism.uvsq.fr (1994-11-24) |
Re: Why is using single-precision slower than using double-precision dekker@dutiag.twi.tudelft.nl (Rene Dekker) (1994-11-30) |
Re: Why is using single-precision slower than using double-precision meissner@osf.org (1994-11-24) |
Newsgroups: | comp.parallel,comp.arch,comp.compilers |
From: | hebert@prism.uvsq.fr (Renaud HEBERT) |
Keywords: | arithmetic, C |
Organization: | Laboratoire PRiSM - Universite de Versailles-St Quentin - France |
References: | <3aqv5k$e27@monalisa.usc.edu> <3b07cs$mdv@hubcap.clemson.edu> |
Date: | Thu, 24 Nov 1994 08:50:17 GMT |
Did you used float constant when you were calculating in single precision?
Remenber that floating points constants are double and that if you have
float x,y;
y = 5.0 * x; here you have (double) * (float) -> (float) so in C you have the
following:
y = (float)(5.0 * (double)x) so you have two conversions..
On the other hand if you have
float x,y;
y = 5.0f * x;
^a single-precision constant
Here you have an operation between two float, I thought that the
compiler would generate the following (float) * (float) -> (float). But everyone
here is telling that the compiler will generate
y = (float)((double)5.0f * (double)x)
^^^of course this isn't a true conversion here.
Well if you want to know what's going on, the only way is to look at the assembly
I've compiled on a sun y = 5.0f * x; (y,x float) with gcc -O2
the multiply instruction is
fmuls %f0,%f2,%f0 (single precision multiply) and it seems that there
isn't any conversion (I don't know sparc assembly...).
So why all these people talked about an automatic conversion ?
Because they are too lazy to insert a "f" after their constants :-).
But it may depends on the compiler though.
Regards.
Renaud HEBERT
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.