Skip to content

Commit

Permalink
infinity and nan tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reczkok committed Oct 14, 2024
1 parent a9028be commit d03fd70
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/typed-binary/src/test/float.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,18 @@ describe('Float16Schema', () => {
expect(decoded3).to.closeTo(value3, 0.000976);
expect(decoded4).to.closeTo(value4, 16);
});

it('should handle NaN and Infinity', () => {
const value1 = Number.POSITIVE_INFINITY;
const value2 = Number.NEGATIVE_INFINITY;
const value3 = Number.NaN;

const decoded1 = encodeAndDecode(f16, value1);
const decoded2 = encodeAndDecode(f16, value2);
const decoded3 = encodeAndDecode(f16, value3);

expect(decoded1).to.equal(value1);
expect(decoded2).to.equal(value2);
expect(decoded3).to.be.NaN;
});
});

0 comments on commit d03fd70

Please sign in to comment.