PERCENTAGES
Prices go up by 20%, a sale takes 25% off, a battery is at 50%. satellite.variable.percentage holds a percentage as its own kind of value, and it knows what those everyday sums mean. satellite.variable.percent is its second spelling, so both words declare the same type.
Writing a percentage
You write a percentage with its % touching the digits: 50%, 12.5%, -50%. The % is required. A percentage name given a plain 50 is refused before the program starts, with “ERROR: expected 50%”.
What each sum means
A percentage on its own, or with another percentage, stays a percentage. A number and a percentage together answer a number:
50% + 25%is75%, and50% - 25%is25%50% * 50%is25%: a percentage of a percentage50% / 4is12.5%: a share of it200 * 50%is100, and so is50% * 200: that percentage of a number200 + 50%is300: the number grown by it200 - 50%is100: the number reduced by it200 / 50%is400: the number that 200 is 50% of
(satellite)
satellite.capsule satellite.main()
{
satellite.variable.percentage tax = 20%
satellite.variable.percent sale = 25%
satellite.variable.number price = 80
satellite.console.display(price + tax)
satellite.console.display(price - sale)
satellite.console.display(price * sale)
satellite.console.display(200 / 50%)
satellite.console.display(tax + sale)
satellite.console.display(sale / 2)
satellite.console.display(tax.string + " tax")
satellite.return(satellite)
}96
60
20
400
45%
12.5%
20% tax80 plus 20% tax is 96, and 80 with 25% off is 60. The 25% of 80 that came off is 20.
Exact to 32 places
A percentage keeps 32 digits after the point, exactly. It is not a binary float, so 0.1% + 0.2% is 0.3% with nothing left over. There is no ceiling above: 1000000000000% is a perfectly good percentage. A 33rd digit after the point is rounded half away from zero.
(satellite)
satellite.capsule satellite.main()
{
satellite.variable.percent battery = 50%
satellite.console.display(0.1% + 0.2%)
satellite.console.display(100% / 3)
satellite.console.display(battery < 75%)
battery = battery - 75%
satellite.console.display(battery)
satellite.return(satellite)
}0.3%
33.33333333333333333333333333333333%
true
-25%A percentage compares with ==, !=, <, >, <= and >=, but only with another percentage: 50% == 50 is refused, because a percentage and a plain number are different things.
The number goes first
When you add a percentage to a number or take one away, the number goes first: you add 20% onto 80, so you write 80 + 20%. The other way round is refused, and the message tells you which way to write it:
(satellite)
satellite.capsule satellite.main()
{
satellite.console.display(50% + 5)
satellite.return(satellite)
}--------------------------------------------------------------------------------
SATELLITE CRITICAL ERROR REPORT
--------------------------------------------------------------------------------
S301: TYPES_DO_NOT_MEET
satl(run): 50% + 5: a percentage is taken off or added onto a number, so the
number goes first -- 5 + 50%
directory: backwards.satl:5
syntax: satellite.console.display(50% + 5)
/\
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.
--------------------------------------------------------------------------------What else is refused today
%and^with a percentage, and one percentage divided by another (50% / 50%).- An answer that is not a whole number:
3 * 50%is 1.5, and a percentage answering a float is not built yet, so it is refused withS402. - A percentage meeting a float, such as
10.0 * 50%, is not built yet. - A percentage name holds only a percentage, so
battery = battery * 2is refused when it runs, because that sum answers a number. .stringis the only conversion:.number,.binary,.hexand.reverse()are refused.
Where next
The FULL REFERENCE lists every percentage word. Whole numbers are in NUMBERS, and exact parts of a whole are in FRACTIONS.
