NUMBERS

satellite.variable.number holds a whole number: 7, -12, 0, or one with a hundred digits. It is the type you will use most, for counting, for totals, and for anything that comes in whole pieces.

Making a number and doing sums

You write a number as its digits, with a minus touching the front when it is below zero: 34587, -7. The operators are the ones from school, plus two more:

  • + adds, - takes away, * multiplies
  • / divides and keeps the whole part, % gives the remainder
  • ^ raises to a power, and ** is its second spelling

Every operator is written with a space on both sides. 4 + 3 works, and 4+3 is refused.

fruit.satlSATELLITE 004 Download
The operators on two numbers
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.variable.number apples = 12
    satellite.variable.number pears = 5
    satellite.console.display(apples + pears)
    satellite.console.display(apples - pears)
    satellite.console.display(apples * pears)
    satellite.console.display(apples / pears)
    satellite.console.display(apples % pears)
    satellite.console.display(apples ^ 2)
    satellite.console.display(2 + 3 * 4)
    satellite.console.display((2 + 3) * 4)
    satellite.return(satellite)
}
OUTPUT
17
7
60
2
2
144
14
20

*, / and % are worked out before + and -, as in ordinary arithmetic, and brackets change the order. ^ is worked out right to left, so 2 ^ 3 ^ 2 is 2 ^ 9, which is 512.

Division keeps the whole part

/ between two whole numbers answers a whole number: 12 / 5 is 2, and % tells you the 2 that was left over. When the numbers are below zero, / cuts toward zero and % takes the sign of the number being divided, so -7 / 2 is -3 and -7 % 2 is -1.

When you want the part after the point, write one of the numbers with a point: 12.0 / 5 is a float and answers 2.4. See FLOATS. Dividing by zero is refused with S401, because there is no number it could answer.

How big a number can be

There is no largest number. A satellite number is built from as many pieces as it needs, and it grows by itself when a result gets big. It never wraps around to a small or negative value the way numbers in many languages do.

big.satlSATELLITE 004 Download
Numbers grow as large as they need to
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.console.display(18446744073709551615 + 1)
    satellite.console.display(2 ^ 100)
    satellite.variable.number product = 1
    satellite.statement.for (satellite.variable.number i = 1; i <= 25; i + 1)
    {
        product = product * i
    }
    satellite.console.display(product)
    satellite.console.display(-7 / 2)
    satellite.console.display(-7 % 2)
    satellite.return(satellite)
}
OUTPUT
18446744073709551616
1267650600228229401496703205376
15511210043330985984000000
-3
-1

The first line is the largest number a common 64-bit integer can hold, plus one. In satellite it is just the next number. Small numbers stay fast: a number only spreads into more pieces when it has to. The only limit is your computer’s memory.

Comparing numbers

== (equal), != (not equal), <, >, <= and >= compare two numbers and answer true or false, which is what an if or a while needs. See IF, WHILE AND FOR.

Turning a number into something else

satellite never converts a number behind your back. "total: " + 5 is refused, because a string and a number do not add up. Instead you say what you want, with a method written after a dot:

  • .string is the number as text (also spelled .to_string and .str)
  • .binary is its digits in base 2 (also .bin), and .hex its digits in base 16
  • .reverse() turns its digits round and keeps the sign
  • .add(x) is the same as + x
convert.satlSATELLITE 004 Download
Saying the conversion out loud
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.variable.number score = 87
    satellite.console.display("score: " + score.string)
    satellite.console.display("score: " + score.to_string())
    satellite.console.display(score.binary)
    satellite.console.display(score.hex)
    satellite.console.display(1234.reverse())
    satellite.console.display(score.add(13))
    satellite.console.display(score > 50)
    satellite.return(satellite)
}
OUTPUT
score: 87
score: 87
1010111
57
4321
100
true

A method may be written with or without its empty brackets: score.string and score.to_string() are the same.

What a number refuses

A number name holds only whole numbers. Give one 12.5 and it is refused, “it holds a float”, because that value belongs in a satellite.variable.float. And one shortcut from other languages is not in satellite yet:

plus_equals.satlSATELLITE 004 Download
n += 1 is not built: write n = n + 1
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.variable.number n = 1
    n += 1
    satellite.console.display(n)
    satellite.return(satellite)
}
OUTPUT
--------------------------------------------------------------------------------
SATELLITE CRITICAL ERROR REPORT
--------------------------------------------------------------------------------
S210: NOT_BUILT_YET
satl(check): in satellite.main, n += ... is not built yet -- write n = n + ...

directory: plus_equals.satl:6
syntax: n += 1
        /\

this word is numbered in the language and the library behind it does not exist
yet. The word is right; there is nothing yet to run.
machine code 14 not_built_yet -- satl exits with this.

--------------------------------------------------------------------------------

The report says what to write instead: n = n + 1. Methods such as .max, .min, .abs and .power are not built for numbers yet either, and satl refuses them by name when you try.

Where next

The FULL REFERENCE has every number word. Numbers with a point in them are in FLOATS, and numbers written in bits or in base 16 are in BINARY AND HEXADECIMAL.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *