javascript - discrepancy between Float32Array and DataView -


thought understood how float32array works, looks i'm not quite there. in simplest example possible:

buffer = new arraybuffer(128); dataview = new dataview(buffer); floatarray = new float32array(buffer);  dataview.setfloat32(8, 7); console.log(floatarray[2]); //prints gibberesh 

the way understood it, data view should set float starting @ 8th byte 7, third float in float array expect 7.

what missing here?

thanks

this makes work, last parameter being littleendian

dataview.setfloat32(8, 7, true); 

this might better, although can't sure. presumably float32array uses system's littleendian, while dataview can use either.

var littleendian = (function() {   var buffer = new arraybuffer(2);   new dataview(buffer).setint16(0, 256, true);   return new int16array(buffer)[0] === 256; })();  dataview.setfloat32(8, 7, littleendian); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -