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

ln

PreviouscosNextlog

Last updated 11 months ago

Find the natural logarithm of x

ln<return_type>(x);

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

ln<int>(123); //2
ln<float>(371283123789); //26.6402
ln<bool>(7); //1

Natural logarithm f(x) = ln(x) isn't defined for non-positive numbers, so the compiler will throw an exception:

Error: The natural logarithm is undefined for non-positive values.

The function works so that it can also handle big integers/numbers aswell. How it works, as we first take the scientific notation of the number, calculate the value using the very fast converging expansion and then multiplying the value by n - 1 times of log10. You can find an in depth explanation of this approach here: .

😱
https://math.stackexchange.com/questions/977586/is-there-an-approximation-to-the-natural-log-function-at-large-values