Trig inaccuracy

I am using the trig functions in Snap, and noticed that they are not completely accurate. For example, Fourier script pic sin(180) should return 0, not a really small number. Do this have to do with the fact that JavaScript uses radians, but Snap uses degrees? For example Fourier script pic (1) returns 0 because 0 is the same in degrees and radians. However Fourier script pic returns a decimal because (I think) 180 must be converted to π radians. Just thought I should point this out.

Yes, I keep telling Jens that the right way to do trig functions in degrees is to start by converting the angle in degrees to something in the range [0, 45], which may involve swapping sin with cos and may involve changing the sign of the eventual result, then multiply by π/180, which is how Prof. Kahan says to do it, but he (Jens) doesn't believe me that it matters.

It seems as if such a small error would not matter, but the problem is not that is an error of 10^-16 at an arbitrary number, but the fact that sin(0) is not 0, which is a known value. For example untitled script pic (8) would never report true, even though it is within one quadrillionth of 0.

Sans titre script pic

Here is what I learned in my computer science course: when using floating-point arithmetic, check for close enough, not equality.

Instead of [scratchblocks]<(number) = (what I want)>[/scratchblocks],

do [scratchblocks]<([abs v] of ((number) - (what I want))) < [0.001]>[/scratchblocks].

Sorry, I meant to say that sin of 180 is not 0:
untitled script pic (9)

Yeah I knew that, just not quite awake. Sorry. But my answer about how to compute trig functions of angles in degrees still stands.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.