4 ms·
I can’t think of code that needs rationals that doesn’t need exactness I can't think of code that really needs rationals. Irrational numbers are proof that nu
by jqpabc123 5y ago
I can’t think of code that needs rationals that doesn’t need exactness
I can't think of code that really needs rationals.
Irrational numbers are proof that numeric "exactness" is relative.
- zelphirkalt 5y agoI would say you "need" rationals, when there is no reason to give an incorrect or imprecise result and performance is not that important or input size is not too big. When you need that kind of precision for irrational numbers, you can opt for symbolic calculation, where important irrational numbers are simply symbols or terms and you can transform them at the end of the calculation into a number of as much precision, as you need. Of course there are always edge cases, where finding a good solution is difficult. For example, what if you need performance and as much precision as possible? Cannot use floating point numbers, cannot use rationals with same performance as floating point numbers (I think), cannot use symbolic calculation, also because of performance ... Not sure what to do then, but I have not hit such a case ever. I imagine, that perhaps space operations need that kind of precision. Perhaps they simply have clusters run for a few days or so, to get to that precision.
- jqpabc123 5y agoThere are valid reasons why most programming languages don't include "rationals". Most things in the real world simply can't be measured to a level of accuracy beyond 4 decimals.
- Someone 5y agoComputer algebra systems are the typical example. They’ll have a ‘Number’ type that, among others, has integers, rationals, algebraic numbers, etc. They also can come in handy in various puzzle problems.