JavaScript VS PHP: The same calculation returns different result -


i'm trying simple math (?) in javascript:

( 1023 * 2 ) + 76561197960265728; 

i did same calculation in php, results different:

javascript: 76561197960267780

php: 76561197960267774 (the right result)

i tried following: http://jsfiddle.net/yxba4/

is there "limit" in javascript high numbers in calculations?

//edit:

thanks answers, use bignumber one.

my full working code now:

on jsfiddle

the value 76561197960265730 id greater maximum allowed number size in javascript. note there no real integers in javascript number type 64bit floating point value , platform independent. largest possible integer value 2^53 because 11 bits @ least reserved numbers after comma , signage bit.

in example can see doing:

alert(76561197960265728); 

what give error, without calculations. (output: '76561197960265730')

in php maximum integer value depends on system. if on 64 bit system, max integer value 2^64 greater (2 * 1023) + 76561197960265728. that'swhy calculation succeeded in php - on 64 bit system

in php can detect maximum integer size on system reading constant php_int_max , `


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -