-3

I can't search what does the logarithm code look like in C++? What the code of the logarithm function looks like in C++ in the library cmath? Exactly the code. I don't need to figure out how I can get the logarithm. I want to know how this algorithm works.

Tarik
  • 10,810
  • 2
  • 26
  • 40
OHtuzh
  • 21
  • 3
  • 5
    I googled "cmath source code" and found [cmath source code \[include/c++/7.2.1/cmath\] - Woboq Code Browser](https://code.woboq.org/gcc/include/c%2B%2B/7.2.1/cmath.html). `__builtin_log*` functions are used in this implementation. – MikeCAT Jan 08 '21 at 13:45
  • In which standard library implementation? (libstdc++, libc++, etc) – Aykhan Hagverdili Jan 08 '21 at 13:58
  • Or, more loosely, what compiler? GCC, Clang, or MSVC? – HolyBlackCat Jan 08 '21 at 14:08
  • See also, for example, https://stackoverflow.com/questions/52736011/instruction-fyl2xp1 – zkoza Jan 08 '21 at 15:19
  • See also https://math.stackexchange.com/questions/61209/what-algorithm-is-used-by-computers-to-calculate-logarithms – beaker Jan 08 '21 at 15:45

2 Answers2

2

That is implementation specific and therefore can vary from system to system.

Since there are several ways to compute a logarithm, a good book on this kind of algorithm is a good start.

U. W.
  • 414
  • 2
  • 10
2

You would be very disappointed. On modern processors, the C++ compiler inserts the assembly instruction that obtains it from the floating-point ALU. There is no code.