From 7554d02757c58450f74e30c6c8964cb1b6636a60 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 10 Oct 2020 23:33:00 +0100 Subject: [PATCH] move big comment into zcoord.rs Signed-off-by: Ian Jackson --- templates/bigfloat.ts | 62 ------------------------------------------- zcoord/zcoord.rs | 61 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 63 deletions(-) diff --git a/templates/bigfloat.ts b/templates/bigfloat.ts index 5acef33c..66e733a1 100644 --- a/templates/bigfloat.ts +++ b/templates/bigfloat.ts @@ -4,68 +4,6 @@ // 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 { diff --git a/zcoord/zcoord.rs b/zcoord/zcoord.rs index 1e114160..bf3a9bfb 100644 --- a/zcoord/zcoord.rs +++ b/zcoord/zcoord.rs @@ -2,7 +2,66 @@ // 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}; -- 2.30.2