3 ms·
>Actually it's possible to represent 1/3 perfectly accurately I'm curious, how?
by craftyguy 9y ago
>Actually it's possible to represent 1/3 perfectly accurately
I'm curious, how?
- ars 9y ago> I'm curious, how? As 1/3 - exactly as it's on your screen. All rational numbers can be represented exactly.
- craftyguy 9y agoHmm, yes, it can be represented in ASCII. But you still have to approximate when storing it in a way that is actually useful for computation using a finite number of bits.
- umanwizard 9y agostruct rational { int numerator; int denominator; };
- dragonwriter 9y agoMany real programming languages support arbitrary precision decimal and/or rational numbers. Sure, there are times when space or speed concerns favor inexact representation over correctness, but that's an optimization that ought to be properly evaluated; the fact that lots of languages are designed in a way which makes it the default everyone reaches for contributes to lots of errors.
- LASR 9y agoNo. of course not. A lot of scientific calculators do this. They have a fractional arithmetic mode that keeps numbers you input as fractions as fractions in the output. Scientific calculators even have irrational modes where they represent irrational numbers such as sqrt(2) as sqrt(2) and can do 100% precise operations on it. Like sqrt(2) * sqrt(2) will give you a result of 2 https://i.imgur.com/l83fwr2.png https://i.imgur.com/l83fwr2.png
- mamcx 9y agoAnd another dumb questions: Is possible to convert to rationals in calculations? So if I do: 1/3 + 4 + sum / total it record values properly?
- dreamcompiler 9y agoYes. Common Lisp is an example of a language that can represent rationals exactly and do arithmetic on them. You can avoid floating-point precision loss by using this method. But there are drawbacks: 1) The numerator and denominator will often turn into bignums as a calculation progresses, consuming ever-larger amounts of space and time, and 2) This won't help you with any calculation involving irrationals, except to prevent your initial imprecision from growing larger.