From: Colin Bartlett Date: 2009-12-24T01:27:52+09:00 Subject: Re: Trig value errors jzakiya wrote > We know cos(PI/2)=0 not 6.123023176911189e-17, > so round it, truncate, whatever, to 0. But Ruby PI is not (exactly) the mathematical pi, so it's going to be difficult to decide in cos(x), with x very close to pi/2, whether x was "really" pi/2, or something a bit different from pi/2 ? Phrogz wrote: > I thought asking Alpha would be an easy place to start. > ... > http://www.wolframalpha.com I didn't know about WolframAlpha! Thanks! sin(pi/2) #=> 1 tan(pi/2) #=> infinity; so far, so good sin(pi*0.5) #=> 1 sin(pi*0.5) - 1 #=> 0 "number name zero", so it is zero! tan(pi*0.5) #=> 1.63312 x 10^16 (Actually in some ways I find that last result a little surprising, because floating point holds 0.5 exactly. But also not surprising!) Since Fleck Jean-Julien mentioned Octave: > Well, what you are looking for is ... or Octave, > some kind of symbolic mathematics software. > ... But even there you can still quite easily find > "mathematical bugs" that is results that are not in the > simplest form expected even by my least gifted students. A naive user (me) of Octave gets: sin(pi/2) #=> 1 cos(pi/2) #=> 6.123....189e-017 (By naive, I mean that a more experienced user might be able to do better than that.)