From: Ian Jackson Date: Sun, 4 Oct 2020 23:23:20 +0000 (+0100) Subject: wip js testing X-Git-Tag: otter-0.2.0~748 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=8ce9b92c8196534f2ff641575874afaede762bc2;p=otter.git wip js testing Signed-off-by: Ian Jackson --- 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; }