1

I know that doubles are more precise than floats and that they should be used for financial stuff and other things that require precision, but why do we use floats? Why not just get rid of floats and use doubles for everything since they're more accurate?

Sorry, if this should've been asked somewhere else. I feel like only posts that contain code should go to stack overflow and I didn't know where else to ask this.

4

Doubles take twice more space. On some devices and for some applications this makes a difference. Think of 3D graphics: lots of numbers and no need for super-accurate results.

Also, financial transactions use integers (think dollars and cents) because they need not just accuracy, but exactness.

  • Correct me if I'm wrong, but we still use floats because somethings like 3D graphics don't need the extra precision and your literally using half as much memory by using floats instead of doubles. – Adam Oates Apr 26 at 7:37
  • This would also probably be the reason Rust has 32 and 64 but float types, but no double type. – Adam Oates Apr 26 at 7:42
  • This answer would be improved by mentioning that the issue with increased size is not memory per se but speed. The primary reason for wanting to use less memory is that it makes processing faster. – Jack Aidley Apr 26 at 8:22
  • 3
    @DavidArno, did you read both the answer and the comments on that link? Because it would seem the comments break down the answer. – r_ahlskog Apr 26 at 10:52
  • 1
    @AdamOates Rust's f64 type is Rust's double type. From the book: "Floating-point numbers are represented according to the IEEE-754 standard. The f32 type is a single-precision float, and f64 has double precision." – 8bittree Apr 26 at 14:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.