From: jzakiya Date: 2009-12-24T09:55:05+09:00 Subject: Re: Trig value errors On Dec 23, 7:45 pm, Seebs wrote: > On 2009-12-24, jzakiya wrote: > > > 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; > > } > > That'd be exceptionally stupid. > > Here's the problem:  There exists at least one value for which the correct > value of cos(x) is about 9e-11, which can be correctly represented (within > a much, much, smallermargin of error) in a floating point value, and which > you would then "fix" by changing it from not-zero to exactly-zero. > > Which is to say, this would introduce a comparatively HUGE error, much larger > than the alleged error you're complaining about. > > If you want approximate values, round them. > > -s > -- > Copyright 2009, all wrongs reversed.  PeterSeebach/ usenet-nos...@seebs.nethttp://www.seebs.net/log/<-- lawsuits, religion, and funny pictureshttp://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! > Here's the problem: There exists at least one value for which the correct > value of cos(x) is about 9e-11, which can be correctly represented (within) And what (extremely small) angle(s) would that be? Provide examples please: If so then do: if (abs(cos_value) < 1e-14) cos_value = 0.0; This provides the correct answers for the errors I illustrated. This makes me happy. :-)