Convert between int [ish] and double [ish] in asm.js

If I need to, say, find the integer part and fractional part of a number in the asm.js module, how to do this? None of the standard operators convert between regular and double types; even Math.floor returns double, and its result cannot be forced to int.

var floor = stdlib.Math.floor; function(n) { n = +n; var a = 0; a = floor(n)|0; // fails: "Operands to bitwise ops must be intish" var b = 0.0; b = +(na); // would fail if compiler got to here return; } 
+7
source share
1 answer

Vyacheslav Egorov (twitter: @mraleph) says: use ~~ to force an int. Special Verification Case: http://asmjs.org/spec/latest/#unaryexpression

 a = ~~floor(n); // success! 
+10
source

All Articles