Additional float conversion tests (#1550)
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user