Re: Floating point related question

From: Ernst Christen <Ernst.Christen_at_.....>
Date: Thu Dec 21 2006 - 10:23:18 PST
Arpad,

You can find an algorithm to determine the value of eps, the smallest number such that 
1.0+eps > 1.0, at http://en.wikipedia.org/wiki/Machine_epsilon. This should allow you to 
write your own function that returns this value until the functionality is provided by a 
standard. However, in my experience a dependency on comparisons for equality of floating 
point numbers is best avoided by changing the algorithm unless you know that the numbers 
you compare have an exact binary representation within the precision provided by the 
floating point format you are using.

Ernst Christen

On Wed, 20 Dec 2006 16:09:01 -0800, Muranyi, Arpad wrote:
> Hello Everyone,
>
> We all know that using relational operators between
> floating point numbers is a risky proposition.  This
> code, for example, may never execute, believe it or
> not, (I tried it):
>
>       if (0.1+0.2 = 0.3) then
>         report "Test";
>       end if;
>
> However, there are times when taking care of such
> floating point errors may be needed.
>
> In Matlab there is a function, called "eps" which
> can help in incorporating such errors in equations.
> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/index.html?/ac
> cess/helpdesk/help/techdoc/ref/eps.html&http://www.google.com/search?hl=
> en&q=eps+function
>
> I would like to find out whether there is a similar
> function in VHDL-AMS.  For a moment I thought I could
> use the T'succ(x) or related functions, but the problem
> is that this would only work on discrete or physical
> types.  The type "real" is not one of these.  Could
> someone give me some ideas how to go about this?
>
> Thanks, and Happy Holidays...
>
> Arpad
> ========================================================
Received on Thu Dec 21 10:23:27 2006

This archive was generated by hypermail 2.1.8 : Thu Dec 21 2006 - 10:24:59 PST