Is it more efficient to compare the float than the double?

advertisements

I would think they are the same on 64bit architect.

For example I'm writing a function template, should I provide a specification for float as well as double, or should I just provide one specification takes a double and let other numbers converted to double automatically? Assuming the only numeric types considered are float, double, int, long, unsigned int, unsigned long.


It is typically either the same or slightly faster to compare a float to a float than a double to a double, but the difference is typically miniscule either way. The bigger performance problem you might be looking at is the conversion from float to double, which can either be free or pretty expensive, depending on where and how it is being done.

Either way, it's really not worth worrying too much about unless you have profiled and found a bottleneck in some huge loop involving this function, in which case you can then test the performance difference yourself and react accordingly.