Number

Home of the ABS programming language: the joy of shell scripting.


Number

Numbers are very straightforward data structures:

123
1.23

Most mathematical operators are designed to work with them

(2 ** 5.5 / 1 / 3 + 19) % 5 # 4.08494466531301

Note that numbers have what we call a “zero value”: a value that evaluates to false when casted to boolean:

!!0 # false

You can use bitwise operators on numbers, but bear in mind that they will be implicitely converted to integers:

1 ^ 1 # 0
1 ^ 0 # 1
1 ^ 0.9 # 1, as 0.9 is converted to 0

Supported functions

number()

Identity:

99.5.number() # 99.5

int()

Rounds down the number to the closest integer:

10.3.int() # 10

round(precision?)

Rounds the number with the given precision. The precision argument is optional, and set to 0 by default:

10.3.round() # 10
10.6.round() # 11
10.333.round(1) # 10.3

ceil()

Rounds the number up to the closest integer:

10.3.ceil() # 11

floor()

Rounds the number down to the closest integer:

10.9.floor() # 10

str()

Returns a string containing the number:

99.str() # "99"

Next

That’s about it for this section!

You can now head over to read about arrays.