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

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

Re: [avr-libc-dev] Pow Function in avr8


From: Amine Najahi
Subject: Re: [avr-libc-dev] Pow Function in avr8
Date: Wed, 28 Nov 2012 16:49:07 +0100

Hi George,

The pow function is part of what is called elementary functions in the
IEEE-754 floating point standard.
The standard requires +,-,*,/ and sqrt to be precise to less than 1 ulp
(unit in the last place or what you
have called machine epsilon), but does not require elementary functions to
be as precise (log, exp, sin, cos, pow).
In computer arithmetic, functions are approximated by polynomials but some
of them are
transcendental (an algebraic property), which makes approaching them to
machine precision very costly
(see http://en.wikipedia.org/wiki/Rounding#The_table-maker.27s_dilemma).

The floating point standard leaves their accuracy implementation defined
(for now, this will surely change in the future)
which means that as soon as you use one of these functions, your program
has probably no chance to be
reproducible on a different machine.

In your case, all you can say, is that on your examples, your host machine
has a better implementation that avr-libc.
A small error occurs while log is computed, gets amplified once multiplied
by the exponent i, which causes
a bigger error while computing exp (knowing that exp itself introduces its
proper error too).

To see the error appear since log's computation, take an int pointer on the
float value, and print it as an hexadecimal integer.
This will let you probably see an error on the last bits. Printing as a
float is no good idea since it involves itself a rounding
(which itself produces a rounding error :-) I know floating point math is
not intuitive at all).

Final word: it is not a bug, but the implementation's accuracy needs to be
stated somewhere in the manual.

Amine


reply via email to

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