[vox-tech] float vs double, int vs short

Boris Jeremic jeremic at ucdavis.edu
Thu Feb 16 12:27:30 PST 2006


I think that on X86, both float and double get expanded to long double, then all 
the computations locally (in CPU) get done with long double) and the results are 
then converted to whatever they were intended to be to begin with. See the 
attached example code for finding machine epsilon (plain c, just do


gcc LUGODtest.cpp

and run ./a.out


On other architectures (tried on SUN) there is actually  a difference (as it 
should be).

So to conclude, I do not think that you gain much (if anything) on CPU with 
floats versus doubles. There might be a gain in moving data from and to memory 
and similar, but computationally, probably the best is to run a million loops on 
  an example (maybe even the one for machine epsilon attached below) and see 
where it goes...

Boris




Ken Bloom wrote:
> On Thu, Feb 16, 2006 at 11:21:11AM -0500, Peter Jay Salzman wrote:
> 
>>I've been googling for the past 15 minutes and have read that:
>>
>>   * computations with doubles are always faster than floats
>>   * computations with doubles are often faster than floats
>>   * computations with floats are often faster than doubles
>>   * computations with floats are always faster than doubles
>>
>>The arguments I've read for all four cases seem reasonable.  I trust
>>the collective brains of lugod more than any internet forum.  What's
>>the real scoop on the relative speed of basic arithmetic operations
>>on floats and doubles?
> 
> 
> Write a simple benchmark and tell us. A program that runs the desired
> operations in a loop a few million times should give you a good idea
> which is faster.
> 
> Likewise for shorts and ints.
> 
> --Ken
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> vox-tech mailing list
> vox-tech at lists.lugod.org
> http://lists.lugod.org/mailman/listinfo/vox-tech
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LUGODtest.cpp
Type: text/x-c++
Size: 1553 bytes
Desc: not available
Url : http://ns1.livepenguin.com/pipermail/vox-tech/attachments/20060216/876ce1ee/LUGODtest.bin


More information about the vox-tech mailing list