Skip to main content

Number Class

Number is Alia's built-in number class, used to represent and process numeric data.

Creating Numbers​

Literals​

const num1 = 42
const num2 = 3.14
const num3 = -10

Constructor Form​

const num4 = new Number [42]
const num5 = Number[42]

Instance Methods​

toString​

Returns the string corresponding to the number, with signature alias -> String.

const num = 42
print call num.toString ~ outputs '42'

valueOf​

Returns the primitive value of the number, with signature alias -> Number.

const num = 42
print call num.valueOf ~ outputs 42

toBoolean​

Returns the boolean value corresponding to the number, with signature alias -> Boolean. Non-zero values correspond to true, and zero corresponds to false.

const num = 42
print call num.toBoolean ~ outputs true
const zero = 0
print call zero.toBoolean ~ outputs false

toArray​

Returns a single-element array containing the number, with signature alias -> Array.

const num = 42
print call num.toArray ~ outputs Array [Number 42]

toCode​

Returns the code-form string of the number, with signature alias -> String.

const num = 42
print call num.toCode ~ outputs '42'

toDescription​

Returns the description string of the number, with signature alias -> String.

const num = 42
print call num.toDescription ~ outputs 'Number 42'

Number Operations​

Arithmetic Operations​

const a = 10
const b = 5

print a + b ~ addition, outputs 15
print a - b ~ subtraction, outputs 5
print a * b ~ multiplication, outputs 50
print a / b ~ division, outputs 2

Comparison Operations​

const a = 10
const b = 5

print a > b ~ outputs true
print a < b ~ outputs false
print a >= b ~ outputs true
print a <= b ~ outputs false
print a == b ~ outputs false
print a != b ~ outputs true

Assignment Operations​

let x = 10
x += 5 ~ x = x + 5
print x ~ outputs 15

x ++ ~ x = x + 1
print x ~ outputs 16

Example Code​

const integer = 42
const float = 3.14
const negative = -10

print 'Integer: ' .. (call integer.toString)
print 'Float: ' .. (call float.toString)
print 'Negative: ' .. (call negative.toString)

const a = 10
const b = 5
print 'Addition: ' .. (a + b)
print 'Subtraction: ' .. (a - b)
print 'Multiplication: ' .. (a * b)
print 'Division: ' .. (a / b)

if a > b {
print 'a is greater than b'
}

let counter = 0
counter += 1
print 'Counter: ' .. counter

const strNum = '123'
const converted = strNum as Number
print 'After conversion: ' .. converted
print 'Constructor conversion: ' .. Number[strNum]

const radius = 5
const area = 3.14159 * radius * radius
print 'Circle area: ' .. area

Next Steps​