Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/typed-binary/src/io/bufferReader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BufferIOBase } from './bufferIOBase.ts';
import { float16ToNumber } from './float16converter.ts';
import type { ISerialInput } from './types.ts';
import { unwrapBuffer } from './unwrapBuffer.ts';

Expand Down Expand Up @@ -54,9 +53,9 @@ export class BufferReader extends BufferIOBase implements ISerialInput {
}

readFloat16(): number {
const value = this.dataView.getUint16(this.byteOffset, this.littleEndian);
const value = this.dataView.getFloat16(this.byteOffset, this.littleEndian);
this.byteOffset += 2;
return float16ToNumber(value);
return value;
}

readFloat32(): number {
Expand Down
7 changes: 1 addition & 6 deletions packages/typed-binary/src/io/bufferWriter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BufferIOBase } from './bufferIOBase.ts';
import { numberToFloat16 } from './float16converter.ts';
import type { ISerialOutput } from './types.ts';
import { unwrapBuffer } from './unwrapBuffer.ts';

Expand Down Expand Up @@ -50,11 +49,7 @@
}

writeFloat16(value: number): void {
this.dataView.setUint16(
this.byteOffset,
numberToFloat16(value),
this.littleEndian,
);
this.dataView.setFloat16(this.byteOffset, value, this.littleEndian);

Check failure on line 52 in packages/typed-binary/src/io/bufferWriter.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20.x)

packages/typed-binary/src/test/float.test.ts > Float16Schema > should handle NaN and Infinity

TypeError: this.dataView.setFloat16 is not a function ❯ BufferWriter.writeFloat16 packages/typed-binary/src/io/bufferWriter.ts:52:19 ❯ Float16Schema.write packages/typed-binary/src/structure/baseTypes.ts:274:12 ❯ Module.encodeAndDecode packages/typed-binary/src/test/helpers/mock.ts:21:10 ❯ packages/typed-binary/src/test/float.test.ts:80:22

Check failure on line 52 in packages/typed-binary/src/io/bufferWriter.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20.x)

packages/typed-binary/src/test/float.test.ts > Float16Schema > should encode and decode a f16 value

TypeError: this.dataView.setFloat16 is not a function ❯ BufferWriter.writeFloat16 packages/typed-binary/src/io/bufferWriter.ts:52:19 ❯ Float16Schema.write packages/typed-binary/src/structure/baseTypes.ts:274:12 ❯ Module.encodeAndDecode packages/typed-binary/src/test/helpers/mock.ts:21:10 ❯ packages/typed-binary/src/test/float.test.ts:62:22

Check failure on line 52 in packages/typed-binary/src/io/bufferWriter.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20.x)

packages/typed-binary/src/test/float.test.ts > Float16Schema > should encode and decode a f16 value near or equal a power of 2 with high precision

TypeError: this.dataView.setFloat16 is not a function ❯ BufferWriter.writeFloat16 packages/typed-binary/src/io/bufferWriter.ts:52:19 ❯ Float16Schema.write packages/typed-binary/src/structure/baseTypes.ts:274:12 ❯ Module.encodeAndDecode packages/typed-binary/src/test/helpers/mock.ts:21:10 ❯ packages/typed-binary/src/test/float.test.ts:37:22

Check failure on line 52 in packages/typed-binary/src/io/bufferWriter.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 16.x)

packages/typed-binary/src/test/float.test.ts > Float16Schema > should handle NaN and Infinity

TypeError: this.dataView.setFloat16 is not a function ❯ BufferWriter.writeFloat16 packages/typed-binary/src/io/bufferWriter.ts:52:19 ❯ Float16Schema.write packages/typed-binary/src/structure/baseTypes.ts:274:12 ❯ Module.encodeAndDecode packages/typed-binary/src/test/helpers/mock.ts:21:10 ❯ packages/typed-binary/src/test/float.test.ts:80:22

Check failure on line 52 in packages/typed-binary/src/io/bufferWriter.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 16.x)

packages/typed-binary/src/test/float.test.ts > Float16Schema > should encode and decode a f16 value

