logo elektroda
logo elektroda
X
logo elektroda

Calculate Natural Logarithm in C++: Using math.h Library and Function Names

MARIO159 27250 8
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 1944165
    MARIO159
    Level 12  
    Questions as in the topic how can I calculate the natural lagarithm from some number. I didn't notice the function in math.h. and what is the name of the function :)
  • ADVERTISEMENT
  • #2 1944301
    Sam Sung
    Level 33  
    There is a function in
    called log :)
    Quote:
    EXP(3) Linux Developer's Manual EXP(3)
    (...)
    SYNTAX
    #include
    (...)
    double log(double x);
    (...)
    DESCRIPTION
    (...)
    The log() function returns the natural logarithm of x.
  • ADVERTISEMENT
  • #3 1944306
    tsoltys
    Level 15  
    MARIO159 wrote:
    Questions as in the topic how can I calculate the natural lagarithm of some number. I didn't notice the function in math.h. and what is the name of the function :)


    It is - you just need to look at the math.h documentation.

    Quote:
    NAME
    log - natural logarithm function
    SYNOPSIS
    #include
    double log(double x);
    DESCRIPTION
    The log() function computes the natural logarithm of x, loge(x). The value of x must be positive.
  • #4 4871030
    johnyu
    Level 1  
    And is there a logarithm function with two parameters in cmath or math.h (I don't know if they are different)? (logarithm number and base)
  • ADVERTISEMENT
  • #5 4871076
    krzychoocpp
    VIP Meritorious for electroda.pl
    As far as I know, there isn't. Because there is no need.

    $$\frac{\log_c b}{\log_c a} = \log_a b$$
  • ADVERTISEMENT
  • #6 5808376
    marekkiek
    Level 14  
    I have this problem in one expression I need to calculate log base 2, but I can't use the logarithm function, I have to write it myself. Is it possible to see the code of a library function and to write something based on its syntax?

    Regards
  • #8 5809845
    Sam Sung
    Level 33  
    Maybe it's something like this - it's not a single expression, but a statement:
    for (wynik = 0; x > 1; wynik++, x >>= 1)
      ;
    (ix result of type unsigned int.)
    In a single expression of the C language in the literal sense, it probably can't be done.
    Suspecting a library function is unlikely to help, because it meets other requirements.

Topic summary

The discussion centers around calculating the natural logarithm in C++ using the math.h library. The primary function for this purpose is identified as "log". Users inquire about the existence of a logarithm function with two parameters for different bases, but it is clarified that such a function is not necessary. One user expresses a need to implement a logarithm base 2 function manually and seeks guidance on writing the code. Suggestions include consulting external resources like Wikipedia for logarithm series and a specific site for integer logarithm calculations. The conversation emphasizes the importance of understanding the types of numbers involved and the potential complexity of library function implementations.
Summary generated by the language model.
ADVERTISEMENT