Skip to content

Numbers

Uri edited this page Jun 24, 2021 · 1 revision

All this samples can be tested online using publicly accessed ol terminal session at the project page: http://yuriy-chumak.github.io/ol/

Integers and Floating-Point Numbers

The type of the value can be obtained using core function type.

> (print (type 123456789123456789))
40

Integer types:

Type Type value Value range
type-enum+ 0 0 .. 2^24 for 32-bit systems, 2^56 for 64-bit
type-enum- 32 -2^24 for 32-bit systems, -2^56 for 64-bit .. -0
type-int+ 40 2^24+1 for 32-bit systems, 2^56+1 for 64-bit .. Unlimited (actually, by accessible OS memory)
type-int- 41 -Unlimited (actually, by accessible OS memory) .. -2^24-1 for 32-bit systems, -2^56-1 for 64-bit

The current maximal value of type-enum+ can be obtained using function (vm:maxvalue).

Floating-point types:

Type Type value Value range
type-inexact Depends on compiler options: it can be half, float or double FPU register values

The size of inexact numbers can be obtained using core function size:

> (print (size (inexact 1.0)))
8

Integers

Literal integers are represented in the standard manner:

> 1
1

> 1234
1234

> 1234567890987654321
1234567890987654321

> 123.0
123

> 22/11
2

> 7+0i
7

The type for an integer literal depends on integer value: the "small" values represents as type-enum+ and type-enum-, the larger values represents as type-int+ and type-int-.

> (type 1234)
0

> (type 1234567890987654321)
40

Binary, octa- and hexadecimals supported too:

> #b10111111
191

> #b10110000/#b10000
11

> #b-10110000
-176

> #o707123
233043

> #x198273761098abcccce88272637777ffffccccbbaa92828aab
160126193094665126051886511292983700006306338004851755223723

> (type #x123445)
0

Overflow behavior

No numeric overflows in Ol. In case of exceding the maximal value of type-enum it just changes type to type-int.

> (vm:maxvalue)
72057594037927935

> (type (vm:maxvalue))
0

> (+ (vm:maxvalue) 1)
72057594037927936

> (type (+ (vm:maxvalue) 1))
40

In case of division by 0 the infinite (represent as +inf.0) and -infinite (represent as -inf.0) will obtain.

> 11/0
+inf.0

>-1919/0
-inf.0

Division errors

No division errors in Ol. Just not-a-number (represent as +nan.0) value returned.

> 0/0
+nan.0

Floating-Point Numbers

... TBD ...

Clone this wiki locally