On Thu, 15 Nov 2001, Tony Denault wrote:
>
> On Wed, 14 Nov 2001, Calin A. Culianu wrote:
>
> > Umm, just like printk, rtl_printf doesn't support floats. Rationale:
> > floats don't (normally) belong in the kernel. However, as we all know,
> > for scientific or other applications using rt-linux, that design choice
> > doesn't help us much... :( I myself have half a mind to patch rtl_printf
> > myself so that I can printf some floats. It shouldn't be too tough.. :/
>
> I'm sure almost all rtlinux users must hack up their own version of
> sprintf if they need floats in the RT code. I have a pretty ugly one that
> works for me (float only carried out to 3 decmial places). Handy for quick
> debugging. For real data display I used shared memory and have linux task
> do the data display. I'm post it if anyone wishes to use it. I'm sure
> there are much better version out there...how about posting them?
Hey Tony thanks a lot for the rallying call... and for the code.. :) I
think I will probably use this function for quick debugging (but for
serious display I definitely agree that user-space is the way to go).
>
> Maybe FMS can put a good implementation in their floating point
> examples so everyone benefits.
>
> Tony
>
>
> /-----------------------------------------------------------------------------\
> | Tony Denault | Internet: [EMAIL PROTECTED] |
> | NASA IRTF, Institute of Astronomy | Phone: (808) 974-4206 |
> | 1175 Manono St., Bldg 393 | Fax: (808) 974-4207 |
> | Hilo, Hawaii 96720 | |
> \-----------------------------------------------------------------------------/
>
>
> int mrt_sprintf( char * message, int msg_len, const char *format,...)
> {
>
> char buf[128];
> int pos = 0;
>
> va_list args;
>
> va_start(args,format);
>
> while (*format && (pos < msg_len-2)) {
> if (*format == '%'){
> char *b;
> ++format;
> switch(*format) {
> case 's':{
> char *s;
> s = va_arg(args,char *);
> sprintf(buf,"%s",s);
> }break;
> case 'd':{
> int d;
> d = va_arg(args,int);
> sprintf(buf,"%d",d);
> }break;
> case 'x':{
> int d;
> d = va_arg(args,int);
> sprintf(buf,"%x",d);
> }break;
> case 'g':{
> double f;
> int fi, f0, f1, f2;
> char c;
> f = va_arg(args,double);
> if (f <0){
> c = '-';
> f = -f;
> }else{
> c = ' ';
> }
> fi = (int)f; // integer portion.
> // decmial portion...get index for upto 3 decmial places.
> f = f - fi;
> f0 = f*10; f0 %= 10;
> f1 = f*100; f1 %= 10;
> f2 = f*1000; f2 %= 10;
> sprintf(buf,"%c%d.%c%c%c", c, fi, dig[f0], dig[f1], dig[f2]);
> }break;
> default:
> sprintf(buf,"(Unsupported format %c)",*format);
> }
>
> ++format;
> b = buf;
> while (*b && pos < msg_len-2){
> message[pos] = *b;
> ++b;
> ++pos;
> }
> }else{
> message[pos] = *format;
> ++pos;
> ++format;
> }
> }
>
> message[pos] = 0;
> va_end(args);
>
> return pos;
> }
>
>
>
> -- [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/