TypeError: this.dataView.setFloat16 is not a function ❯ BufferWriter.writeFloat16 packages/typed-binary/src/io/bufferWriter.ts:52:19 ❯ Float16Schema.write packages/typed-binary/src/structure/baseTypes.ts:274:12 ❯ Module.encodeAndDecode packages/typed-binary/src/test/helpers/mock.ts:21:10 ❯ packages/typed-binary/src/test/float.test.ts:62:22

Check failure on line 52 in packages/typed-binary/src/io/bufferWriter.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 16.x)

packages/typed-binary/src/test/float.test.ts > Float16Schema > should encode and decode a f16 value near or equal a power of 2 with high precision

TypeError: this.dataView.setFloat16 is not a function ❯ BufferWriter.writeFloat16 packages/typed-binary/src/io/bufferWriter.ts:52:19 ❯ Float16Schema.write packages/typed-binary/src/structure/baseTypes.ts:274:12 ❯ Module.encodeAndDecode packages/typed-binary/src/test/helpers/mock.ts:21:10 ❯ packages/typed-binary/src/test/float.test.ts:37:22

Check failure on line 52 in packages/typed-binary/src/io/bufferWriter.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 22.x)

packages/typed-binary/src/test/float.test.ts > Float16Schema > should handle NaN and Infinity

TypeError: this.dataView.setFloat16 is not a function ❯ BufferWriter.writeFloat16 packages/typed-binary/src/io/bufferWriter.ts:52:19 ❯ Float16Schema.write packages/typed-binary/src/structure/baseTypes.ts:274:12 ❯ Module.encodeAndDecode packages/typed-binary/src/test/helpers/mock.ts:21:10 ❯ packages/typed-binary/src/test/float.test.ts:80:22

Check failure on line 52 in packages/typed-binary/src/io/bufferWriter.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 22.x)

packages/typed-binary/src/test/float.test.ts > Float16Schema > should encode and decode a f16 value

TypeError: this.dataView.setFloat16 is not a function ❯ BufferWriter.writeFloat16 packages/typed-binary/src/io/bufferWriter.ts:52:19 ❯ Float16Schema.write packages/typed-binary/src/structure/baseTypes.ts:274:12 ❯ Module.encodeAndDecode packages/typed-binary/src/test/helpers/mock.ts:21:10 ❯ packages/typed-binary/src/test/float.test.ts:62:22

Check failure on line 52 in packages/typed-binary/src/io/bufferWriter.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 22.x)

packages/typed-binary/src/test/float.test.ts > Float16Schema > should encode and decode a f16 value near or equal a power of 2 with high precision

TypeError: this.dataView.setFloat16 is not a function ❯ BufferWriter.writeFloat16 packages/typed-binary/src/io/bufferWriter.ts:52:19 ❯ Float16Schema.write packages/typed-binary/src/structure/baseTypes.ts:274:12 ❯ Module.encodeAndDecode packages/typed-binary/src/test/helpers/mock.ts:21:10 ❯ packages/typed-binary/src/test/float.test.ts:37:22
this.byteOffset += 2;
}

Expand Down
31 changes: 0 additions & 31 deletions packages/typed-binary/src/io/float16converter.ts

This file was deleted.

4 changes: 3 additions & 1 deletion packages/typed-binary/src/test/float.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('Float16Schema', () => {
});

it('should encode and decode a f16 value', () => {
const value1 = 5472.5; // precision should be 4
const value1 = 5474; // precision should be 4
const value2 = 145; // precision should be 2^-2
const value3 = 0.34; // precision should be 2^-12
const value4 = 21877.5; // precision should be 16
Expand All @@ -64,6 +64,8 @@ describe('Float16Schema', () => {
const decoded3 = encodeAndDecode(f16, value3);
const decoded4 = encodeAndDecode(f16, value4);

// Nearest two representible numbers to 5474 are 5472 and 5476
expect(Math.abs(decoded1 - value1)).toEqual(2);
expect(decoded1).to.closeTo(value1, 4);
expect(decoded2).to.closeTo(value2, 0.25);
expect(decoded3).to.closeTo(value3, 0.000976);
Expand Down
Loading