RE: How to print out double precision number in the kernel using the printk

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you very much.

Now I roughly understand the  floating point inside the kernel :).

Haiguang

At 10:32 AM 10/31/01 -0800, you wrote:

From my experience you "can" use floating point in the kernel..
However, most don't recommend doing so as it and slow and so on
and so forth.  If printk won't support it using %f then I would
suggest reading into how floating point numbers are actually
stored, and doing the translation yourself, or translate it using
ints and such.  I would suggest just looking into the way that
double precision numbers are stored though as that would be better.

I have used floating point in the kernel and don't recommend it
unless you absolutley must.  Adding floating point will make your
changes gruesome and ugly to those without floating point, since
the floating point emulators only work with user-space apps.

If there is not floating point printing via printk you can try
something like this (if you don't want figure out how double
precisisons would work)

float float_foo, float_bar;
int int_foo,int_bar;

float_foo = 1.0005;
int_foo = TRUNC(float_foo);
float_bar = float_foo - int_foo;

int_bar = TRUNC(float_bar * 10000);

printk ("%d.%03d",int_foo, int_bar);

This should only require you to write TRUNC a function that
truncates floats if none exists.  I'm not sure if casting
will round the value up if say its 2.657 (which would print 3.657
if casting rounded up).  If casting does not round up then
you can simply do int_foo = (int) float_foo and is easy to
test and figure out.

> > > How to print out double precision number like 1.0005 in
> the kernel using
> > > the printk.
> > >
> > > I am sorry ask such a simple question?
> > >

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux