• 0 Posts
  • 6 Comments
Joined 2 years ago
cake
Cake day: July 22nd, 2023

help-circle





  • That’s not really true and it depends on what you mean. If your decimal datatype has the same number of bits it’s not more accurate than base 2 floats. This is often hidden because many decimal implementations aren’t 64 bit but 128 bit or more. But what it can do is exactly represent base 10 numbers which is not a requirement for a lot of applications.

    You can use floats everywhere where you don’t need numbers to be base 10. With base 2 floats the operations couldn’t be more accurate given the limit of 64 bits. But if you write f64 x = 0.1; and one assumes that the computer somehow stored 0.1 inside x they already made a wrong assumption. 0.1 can’t be converted into a float because it’s a periodic in base 2. A very very pedantic compiler wouldn’t even let you compile that and force you to pick a value that actually can be represented.

    Down the rabbit hole: https://zeta.one/floats-are-not-inaccurate/