Find the answer to your Linux question:
Results 1 to 5 of 5
I am writing a modul which need be integrated to the kernel. In the module, I need the value of log (x). Usually in the applications, I just need include ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2004
    Posts
    43

    How to use Logarithmic (log) function in the kernel code?


    I am writing a modul which need be integrated to the kernel.

    In the module, I need the value of log (x). Usually in the applications,
    I just need include math.h header file. However, I don't know how to
    do it in the kernel. It said:

    unresolved symbol log


    How to use log function under the kernel?

    Thanks a lot!

  2. #2
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    The Kernel does not provide support for floating point operations, and log tends to be a floating point operation. (Very rarely is the result of a logarithm an integer). For this reason, the only way that you'd be able to implement a logarithm that I know of would be to write your own version, bearing in mind that you'd only be dealing with a granularity of one (that is, it could only work on integers, and fp is not/never has been/never will be supported by the Linux Kernel).

  3. #3
    Just Joined!
    Join Date
    Nov 2004
    Posts
    43
    Quote Originally Posted by lakerdonald
    The Kernel does not provide support for floating point operations, and log tends to be a floating point operation. (Very rarely is the result of a logarithm an integer). For this reason, the only way that you'd be able to implement a logarithm that I know of would be to write your own version, bearing in mind that you'd only be dealing with a granularity of one (that is, it could only work on integers, and fp is not/never has been/never will be supported by the Linux Kernel).
    Thanks a lot for your reply!

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Indeed, it is as lakerdonald says that kernel mode code cannot use floating point code (since the kernel doesn't save the FPU state, that would disrupt user-space). However, it's more than well possible to implement a logarithmic algorithm with finer granularity than integral numbers without resorting to floating point support by using fixed point fractional numbers.

  6. #5
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    True. I suppose you could also implement a convoluted floating point type, and then write a bunch of drop-in replacement functions that calculate integers and then shift accordingly. It would be woefully inefficient, so I'd recommend Dolda's method.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •