3 ms·
It depends on the processor, but yes in some cases using floats would be faster for this reason. Please note that floats don't have "additional" precision, they
by NohatCoder 5y ago
It depends on the processor, but yes in some cases using floats would be faster for this reason. Please note that floats don't have "additional" precision, they have a different structure that means they can express a different set of numbers. Integers should in general always be preferred when the data you deal with is of integral nature.
Even if your CPU can do some instructions faster with floats it is generally not the kind of optimization you would want to make. You would end up making things more complicated for little practical benefit.
Funny thing by the way, integer arithmetic units are generally cheaper to make than float units, but most multiply/division heavy code is floating point, so CPU makers prioritise the floating point units.
- spekcular 5y agoThank you for the detailed explanation.