javascript - Why does node not evaluate Math.tan(Math.PI/2) to Infinity but Chrome V8 does? -
when running in node command-line interface:
> math.tan(math.pi/2) 16331778728383844
but in chrome:
> math.tan(math.pi/2) infinity
aren't both using same v8 engine?
node's result not equal maximum "integer" value in javascript.
if @ v8 implementation of math
object, see:
function mathtan(x) { return mathsin(x) / mathcos(x); }
indeed, math.cos(math.pi/2)
returns unusual value in node (in fact, reciprocal of unusual math.tan
result):
> math.cos(math.pi/2) 6.123031769111886e-17 // in chrome, 0
so, question reduces to: why math.cos(math.pi/2)
non-zero in node <=0.10.24?
this difficult answer. implementation of sine , cosine supplied math-heavy function called trigonometricinterpolation
, relies on reverse lookup table of 1800 sample values generated c++ code, code generated a python script when v8 first installed.
it worth noting, however, current trig lookup table code very replaced older lookup table, current release of node may not using recent trig lookup table (since new code arrived in v8 on nov. 22, 2013, the pull v8 node prior 0.10.24 release in december 2013 on nov 11, 2013, eleven days prior change). chrome using up-to-date code, while current stable node using different trigonometric code.
Comments
Post a Comment