maTH
  • šŸ‘‹Welcome!
  • šŸ—æInstallation
  • Reference
    • 😱Mathematical operations
      • add
      • pascal
      • factorial
      • factorialL
      • GCD
      • LCM
      • pow
      • permutations
      • combinations
      • combinationsWithRep
      • subtract
      • multiply
      • divide
      • sin
      • cos
      • ln
      • log
      • radToDeg
      • degToRad
      • mod
      • abs
      • floor
      • ceil
      • root
      • exp
      • tan
      • arcsin
      • arccos
      • arctan
      • sinh
      • cosh
      • round
    • 🄶Statistics
      • Binomial
      • Poisson
      • Geometric
      • Pascal
      • Hypergeometric
      • Exponential
      • Uniform
    • 🄵Data structures
      • Stack
      • Queue
      • LinkedList
    • šŸ¤“Algorithms
      • Bubble sort
      • Insertion sort
      • Selection sort
      • Merge sort
      • Quicksort
      • Heap sort
      • Count sort
      • Bucket sort
      • Radix sort
    • 😳Constants
Powered by GitBook
On this page
  1. Reference
  2. Mathematical operations

log

Find the logarithm of argument x with the base of a

log<return_type>(a, x);

will return the logarithm of the argument x with the base a, both given as arguments. The return_type specifies in which data type the result will be returned in, like shown in below example:

log<int>(20, 400); //2
log<float>(1.43, 543.18); //17.6066

Just like ln(x), log(a, x) isn't defined for all non-positive arguments x, as the compiler will throw an exception:

Error: Logarithm is undefined for non-positive values.

Because the ln(x) function is so precise, we can just use the:

loga(x)=ln(x)ln(a)log_a(x) = \frac{ln(x)}{ln(a)}loga​(x)=ln(a)ln(x)​

formula to calculate the given logarithm.

PreviouslnNextradToDeg

Last updated 11 months ago

😱