Created
July 20, 2021 18:04
-
-
Save remy/2edf4cf37f32cf2571e491d3b014faf0 to your computer and use it in GitHub Desktop.
The int16 is to keep the bytes in the data type and not slip into 32bit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const scale = 8; | |
const d2f = (x) => Uint16Array.of(x * (1 << scale)); | |
const f2d = (x) => Int16Array.of(x)[0] / (1 << scale); | |
const mul = (x, y) => Uint16Array.of(((x[0] >> 4) * (y[0] >> 2)) >> 2); | |
const a = d2f(-5); // ? | |
f2d(a) // ? | |
const b = d2f(0.8) // ? | |
f2d(b) // ? | |
const c = mul(a, b) // ? | |
// should be -4 | |
f2d(c) // ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment