admin管理员组文章数量:1415654
If I need to, say, find the the integer part and the fractional part of a number within an asm.js module, how do I do it? None of the standard operators convert between intish and doubleish types; even Math.floor returns a double, and its result can't be coerced to an 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 = +(n-a); // would fail if piler got to here
return;
}
If I need to, say, find the the integer part and the fractional part of a number within an asm.js module, how do I do it? None of the standard operators convert between intish and doubleish types; even Math.floor returns a double, and its result can't be coerced to an 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 = +(n-a); // would fail if piler got to here
return;
}
Share
Improve this question
asked May 21, 2013 at 22:25
ZachBZachB
15.5k5 gold badges66 silver badges93 bronze badges
1 Answer
Reset to default 10Vyacheslav Egorov (twitter:@mraleph) says: use ~~
to coerce to an int. Special validation case: http://asmjs/spec/latest/#unaryexpression
a = ~~floor(n); // success!
本文标签: javascriptConverting between intish and doubleish in asmjsStack Overflow
版权声明:本文标题:javascript - Converting between int[ish] and double[ish] in asm.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745177311a2646297.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论