optimization - In JavaScript, how do I ensure floating point numbers stay under 32bits? -
obviously numbers in javascript aren't explicitly typed, represented types interpreter. saw thing google's v8 js engine said it's optimized 32 bit numbers, found odd many js programmers have need doubles floating point. examples think of if i'm dividing 2 integers, in order normalize screen coordinates between 0 , 1, , interpreter truncating result @ 64 bits instead of 32. seems unlikely me, again don't know how else needing such precision specify it. i'm wondering...is there way ensure quotient of 2 (not gigantic) integers under 32 bits in length?
i saw thing google's v8 js engine said it's optimized 32 bit numbers
this means v8 internally store numbers integers when can deduce stay in respective range. common counters or array indices, example.
is there way ensure quotient of 2 (not gigantic) integers under 32 bits in length?
no - arithmetic operations carried out if 64 bit floating point numbers (like numbers in js). thing can truncate result 32 bit integer. you'll use bitwise right shift operator internally casts operands integers:
var q = (a / b) >>> 0;
see what javascript >>> operator , how use it? details.
Comments
Post a Comment