Additional float conversion tests (#1550)

This commit is contained in:
Jaco
2022-06-20 08:09:51 +03:00
committed by GitHub
parent 540971d388
commit c4ceeb8382
2 changed files with 14 additions and 0 deletions
+1
View File
@@ -54,6 +54,7 @@ describe('floatToU8a', (): void => {
foo = 'bar';
}
// https://www.h-schmidt.net/FloatConverter/IEEE754.html
expect(
u8aToHex(floatToU8a(new Test(123.456)))
).toEqual('0x79e9f642');
+13
View File
@@ -41,6 +41,19 @@ describe('u8aToFloat', (): void => {
u8aToFloat(hexToU8a('0x0000c07f'))
).toEqual(Number.NaN);
});
// https://www.h-schmidt.net/FloatConverter/IEEE754.html
it('decodes a known number', (): void => {
expect(
u8aToFloat(hexToU8a('0x79e9f642')).toFixed(3)
).toEqual('123.456');
});
it('decodes a known number (BE)', (): void => {
expect(
u8aToFloat(hexToU8a('0x42f6e979'), { isLe: false }).toFixed(3)
).toEqual('123.456');
});
});
describe('64-bit', (): void => {