chiark / gitweb /
bigfloat.ts fixes
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 5 Oct 2020 18:40:19 +0000 (19:40 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 5 Oct 2020 18:40:19 +0000 (19:40 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
templates/bigfloat-tests.ts
templates/bigfloat.ts

index 40652a2739715cfdf67abcba2719b1741929eebf..d2c50cbd14e2c4a4021d8d26d00ec90c137ce96e 100644 (file)
@@ -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");
index dc9ac26988b07cf01c21056b9080ec8ddfaf616d..790dc5dd94132325ac1d578a3333b4a92405b2b3 100644 (file)
@@ -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);