avr-libc-dev
[Top][All Lists]
Advanced

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

Re: [avr-libc-dev] [bug #1929] -Inf not detected


From: Dmitry K.
Subject: Re: [avr-libc-dev] [bug #1929] -Inf not detected
Date: Tue, 7 Jun 2005 14:21:12 +1100
User-agent: KMail/1.5

On Monday 06 June 2005 08:07, Joerg Wunsch wrote:
> As Anatoly Sokolov wrote:
> > No this bug in gcc-4.0.0/avrlibc-1.2.3.
> > Test case work fine with all compare operation ( <, >, =>, <=).
>
> I think the problems only arise as soon as library functions are
> involved.  The compiler's handling itself is OK, but FPlib only
> supports a very simplified approach of IEEE specific numbers (NaN,
> Inf, +/- 0).

I shall add a few notes about Inf.

1.
'Inf' is not realized in avr-libc. The next examples work fine
on PC, but they are failed (return 1) with AVR/avr-libc:

------------------------------------
#include <float.h>
volatile double vx;

int main ()
{
    vx = DBL_MAX;
    vx = vx * vx;       /* overflow must        */

    vx = 1.0 / vx;      /* check of 'Inf' functionality */
    if (vx != 0.0)
        return 1;       /* error: Inf is not work       */

    return 0;
}
-------------------------------------
#include <float.h>
#include <math.h>
volatile double vx;

int main ()
{
    vx = DBL_MAX;
    vx = vx * vx;       /* overflow must        */

    if (!isinf(vx))
        return 1;       /* error: Inf (or isinf) is not work    */

    return 0;
}
-------------------------------------

2.
I think, the Inf's support absence is not an error, but it is
a very beatiful decision.  'Inf' support is very bulky. Besides
common arithmetic, same funtions are needed extra logic. For example,
atan(Inf) must be Pi/2.  'Inf' functionality is more needed in an
universal scientific library, but not in a microcontroller's
application.
   At the other hand, Avr-libs supports a NaNs: a) as over/under-flow
result, b) as any operation with NaN.  Such support in library is
not bulky and it is possible to reduce user code considarable.
With NaNs it is possible to omit all margin's cheking, and to check
only final result, at the end of work loop.

3.
NaN's support in Avr-libc is not absolutoly clean: it is possible to
obtain 0xffc0ffff and 0x7fc0ffff in another case.

4.
Avr-libc's functions 'isnan' and 'isinf' are not conform to other
library. For example, next program is failed in AVR/avr-libc:

---------------------------------------
#include <float.h>
#include <math.h>
volatile double vx;

int main ()
{
    vx = DBL_MAX;
    vx = vx * vx;       /* overflow must        */

    if (!isinf(vx) && !isnan(vx))
        return 1;       /* error: vx is not detekted, as non-normal     */

    return 0;
}
---------------------------------------

5.
'isinf', probably, should return always 0 as arithmetics with Inf is not 
realized.

I have write a corrected variant 'isnan' (7 words only). I shall send it
after testing.

Dmitry.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]