calc
calc copied to clipboard
sin and tan
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.
I've noticed this too, but it's likely a problem with Go itself, not with calc
: https://play.golang.org/p/c2-ZAgTXmt
Float64 has about 15 significant digits, so why not truncate?: http://play.golang.org/p/rmdSC3197k
The utility uses floating-point numbers, so this is working as intended.
…
sin(pi)
gives1.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
.