Cheddar icon indicating copy to clipboard operation
Cheddar copied to clipboard

Proposal: Arbitrary Precision Numbers

Open vihanb opened this issue 7 years ago • 3 comments

This proposal details the workings of the planned upgrade to arbitrary precision numbers. Details are yet to be worked out

Overview

At the moment Cheddar has limited 64-bit numbers. These can loose precision with large numbers and also have floating point errors. This is not at all wanted in Cheddar and therefore, after a certain limit has been reached, should be implicitly upgraded to "bigints".

Definition

Using Number.MAX_SAFE_INT to detail the largest integer than can be reached. Use an alternative CheddarNumber#big_value to store an array detailing the number. The array should be a Uint32Array typed arrays allocated to the size of the number, where each item is exactly 32-bits. With each item representing a 32-bit uint (4294967295). CheddarNumber#bigsize stores the number of allocated sections in the array which will be referenced by each operation to determine whether or not the number has been promoted. During any operation if the Number.MAX_SAFE_INT has been exceeded, the promotion will occur if and only if, the number stores a CheddarClass#Reference to a variable or, the number has lost precision. This is too avoid needlessly promoting where the final value is near Number.MAX_SAFE_INT but still has precision.

Changelist

The following needs to be changed:

  • CheddarNumber#value getters and setters
  • CheddarNumber.Operator promotion

and probably some more stuff...

vihanb avatar Aug 06 '16 19:08 vihanb