From: Seebs Date: 2009-12-24T09:50:09+09:00 Subject: Re: Trig value errors 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, smaller margin 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. Peter Seebach / usenet-nospam@seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!