FRACTIONS
A third is not 0.333. It is one part in three, and no decimal ever quite reaches it. satellite.variable.fraction keeps a fraction the way you would write it on paper: one number above the line and one below it, tied together.
Writing a fraction
You write a fraction with a slash that touches both numbers: 1/3. That touching slash is the whole difference between a fraction and a division. 1 / 3, with a space on each side, is whole-number division and answers 0.
(satellite)
satellite.capsule satellite.main()
{
satellite.variable.fraction third = 1/3
satellite.variable.fraction half = 2/4
satellite.console.display(third)
satellite.console.display(half)
satellite.console.display(half == 1/2)
satellite.console.display(third < half)
satellite.console.display(3/4 > 2/3)
satellite.console.display(third.numerator)
satellite.console.display(third.denominator)
satellite.console.display(third.string + " of a pie")
satellite.return(satellite)
}1/3
2/4
true
true
true
1
3
1/3 of a pieTwo things to notice here:
- A fraction stays as you wrote it.
2/4shows as2/4. satellite does not reduce it to1/2behind your back. - Fractions compare by what they are worth.
2/4 == 1/2is true, and1/3 < 1/2is true, even though the numbers are written differently.
.numerator is the number above the line, .denominator the number below it, and .string is the fraction as text.
Signs, decimals and whole numbers
The minus sign goes on top: -1/3. Each part is held as a float, and is shown as the plain number it is. So 1/3 shows 1/3 and never 1.0/3.0, while a part with digits after its point shows them: 1.5/2. A whole number given to a fraction name becomes that number over 1.
(satellite)
satellite.capsule satellite.main()
{
satellite.console.display(-1/3)
satellite.console.display(1.5/2)
satellite.variable.fraction whole = 3
satellite.console.display(whole)
satellite.console.display(10/4 >= 5/2)
satellite.console.display(1 / 3)
satellite.return(satellite)
}-1/3
1.5/2
3/1
true
0The last line shows the spaced slash at work: 1 / 3 is division, and a whole-number division of 1 by 3 is 0.
A bottom number of 0 is refused (S401), because nothing can be split into zero parts.
The spaced slash, refused
If you give a fraction name a spaced slash, satl catches it before the program starts, and tells you how to write it:
(satellite)
satellite.capsule satellite.main()
{
satellite.variable.fraction third = 1 / 3
satellite.console.display(third)
satellite.return(satellite)
}--------------------------------------------------------------------------------
SATELLITE CRITICAL ERROR REPORT
--------------------------------------------------------------------------------
S301: TYPES_DO_NOT_MEET
satl(check): in satellite.main, 1 / 3 is whole-number division -- a fraction is
written with a touching slash: 1/3
directory: spaced.satl:5
syntax: satellite.variable.fraction third = 1 / 3
/\
this operator has no scenario for the two kinds it was given. Nothing was
guessed at, because a guess here is an answer that is wrong and does not say so.
machine code 27 types_do_not_meet -- satl exits with this.
--------------------------------------------------------------------------------Not built yet
Today a fraction is written, shown and compared. These are refused:
- arithmetic between fractions:
1/3 + 1/3is “fraction arithmetic is not built yet” - a fraction made of two names, such as
a/b - a fraction meeting a float, a percentage or another of the newer types, such as
1/3 == 0.5 .numberon a fraction
Where next
The FULL REFERENCE lists every fraction word. Decimals are in FLOATS, and parts of a hundred are in PERCENTAGES.
