From 8ce9b92c8196534f2ff641575874afaede762bc2 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 5 Oct 2020 00:23:20 +0100 Subject: [PATCH] wip js testing Signed-off-by: Ian Jackson --- templates/bigfloat-tests.ts | 15 +++++++++++++++ templates/bigfloat.ts | 1 + 2 files changed, 16 insertions(+) create mode 100644 templates/bigfloat-tests.ts diff --git a/templates/bigfloat-tests.ts b/templates/bigfloat-tests.ts new file mode 100644 index 00000000..bc87f45a --- /dev/null +++ b/templates/bigfloat-tests.ts @@ -0,0 +1,15 @@ +// -*- JavaScript -*- +// Copyright 2020 Ian Jackson +// SPDX-License-Identifier: AGPL-3.0-or-later +// There is NO WARRANTY. + +function assert_eq(a,b) { if (a != b) throw('unequal ' + a + ' ' + b); } + +x = "!0000 ffff_ffff_fff0"; +y = "!0000 0000_0000_0040"; +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(), "+0000x 0000_0000_0030"); diff --git a/templates/bigfloat.ts b/templates/bigfloat.ts index 9535f472..dc9ac269 100644 --- a/templates/bigfloat.ts +++ b/templates/bigfloat.ts @@ -131,6 +131,7 @@ namespace Bigfloats { for (;;) { v.limbs[i] = Math.floor(v.limbs[i] + step); if (v.limbs[i] < LIMB_MODULUS) return totadj; + v.limbs[i] %= LIMB_MODULUS; i--; if (i < 0) { if (v.sign < 0) { v.sign = +1; return totadj; } -- 2.30.2