Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downcasting of Signed Types Not Working #23

Open
Danielku15 opened this issue Jan 25, 2013 · 0 comments
Open

Downcasting of Signed Types Not Working #23

Danielku15 opened this issue Jan 25, 2013 · 0 comments

Comments

@Danielku15
Copy link

If you try to downcast any integer to a lower byte signed integer the output is wrong.

trace("i16: " + (i16)(65535));

Leads to "Unknown expression type: undefined". It works as long the casted integer is in range of the int16.

A solution could be to write the unsigned version of the target integer into a ArrayBuffer using the according view, then read it again from the target type view.

var castBuffer = new ArrayBuffer(2);
var i16 = new Int16Array(castBuffer);
var u16 = new Uint16Array(castBuffer);
var i8 = new Int8Array(castBuffer);
var u8 = new Uint8Array(castBuffer);

exports.toInt16 = function (i) { u16[0] = i & 65535; return i16[0]; }
exports.toInt8 = function (i) { u8[0] = i & 255; return i8[0]; }

Downcasting float64 to float32 could be hard. I don't have a solution for this yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant