Here's the corrected version of my function.. in case you wanted it...
(the other version breaks on numbers with a leading '0' in the part after
the decimal point).
void
print_a_double (double d)
{
int left = d, right = (d - left) * 1000;
/* uncommend the below 'rtl_' if in rtlinux task */
/*rtl_*/printf ("%d.%03d", left, right);
}
On Sat, 8 Dec 2001, Calin A. Culianu wrote:
> On Fri, 7 Dec 2001, Young Joon Lee wrote:
>
> > Hi,
> >
> > I tried to print 3.14159 in rtl_printf.
> > But %f, %lf, %e are not working in rtl_printf().
> > Does anybody know how to do this?
>
>
> :). You can't. For some reason the philosophy of the kernel was that you
> can't/shouldn't do anything with floats in the kernel (I think maybe it
> has to do with keeping context switches more efficient?). As such, the
> %g/%f conversion specifiers are unimplemented in printk and rtl_printf.
>
>
> However, there is hope: I believe I remember seeing a bunch of patches
> floating (no pun intended) around that can modify rtl_printf to handle
> floats/doubles. Also, it probably wouldn't be that hard to roll your own,
> as it were, and implement the feature yourself for your own personal use..
> if all else fails.. :/
>
> Here would be a simple and crude way to print a float using only %d as a
> primitive.. it's crude but works in a pinch for debugging code:
>
>
> void
> print_a_double (double d)
> {
> int left = d, right = (d - left) * 1000; /* change this 1000 for
> more or less
> precision */
>
>
> /* uncommend the below 'rtl_' if in rtlinux task */
> /*rtl_*/printf ("%d.%d", left, right);
> }
>
>
> -Calin
>
> >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Send your FREE holiday greetings online!
> > http://greetings.yahoo.com
> > -- [rtl] ---
> > To unsubscribe:
> > echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
> > echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
> > --
> > For more information on Real-Time Linux see:
> > http://www.rtlinux.org/
> >
>
>
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/