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.
- 08-09-2005 #1Just 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!
- 08-09-2005 #2
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).
- 08-09-2005 #3Just Joined!
- Join Date
- Nov 2004
- Posts
- 43
Thanks a lot for your reply!
Originally Posted by lakerdonald
- 08-10-2005 #4Linux 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.
- 08-10-2005 #5
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.


Reply With Quote
