From: jzakiya Date: 2009-12-24T09:45:25+09:00 Subject: Re: Trig value errors On Dec 23, 1:05 pm, pharrington wrote: > On Dec 23, 12:35 pm, jzakiya wrote: > > > > > Dear Matz, > > > I use a Linux calculator named Qaculate. > > I do not know the people who designed and > > coded it, but it makes me happy. Why? > > > When I put in sin(180) it outputs '0' > > not 1.22460635382238e-16, and when I change > > to radians for angles and do sin(PI) it > > also gives '0' and not 1.22460635382238e-16. > > > This makes me happy. > > > In fact, this little Linux calculator produces > > all the correct (exact) answers for angles on > > an axis for both cos and sin, whether you input > > the angles in degrees or radians. Astonishing!! > > > I don't now anything about how the people who > > designed and implemented Qalculate decided to > > use whatever language they chose to write it in, > > or what libraries they decided to use. I don't > > know (or care) about any of those under-the-hood > > things. > > > What I do KNOW is that the people who designed and > > implemented this calculator CARED that it produced > > the mathematically exact results for those angles. > > > This makes me happy. > > > I use another add-on calculator for Firefox, called, > > tada! Calculator. Again, I don't know the people who > > designed and/or coded it, and I don't know what > > language or libraries they used to do it in either. > > But when I use this little calculator in Firefox I do > > know I get sin(PI) = 0, not 1.22460635382238e-16. > > > So, for this calculator too, somebody(s) CARED enough > > to make sure the answers came out correctly (exact) > > for angles on an axis too. So when I use this calculator, > > > This makes me happy. > > > I think Ruby is a Great language, and a fun language. > > And I agree with your philosophy that languages that > > people use should serve them, not the other way around. > > > So I humbly tell you I am Surprised that Ruby produces > > the math errors I've illustrated in this thread, and > > > This makes me unhappy. > > > So I am asking you to see that these errors be fixed. > > > If Qaculator and Calculator can produce the correct > > results, then so can Ruby. All that is necessary is that > > you CARE enough that it does it. > > > It would make me very happy if I could share my code, and > > not have to include patches and redefinitions in it just > > to assure other people get the same (exact) results I do. > > > I agree with your Principle of Least Surprises (POLS). > > > The language should work to please the user. > > The language should be intuitive to the user. > > The language should not cause unnecessary surprises. > > > So please, fix these errors. > > > This will make me happy. > > > Thanks > > Also, as an example: > > static VALUE > math_cos(VALUE obj, VALUE x) > { >     Need_Float(x); >     return DBL2NUM(cos(RFLOAT_VALUE(x))); > > } > > If you have a beef with anyone, its with the implementers of the C > standard library, but... Try this (with correct syntax if wrong). Do similar for sin. static VALUE math_cos(VALUE obj, VALUE x) { Need_Float(x); cos_value = DBL2NUM(cos(RFLOAT_VALUE(x))); if (abs(cos_value) < 1e-10) cos_value 0.0; return cos_value; }