calc icon indicating copy to clipboard operation
calc copied to clipboard

sin and tan

Open nunull opened this issue 10 years ago • 3 comments

sin and tan don't seem to work correctly. sin(pi) gives 1.2246467991473515E-16 and tan(pi) -1.2246467991473515E-16, while cos works as expected.

nunull avatar Feb 18 '15 20:02 nunull

I've noticed this too, but it's likely a problem with Go itself, not with calc: https://play.golang.org/p/c2-ZAgTXmt

alfredxing avatar Feb 18 '15 21:02 alfredxing

Float64 has about 15 significant digits, so why not truncate?: http://play.golang.org/p/rmdSC3197k

rpopplewell avatar Feb 19 '15 00:02 rpopplewell

The utility uses floating-point numbers, so this is working as intended.

sin(pi) gives 1.2246467991473515E-16

sin(pi) in floating-point arithmetic is not the same as sin(π) in math. What sin(pi) calculates is the approximate value of sine at the approximate value pi. Since pi is not equal to the true π (in fact, it's off by about 1.22E-16 … does this number look familiar?), that imprecision leads to an imprecision in the value of sin(pi).

…, so why not truncate?: http://play.golang.org/p/rmdSC3197k

Float64 has 15-18 significant digits, not decimal places. 1.22464679914735E-16 truncated to 15 significant digits is still 1.22464679914735E-16.

Rufflewind avatar Aug 07 '15 04:08 Rufflewind