Numbers
In Scriptol, the type number represents any kind of number.
But it is possible to define more precisely the type for a number. The ttable below give the list of numerical types.
number
integer int natural real boolean |
any kind of number (until double of
C++). a number without decimal. 32 bits. as integer. a unsigned 64 bits integer. a 64 bits number with decimals. a two values (true and false) number. |
The double type of C++ or Java is equivalent to real in Scriptol.
The natural type in Scriptol has various named in other languages and
operating systems.
Methods
Literal numbers have methods, the table below give the list.
number | toNatural() toText() toInt() toReal() |
converts to natural. converts to text. round down into integer. converts to real. |
integer int |
toNatural() toReal() toText() |
converts into 64 bits unsigned integer. converts to real. converts to text. |
natural | toText() toInt() toReal() |
converts to text. round down into integer. converts to real. |
real | toNatural() toText() toInt() |
converts to natural. converts to text. round down into integer. |
boolean
|
Constructors
As any object in Scriptol, numbers have constructors: int( ...), real( ...)
, etc...
Using the constructor is useless when the number is declared, as a value may
be assigned directly to the object, the constructor allow to convert from
a type to another one, at declaration or in an expression..
Example:
int x = int(y)
converts the real y argument réel to integer.
Literals
In an expression, the set of a literal number is recognized by its format.
Integers have two formats: décimal and hexadécimal.
Reals are recognized by a dot followed by decimals or by zero.
Natural are recognized by the n letter.
A number may be assigned any format.
Keyword | Mathrmatical set | Formats |
number integer / int natural real boolean |
all numbers integers naturals reals booleans |
all formats 123 123n 123.0 ou 0.123 ou 1.2e10 true / false |
Other formats:
- 0xf8 hexadecimal (number, int, natural)
- 012 octal (number, int, natural)
Examples: | int
i = 0.5.toInt() natural n = 12.toNatural() real r = 0.5 + 3.toReal() print i + 0xff print n print r |
Displays: | >
255 > 12 > 3.5 |
Exercises |
1) These variables are declared: |