// SPDX-License-Identifier: AGPL-3.0-or-later
// There is NO WARRANTY.
-// This is a really really shonky BigFloat with only a handful of
-// operations available!
-
-
-// Representation, and model, ought to have these properties
-// CBOR is binary and compact
-// * JSON is not lossy
-// * JSON is human-comprehensible
-// * JavaScript can compare efficiently
-// JavaScript can do arithmetic efficiently
-// * Limb size is 48 for fast JS arithmetic
-// Limb size is small for not being too full of padding
-// * Limb size is big so step algorithm rarely encounters limb boundaries
-//
-// Many of these are not compatible (in theory extending
-// the serde data model might help a bit, but not completely).
-// We choose those properties marked with "*".
-//
-// Main representation is a string:
-// VVVVVVVVVV_VVVVVVVVVV ...]
-// where
-// VVVVVVVVVV = 50 bits in lowercase base32hex ("0-9a-..."), unsigned
-// Value is a whole number of 50-bit groups ("limbs"), at least one sucb.
-//
-// The abstract value is completed by an infinite number of zero
-// limbs to the right. Trailing zero limbs are forbidden in the
-// representation.
-//
-// Supported operations are:
-//
-// Total ordering
-// Values are compared lexically.
-//
-// Select initial value:
-// g000000000
-//
-// Pick a value (or "n" values) strictly in between any two
-// existing values.
-//
-// Find first limb that they differ. Divide intervening values
-// for tht limb evenly (ie divide the range by n+1). If this
-// leaves less than an increment of 1 per output value, do
-// differently: choose a value halfway (rounding down) for the
-// first differeing limb, and add a new limb, whose whole range
-// 0000000000..vvvvvvvvvv is divided evenly into n+1 (thus
-// guaranteeing that the added limb is nonzero).
-//
-// Pick a value later than a specified value.
-//
-// Try to add delta to rightmost nonzero limb, with carry. If
-// this would overflow top limb, start again: add two limbs
-// 0000000000 and then redo (this guarantees that one of the
-// added limbs iis nonzero). Delta is 0001000000.
-//
-// Pick a value earlier than a specified value.
-//
-// Try to subtract delta from rightmost nonzero limb, with
-// borrow. If this would underflow, or would leave leftmost
-// limb equal to 0000000000, start again: decrement rightmost
-// nonzero limb by 1, with borrow, then add two limbs
-// vvvvvvvvvv, and redo.
-
type Bigfloat = Bigfloats.Packed;
namespace Bigfloats {
// SPDX-License-Identifier: AGPL-3.0-or-later
// There is NO WARRANTY.
-// See zcoord.ts
+// This is a multiprecision sort-of-bigfloat with only a handful of
+// operations available!
+//
+// Representation, and model, ought to have these properties
+// CBOR is binary and compact
+// * JSON is not lossy
+// * JSON is human-comprehensible
+// * JavaScript can compare efficiently
+// JavaScript can do arithmetic efficiently
+// * Limb size is 48 for fast JS arithmetic
+// Limb size is small for not being too full of padding
+// * Limb size is big so step algorithm rarely encounters limb boundaries
+//
+// Many of these are not compatible (in theory extending
+// the serde data model might help a bit, but not completely).
+// We choose those properties marked with "*".
+//
+// Main representation is a string:
+// VVVVVVVVVV_VVVVVVVVVV ...]
+// where
+// VVVVVVVVVV = 50 bits in lowercase base32hex ("0-9a-..."), unsigned
+// Value is a whole number of 50-bit groups ("limbs"), at least one sucb.
+//
+// The abstract value is completed by an infinite number of zero
+// limbs to the right. Trailing zero limbs are forbidden in the
+// representation.
+//
+// Supported operations are:
+//
+// Total ordering
+// Values are compared lexically.
+//
+// Select initial value:
+// g000000000
+//
+// Pick a value (or "n" values) strictly in between any two
+// existing values.
+//
+// Find first limb that they differ. Divide intervening values
+// for tht limb evenly (ie divide the range by n+1). If this
+// leaves less than an increment of 1 per output value, do
+// differently: choose a value halfway (rounding down) for the
+// first differeing limb, and add a new limb, whose whole range
+// 0000000000..vvvvvvvvvv is divided evenly into n+1 (thus
+// guaranteeing that the added limb is nonzero).
+//
+// Pick a value later than a specified value.
+//
+// Try to add delta to rightmost nonzero limb, with carry. If
+// this would overflow top limb, start again: add two limbs
+// 0000000000 and then redo (this guarantees that one of the
+// added limbs iis nonzero). Delta is 0001000000.
+//
+// Pick a value earlier than a specified value.
+//
+// Try to subtract delta from rightmost nonzero limb, with
+// borrow. If this would underflow, or would leave leftmost
+// limb equal to 0000000000, start again: decrement rightmost
+// nonzero limb by 1, with borrow, then add two limbs
+// vvvvvvvvvv, and redo.
use std::cmp::{Ordering, max};
use std::convert::{TryFrom, TryInto};