Skip to content
ExamplesOpen editor ↗

log

→ log()

Returns the natural logarithm of a number — the base is **e**, not 10.

log(palo)

log asks one question: what power must e be raised to in order to give this number? So log(exp(3)) is 3, and log(1) is 0.

Careful: the base is e, not 10. If you learned “log” in class, you were most likely working in base 10. The log here is not that one. When you want base 10, write log(n) / log(10).

log needs a number above 0. log(0) returns -Infinity, and log(-1) returns NaN.

Note also that log is not kwala. kwala is what sends words to the message area; log is a mathematics function that returns a number.

The name is left as it stands. “Logarithm” does not appear in the JCE or BGCSE mathematics syllabuses, and no Setswana word for it is in classroom use.

NameTypeDescription
palopaloA number above 0.
A scale that squeezes the big numbers in
tiro setaLoeto() {
  thalaKanefase(400, 400);
  bokamorago(22, 26, 36);
  tlogelaMothalo();

  metlha dipalo = [1, 5, 20, 90, 400, 1800, 9000];

  gopheta (diri i = 0; i < 7; i = i + 1) {
    metlha p = dipalo[i];

    // Ka tolamo, palo ya bofelo e ne e tla tswela kwa ntle ga kanefase.
    // log e e busetsa mo teng — 9000 e nna mothalo o motelele fela.
    metlha bogodimo = lekanyetsa(log(p), 0, log(9000), 12, 300);

    tlatsaMmala(80 + i * 22, 170, 230 - i * 20);
    thalaKhutlonne(28 + i * 52, 350 - bogodimo, 34, bogodimo);

    kwala(p);
  }
}
log is exp turned around
tiro setaLoeto() {
  thalaKanefase(400, 400);
  bokamorago(242);

  // Tiro nngwe e menola e nngwe
  kwala(log(exp(3)));
  kwala(exp(log(3)));

  boketeMothalo(2);

  // Mothalo wa log — o gola ka bonya fa o ya kwa ntle
  mothaloMmala(60, 130, 210);
  gopheta (diri x = 1; x < 380; x = x + 3) {
    thalaNtlha(x + 10, 340 - log(x) * 50);
  }

  // Mothalo wa exp — o tlolela kwa godimo
  mothaloMmala(230, 140, 80);
  gopheta (diri x = 0; x < 200; x = x + 2) {
    thalaNtlha(x + 10, 340 - exp(x * 0.03) * 8);
  }
}

exp, pow, sqrt, kwala