From: Benoit Daloze Date: 2009-12-24T04:53:34+09:00 Subject: Re: Trig value errors --0016e65b54164714ea047b6aad41 Content-Type: text/plain; charset=ISO-8859-1 If you want more precision, you could use BigDecimal (and BigMath). Then you would get something like: irb(main):025:0> p=2000; cos(PI(p)/2, p).to_s => "0.64773210554205705...E-2016" irb(main):026:0> p=2000; sin(PI(p)/2, p).to_s => "0.99999999999999999999999999999999999999...E0" Well, I think it's safe to round the 2016th decimal, isn't it ? Also rounding a ton of 9. So, rounding to the precision(2000), you get what you want. irb(main):036:0> p=20; cos(PI(p)/2, p).round(p).to_f => 0.0 irb(main):037:0> p=20; sin(PI(p)/2, p).round(p).to_f => 1.0 And well, you really don't need 2000 of precision, 20 is far enough in this case. 2009/12/23 Phrogz > On Dec 23, 12:11 am, jzakiya wrote: > > > On Dec 22, 10:07 pm, Phrogz wrote: > > > > irb(main):004:0> x = cos(onedegree/1e06) > > > > => 1.0 > > > > irb(main):005:0> x - 1.0 > > > > => -1.11022302462516e-16 > > > > irb(main):006:0> puts "%.30f" % x > > > > 0.999999999999999888977697537484 > > > This didn't nullify THE POINT I illustrated, which was > > using an increasingly smaller angle approaching zero as > > an argument, it eventually produced a value of '1' for > > cos, but not '0' for the same sin angle, as it should. > > No, it didn't produce a value of 1. Look at the second part of my > post, which you quoted, at the top of this message. > > --0016e65b54164714ea047b6aad41--