From: Ian Jackson Date: Mon, 5 Oct 2020 18:40:19 +0000 (+0100) Subject: bigfloat.ts fixes X-Git-Tag: otter-0.2.0~742 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=92b647172f77543deefaa5e0e12fcd9998c15568;p=otter.git bigfloat.ts fixes Signed-off-by: Ian Jackson --- diff --git a/templates/bigfloat-tests.ts b/templates/bigfloat-tests.ts index 40652a27..d2c50cbd 100644 --- a/templates/bigfloat-tests.ts +++ b/templates/bigfloat-tests.ts @@ -4,14 +4,29 @@ // There is NO WARRANTY. function assert_eq(a: string, b: string) { - if (a != b) throw('unequal ' + a + ' ' + b); + if (a == b) return; + console.log(['unequal', a, b]); + throw('unequal'); } -let x = "!0000 ffff_ffff_fff0" as any; -let y = "!0000 0000_0000_0040" as any; -let i = Bigfloats.iter_upto(x, y, 4); +let x : any; +let y : any +let i : any + +x = "!0000 ffff_ffff_fff0" as any; +y = "!0000 0000_0000_0040" as any; +i = Bigfloats.iter_upto(x, y, 4); assert_eq(i(), "+0000 0000_0000_0000"); assert_eq(i(), "+0000 0000_0000_0010"); assert_eq(i(), "+0000 0000_0000_0020"); assert_eq(i(), "+0000 0000_0000_0030"); + +x = "!0000 ffff_ffff_fffe" as any; +y = "!0000 0000_0000_0001" as any; +i = Bigfloats.iter_upto(x, y, 4); + +assert_eq(i(), "!0000 ffff_ffff_ffff 3333_3333_3333"); +assert_eq(i(), "!0000 ffff_ffff_ffff 6666_6666_6666"); +assert_eq(i(), "!0000 ffff_ffff_ffff 9999_9999_9999"); +assert_eq(i(), "!0000 ffff_ffff_ffff cccc_cccc_cccc"); diff --git a/templates/bigfloat.ts b/templates/bigfloat.ts index dc9ac269..790dc5dd 100644 --- a/templates/bigfloat.ts +++ b/templates/bigfloat.ts @@ -80,10 +80,11 @@ namespace Bigfloats { export function pack(v: Unpacked): Packed { function hex16(x: number) { return ('000' + x.toString(16)).slice(-4); } function hex48(x: Limb) { - return (hex16(Math.floor(x / 0x100000000) ) + '_' + - hex16( (x & 0xffff0000) >> 16 ) + '_' + - hex16( x & 0x0000ffff ) ); + return (hex16(Math.floor(x / 0x100000000 ) ) + '_' + + hex16( (x >> 16) & 0x0000ffff ) + '_' + + hex16( x & 0x0000ffff ) ); } +//# console.log('pack', v); return ( (v.sign < 0 ? '!' : '+') + hex16(v.exponent) + ' ' + @@ -181,6 +182,7 @@ namespace Bigfloats { current.limbs.length = i; current.limbs[i] = 0; } +//# console.log('will iter',current,step,avail); return function() { i += add_to_limb(current, i, step); return pack(current);