Re: (default) Real->Rat precision should match what compiler uses for literals
[email protected] (Solomon Foster) Sun, 4 Mar 2018 08:24:56 -0500
| Newsgroups | perl.perl6.language |
|---|---|
| Message-ID | <CALpVjkiDdr9Kbg=n3CJOCMQyrYVLU_i5YjVybJhqp-BW+uK9Mg@mail.gmail.com> |
--f403045f8bd6bca6350566962292 Content-Type: text/plain; charset="UTF-8" On Sat, Mar 3, 2018 at 3:32 PM, yary <[email protected]> wrote: > Or instead of 1/2**(32 or 64), re-asking these questions about epsilon: > > " Why so large? > > Why not zero? " > > What's justification for using 1/100,000 vs. something smaller vs. 0 "max > possible precision?" > The problem with using max possible precision is that you will generate a Rat with a large denominator. And when you start doing math with those, the results will usually flip back over to Nums pretty quickly. But if you went through the trouble of converting your number from a Num to a Rat, presumably it's because you wanted to work with Rats, so ending up with a Num again is a frustrating result. I don't remember if I was responsible for 1e-6 as the epsilon or not, but it's quite possible it was me, because in my experience that number is a common 3D tolerance in CAD software (I believe it's the default in ACIS) and I tend to grab it for that purpose. My intuition is that the number should probably be between 1e-6 and 1e-8, but it would be great if someone wanted to put in some research/testing to figure out a better value. It's important to remember that the purpose of Rat in p6 is to dodge around the common pitfalls of floating point numbers in casual use, while degrading to Num to prevent your calculations from crawling to a halt when the denominator gets too big. For real world measures, a double's 15 digits of accuracy is normally overkill. (If I'm doing the math right, if you had a CAD model of the second Death Star in meters, 15 digits would allow you to specify dimensions to the nanometer.) If you actually need unbounded precision, then you should be using FatRats. One thing I think we absolutely should have is a quick and easy way to convert from Num to FatRat with minimal loss of precision. I believe right now the default Num -> FatRat conversion also uses 1e-6 as an epsilon, which seems wrong to me. -- Solomon Foster: [email protected] HarmonyWare, Inc: http://www.harmonyware.com --f403045f8bd6bca6350566962292 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On S= at, Mar 3, 2018 at 3:32 PM, yary <span dir=3D"ltr"><<a href=3D"mailto:no= [email protected]" target=3D"_blank">[email protected]</a>></span> wrote:<= br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left= :1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>Or instead of 1/2**= (32 or 64), re-asking these questions about epsilon:<br><br>"=C2=A0 Wh= y so large?<br> <br>=C2=A0=C2=A0 Why not zero?=C2=A0 "<br> <br></div>What's justification for using 1/100,000 vs. something smalle= r vs. 0 "max possible precision?"<br></div> </blockquote></div><div class=3D"gmail_extra"><br></div><div class=3D"gmail= _extra">The problem with using max possible precision is that you will gene= rate a Rat with a large denominator.=C2=A0 And when you start doing math wi= th those, the results will usually flip back over to Nums pretty quickly.= =C2=A0 But if you went through the trouble of converting your number from a= Num to a Rat, presumably it's because you wanted to work with Rats, so= ending up with a Num again is a frustrating result.</div><div class=3D"gma= il_extra"><br></div><div class=3D"gmail_extra">I don't remember if I wa= s responsible for 1e-6 as the epsilon or not, but it's quite possible i= t was me, because in my experience that number is a common 3D tolerance in = CAD software (I believe it's the default in ACIS) and I tend to grab it= for that purpose.=C2=A0 My intuition is that the number should probably be= between 1e-6 and 1e-8, but it would be great if someone wanted to put in s= ome research/testing to figure out a better value.</div><div class=3D"gmail= _extra"><br></div><div class=3D"gmail_extra">It's important to remember= that the purpose of Rat in p6 is to dodge around the common pitfalls of fl= oating point numbers in casual use, while degrading to Num to prevent your = calculations from crawling to a halt when the denominator gets too big.=C2= =A0 For real world measures, a double's 15 digits of accuracy is normal= ly overkill.=C2=A0 (If I'm doing the math right, if you had a CAD model= of the second Death Star in meters, 15 digits would allow you to specify d= imensions to the nanometer.)</div><div class=3D"gmail_extra"><br></div><div= class=3D"gmail_extra">If you actually need unbounded precision, then you s= hould be using FatRats.=C2=A0 One thing I think we absolutely should have i= s a quick and easy way to convert from Num to FatRat with minimal loss of p= recision.=C2=A0 I believe right now the default Num -> FatRat conversion= also uses 1e-6 as an epsilon, which seems wrong to me.</div><div class=3D"= gmail_extra"><br></div><div class=3D"gmail_extra">--=C2=A0<br></div><div cl= ass=3D"gmail_signature" data-smartmail=3D"gmail_signature">Solomon Foster: = <a href=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a= ><br>HarmonyWare, Inc: <a href=3D"http://www.harmonyware.com" target=3D"_bl= ank">http://www.harmonyware.com</a></div> </div></div> --f403045f8bd6bca6350566962292--