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% is 75%, and 50% - 25% is 25%
  • 50% * 50% is 25%: a percentage of a percentage
  • 50% / 4 is 12.5%: a share of it
  • 200 * 50% is 100, and so is 50% * 200: that percentage of a number
  • 200 + 50% is 300: the number grown by it
  • 200 - 50% is 100: the number reduced by it
  • 200 / 50% is 400: the number that 200 is 50% of
shop.satlSATELLITE 004 Download
Percentages at the shop
satellite.include(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)
}
OUTPUT
96
60
20
400
45%
12.5%
20% tax

80 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.

exact.satlSATELLITE 004 Download
Percentages are exact, and compare with each other
satellite.include(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)
}
OUTPUT
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:

backwards.satlSATELLITE 004 Download
For + and -, the number goes first
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.console.display(50% + 5)
    satellite.return(satellite)
}
OUTPUT
--------------------------------------------------------------------------------
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 with S402.
  • A percentage meeting a float, such as 10.0 * 50%, is not built yet.
  • A percentage name holds only a percentage, so battery = battery * 2 is refused when it runs, because that sum answers a number.
  • .string is the only conversion: .number, .binary, .hex and .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.

You may also like...

Leave a Reply

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