feat: yaaay first stem

This commit is contained in:
2024-04-18 00:02:50 +02:00
parent 1da13523ea
commit 2edd22136f
21 changed files with 297 additions and 102 deletions

View File

@@ -0,0 +1,19 @@
// Create a buffer to hold the float as bytes
const buffer = new ArrayBuffer(4);
const view = new DataView(buffer);
export function encodeFloat(value: number): number {
// Write the number as a float to the buffer
view.setFloat32(0, value, true); // 'true' for little-endian
// Read the buffer as an integer
return view.getInt32(0, true);
}
export function decodeFloat(value: number): number {
// Write the integer back as an int32
view.setInt32(0, value, true);
// Read the buffer as a float
return view.getFloat32(0, true);
}