Hey /g/, I'm reading through C++ Primer and a tip states that I should use double instead of float most of the time since float usually isn't precise enough and the difference in performance is minimal.
Is this mainly true?
ya
Float is usually precise enough but the performance difference is minimal so always use double unless you have a reason not to.
Really depends. I find the instances where you need double precision floats are kinda limited, depending on your domain.
For most things general logic, string processing, data storage you're usually better served using integers.
For games, graphics, interactive stuff, the increased processing rate and memory savings of fp32 usually win over the increased precision of fp64.
For scientific computing, general calculations fp64 reigns supreme, although you're often even hitting precision limits with doubles there.
>>53631640
> half precision = 10b fraction = ~3 decimal digits precision
> single precision = 23b fraction = ~7 decimal digits precision
> double precision = 52b fraction = ~16 decimal digits precision
vidya graphics can get away with single precision, most numerical simulation should use double.
on a modern x86_64 processor, you have an FPU designed to crunch through doubles as quickly as possible with negligible performance cost for most operations. multiplies and adds/subtracts are so cheap they're almost free, but things like division/reciprocals, square roots, trig functions, etc. can take dozens of cycles and DO take upwards of twice as long for doubles as for floats.
honestly you should just use double unless you know what you're doing well enough to be able to prove you can see and actually need the speed gain from using floats.
>>53631640
Thanks for the insight /g/. I'll keep this in mind, it's just whenever I saw that comment I was wondering what programmers at /g/ thought about it.
>>53631640
this is true, only if you have a 64bit processor driving a 64 bit OS.
Most modern processors are 64bit.