Table of Contents

9.6 Exponential and logarithmic functions

In many mathematical tasks you need functions to calculate powers, roots or logarithms. Gambas provides you with various functions for this purpose.

9.6.1 Correlation of Potencies, Roots and Logarithms

Since dealing with potencies, roots and logarithms is not part of the daily exercises, three basic considerations are put before the description of the corresponding Gambas functions:

The mathematical operation' Logarithmic operation' hides nothing else than the 'exponent search' for a given number (potency value) and a given basis. If logarithm = log10 (1000) the exponent is searched for, for which 10exponent = 1000. The exponent you are looking for is 3, because 10³ = 1000, which had to be said before you logarithmically start like wild on it.. .

9.6.2 Potency functions

FunctionDescription
potency value = Exp(exponent AS Float) AS FloatCalculates the power value p to base e with the exponent' exponent' (p=eexponent). The exponent must be smaller than 709.779999 to avoid overflow errors. The number e is the Euler number.
potency value = Expm (exponent AS Float) AS FloatCalculates the power value p to base e with the exponent' exponent' for very small exponents. The following applies: Expm(x) = Exp(x) - 1.
potency value = Exp2 (exponent AS Float) AS FloatCalculates the power value p for base 2 with the exponent' exponent' (p = 2exponent).
potency value = Exp10 (exponent AS Float) AS FloatCalculates the power value p to base 10 with the exponent' exponent' (p = 10exponent).

Table 9.6.2.1: Operation: Potentiating

9.6.3 Root functions

FunctionDescription
2root = Sqr(number AS Float) AS FloatCalculates the 2nd root of a number. The real number' number' must not be negative (number? 0).
3root = Cbr(number AS Float) AS FloatCalculates the cubic root of a number. The real number' number' can be 0 (zero), negative or positive.

Table 9.6.2.1: Operation: root extraction

9.6.4 Logarithmic functions

FunctionDescription
exponent = Log (numerus AS Float) As FloatCalculates the natural logarithm of a number (numerus) to the base e (Euler's number) with logarithm = ln(numerus). The symbol' ln' stands for logaritmus naturalis. The number (numerus) must be greater than zero. We are looking for the exponent for which eexponent = numerus applies.
exponent = Logp (numerus AS Float) AS FloatCalculates the logarithm to base e for very small numeric values. The following applies: Logp(x) = Log(1 + x).
exponent = Log2 (numerus AS Float) AS FloatCalculates the logarithm of a number (numerus) to base 2. the number must be greater than zero. We are looking for the exponent for which 2exponent = numerus applies.
exponent = Log10 (number AS Float) AS FloatCalculates the logarithm of a number (numerus) to the base 10.10. The number must be greater than zero. We are looking for the exponent for which 10exponent = numerus applies.

Table 9.6.4.1: Operation: Logarithmic logging

Hints:

9.3.5 Example 1

The calculation of the 5th root from the real number 83, for example, requires the use of some of the above-mentioned functions, which is also reflected in the source code extract:

w = (83)^0.2
ln(w) = 0.5 * ln(83) = 0,88376812155932
w = e^ln(w) = e^0,88376812155932 = 2,42000140696596

The sample is executed in a similar way:

p = (2,42000140696596)^5
ln(p) = 5 * ln(2,42000140696596) = 4,4188406077966
p = e^(5 * ln(2,42000140696596))
Public Sub btn5Root83_Click()
  Dim w As Float
 
  Print "ln(w) = "; 0.2 * Log(83)
  w = Exp(0.2 * Log(83))
  Print "w = "; Exp(0.2 * Log(83))
  Print "Rehearsal 1 (trivial) = "; w * w * w * w * w
  Print "ln(p) = "; 5 * Log(Exp(0.2 * Log(83)))
  Print "Potency value = "; Exp(5 * Log(Exp(0.2 * Log(83))))
End

Output in the console of the IDE:

ln(w) = 0,88376812155932
w = 2,42000140696596
Rehearsal 1 (trivial) = 83,0000000000001
ln(p) = 4,4188406077966
Potency value = 83

9.6.6 Example 2

The calculation of the potency value a^b for a > 0 and any b (a, b ∈ ℝ) works with the following approach: a^b = Exp (b*Log (a)) and delivers 100 in the next calculation:

a = Cbr(100) ' 3. root of 100
b = 3
Print Exp(b * Log(a))

For a = Cbr(100) and b = 6, the approximate value is 9999.999999999999999 ≈ 10000.