math - Implementation of square root method in Javascript -


my partner , working on deterministic physics engine run same on various platforms. in order make such thing, using either fixed point or truncated floating point math (we'll figure out later). however, in order engine ported javascript, have make sure double precision floating point operations in javascript use consistent whatever operations using in desktop port.

with in mind, question is: how math.sqrt() implemented in javascript? if there different implementations across browsers, implementations? or, if there no answer previous questions, maximum amount of error math.sqrt() can produce?

we prefer not write our own square root function since natively implemented math.sqrt() outperform whatever write in javascript.

ecma-262 (the ecmascript 5.1 specification) not require specific implementation math.sqrt , requires specific results unusual number values (nan, -0, etc):

15.8.2.17 sqrt (x)

returns implementation-dependent approximation square root of x.

  • if x nan, result nan.
  • if x less 0, result nan.
  • if x +0, result +0.
  • if x -0, result -0.
  • if x +infinity, result +infinity.

Comments