[uClibc]Problem when I try to print fp numbers with fprintf

Manuel Novoa III mjn3 at codepoet.org
Thu Jun 12 13:20:56 UTC 2003


Hello,

On Thu, Jun 12, 2003 at 02:03:18PM +0300, George Thanos wrote:
> Dear Manuel, list,
> 
> I come back again for the problem of incorrect printing of floats with 
> fprintf..
> 
> I have check _dtostr as you mentioned in your previous email (included 
> below).
> 
> Passing of float arguments is correct. I have checked the hex 
> representation of float information before
> calling fprintf and inside _dtostr. Both hex representations are the 
> same, so I have no indication that passing of float arguments is incorrect.

Ok.  Good.

> Actually I have located the problem or part of it... When I enable FP 
> exceptions "Overflow", "DivByZero" and "InvalidOperation", I receive an 
> exception inside _dtostr.
> I checked the source point of exception by commenting out code inside 
> _dtostr. The point that I receive the trap is the following :
> 
> -> libc/stdio/printf.c( line 1782 )
> 
>       /* need to build the scaling table */
>        for (i = 0, p10 = 10 ; i < EXP_TABLE_SIZE ; i++) {
>                printf("i : %d\n",i);
>                exp_table[i] = p10;
> (line 1782)         p10 *= p10;          
>        }
> 
> 
> I receive the trap when value of <i> is 8. The type of trap I receive 
> is  an overflow trap.(as expected :-).. )
> 
> p10 is of type <long double>. <long double> type in my 
> machine(Hyperstone E132XS) is 8 bytes.
> 
> I suppose this overflow condition should not normally happen.

I wrote the _dtostr code over 2 years ago, prior to uClibc having a
math library.  At the time, uClibc was working for x86 and Erik almost
had it working on arm (as I recall).  It is well overdue for a rewrite
and is on my TODO list after the l10n/i18n work.

> Can you suggest a workaround in order to cope with the problem?

Try modifying the #defines for EXP_TABLE_SIZE and MAX_DIGITS so they're
more appropriate for you arch.

>      Is there 
> any alternative to _dtostr?

Not at the moment... or at least not that I know of.

Manuel



More information about the uClibc mailing list