Skip to content

Instantly share code, notes, and snippets.

@carlopi
Last active February 2, 2022 08:18
Show Gist options
  • Save carlopi/7fa7d9df3d943f43043d514ec1ca41b4 to your computer and use it in GitHub Desktop.
Save carlopi/7fa7d9df3d943f43043d514ec1ca41b4 to your computer and use it in GitHub Desktop.
signBit JavaScript implementation
function signBit(La){
var Lgh_u$pi=null,tmp1=0;
Lgh_u$pi={d:new DataView(new ArrayBuffer(8)),o:0};
Lgh_u$pi.d.setFloat64(Lgh_u$pi.o,La,true);
tmp1=Lgh_u$pi.d.getInt32(1*4+Lgh_u$pi.o,true)|0;
return ((tmp1|0)<0?1:0)|0;
}
//or way better perfromance wise, having the DataView being globally available (=created only once)
var Lgh_u$pi=new DataView(new ArrayBuffer(8));
function signBit(La){
var tmp1=0;
Lgh_u$pi.setFloat64(0,La,true);
tmp1=Lgh_u$pi.getInt32(4,true)|0;
return ((tmp1|0)<0?1:0)|0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment