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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -