Floating-Point vs Rationals
Cluster focuses on debates about precision issues in floating-point arithmetic versus using rationals, fractions, or fixed-point for exact results in division and other operations, with references to languages like Python.
Activity Over Time
Top Contributors
Keywords
Sample Comments
because integer and float math are very different.because for some, 1/3 should not be a float but a ratio. if precision matters, you need ratios not floats. however if you just want speed, you want floats.
Because floating point math doesn't work the same as basic integer arithmetic? Divide two floating point numbers.
Or if you need rationals, use fixed point (unfortunately not native in many languages)
Wouldn't seriously suggest doing this, but rationals with big integers would have exact results for all the common operations
Right; for the former integer arithmetic won't do.
What every Computer Scientist should be asking about Floating-point arithmetic: Why aren't there types for fixed-point/rational arithmetic exposed by your language and/or standard library?
Arbitrary-precision real-number libraries would disagree with you there.
What's wrong about just `float(a)/float(b)`?
> it uses floating point numbers instead of rational numbers.import decimalimport fractions
what do you mean by "rationals"? infinite precision? because finite precision rationals are not associative and much worse than floats in many senses.