Natural numbers, bounded
List of Import References :
See BOOL
See DENOTATION
SIGNATURE Nat
$Date: 2011-09-28 10:10:50 +0200 (Mi, 28. Sep 2011) $ ($Revision: 713 $)
IMPORT BOOL ONLY bool DENOTATION ONLY denotation -- $The free type$ TYPE nat == 0 succ(pred:nat)
It is not possible in OPAL to write down all numbers directly. The numbers used most often are introduced by the follwoing declarations:
FUN 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32: nat
FUN 1 2 4 8 16 32 64 128 256 512 1024: nat
FUN 1 10 100 1000 10000 100000 1000000: nat
The smallest and biggest nat number
The maximum depends on the size of an unsigned long
on the target
platform. If an unsigned long
has n
bits, the largest nat is of
size 2^(n-1)-1
. On a 32 bit architecture, n
is typically 32 and 64 on 64 bit architectures.
FUN min max: nat
Other numbers are represented as denotations and a conversion function
!
:
"1995"!, "4711"!, ... This function aborts if the denotation contains
characters which are not digits (not even spaces are allowed!).
FUN ! : denotation -> nat
The fundamental operations.
FUN + - * : nat ** nat -> nat
Division (5/3 = 5 div 3
==> 1
)
FUN / : nat ** nat -> nat FUN div: nat ** nat -> nat
Remainder of division: 5 % 3 = 5 mod 3
==> 2
FUN % : nat ** nat -> nat FUN mod : nat ** nat -> nat
Power
FUN ^ pow: nat ** nat -> nat
Faster operations for double and half
FUN double : nat -> nat FUN half: nat -> nat
Minimum and maximum
FUN min max : nat ** nat -> nat
Evenness and oddness
FUN even? odd? : nat -> bool
Equality, inequality
FUN = |= : nat ** nat -> bool
Comparisons
FUN <= >= < > : nat ** nat->bool
multiplying operators have higher priority than adding operators
/$ BRACKET RIGHT [+,-] [*,/,%,div,mod] $/ /$ BRACKET LEFT [*,/,%,div,mod] [+,-] $/
arithmetic operators associtate to the left (but not ^
!)
/$ BRACKET LEFT [+,-] [+,-] $/ /$ BRACKET LEFT [*,/,%,div,mod] [*,/,%,div,mod] $/
power has highest priority
/$ BRACKET RIGHT [+,-,*,/,%,div,mod] [^] $/ /$ BRACKET LEFT [^] [+,-,*,/,%,div,mod] $/
next node: Real,
prev node: Int,
up to node: Subsystem Numbers