 Package

org.taffy.core.maths
 Object Hierarchy
 What is it?

A Number is a number, plain and simple. Unlike many other languages, there is no differentiation between "floatingpoint" and "integer" numbers. The Number class is atomic.
 Quick Example
a = 1234
Table of Contents:
Constructing a Number
A Number is simple to create. It is written:
a = 1
b = 2.3
c = 4.4444
Arithmetic
Number supports many mathematical operators. Some operators, such as bitor () and bitand (&), require both the left and right values to be whole, or have no fractional components.

+ (add)

++ (addonetoself)

+= (addequals)

 (subtract)

— (subtractselfbyone)

= (subtractequals)

/ (divide)

/= (divideequals)

* (multiply)

*= (multiplyequals)

^ (raise)

^= (raiseequals)

% (modulus)

! (factorial)

< (lessthan)

⇐ (lessthanorequal)

> (greaterthan)

>= (greaterthanorequal)

~= (deltaequals)

<< (leftshift)

<⇐ (leftshiftself)

>> (rightshift)

>>= (rightshiftself)

 (bitor)

= (bitorself)

& (bitand)

&= (bitandself)

^^ (bitxor)

^^= (bitxorself)

~ (bitnot)

 (negate)

+ (do nothing)
Digit Limits
A digit limit denotes the number of digits allocated to each Number. The default digit limit is 16. For arithmetic that produces a number with X digits, you need an X digit limit to store the result — if the digit limit is less than X, the result will be approximated. The amount of memory required for a Number is heavily dependent on the digit limit.
Note that the digit limit only affects results of arithmetic. You can always create a number with an arbitrary number of digits. But once that number is used in arithmetic, there must be a sufficient digit limit to store the result.
Use the Number#pushDigitLimit: and Number#popDigitLimit to push and pop digit limits, respectively. The method Number#withDigitLimit:do: runs a block with a digit limit localized to just the block.
Number pushDigitLimit: 1024 // do big number operations Number popDigitLimit
The following example shows the effects of a toosmall digit limit, and a sufficient digit limit:
// set the digit limit to 2 Number withDigitLimit: 2 do: { // 'a' is not approximated even though it has 3 digits a = 1.11 ==> 1.11 // the arithmetic result is approximated because the digit limit is 2 a * 2 ==> 2.2 } // set the digit limit to 3, and the result will be exact Number withDigitLimit: 3 do: { a = 1.11 ==> 1.11 a * 2 ==> 2.22 }