John, Thanks for your reply and suggestions. The problem with your suggestion is that a tolerance value is a single number (the way I understand it) but the representation error of floating point numbers changes depending on the value of the number itself. For example eps(10e-15) is much smaller than eps(10e+15), and it will also depend on whether the number is single or double precision. >> eps(10e-15) ans = 1.5777e-030 >> eps(10e+15) ans = 2 Arpad ========================================================== -----Original Message----- From: John Shields [mailto:John_Shields@mentor.com] Sent: Wednesday, December 20, 2006 5:16 PM To: Muranyi, Arpad Cc: vhdl-ams@vhdl.org Subject: Re: Floating point related question Hi Arpad, There is nothing in the language that I am aware of. One should only compare real numbers using a tolerance. The tolerance to use depends on the application and should be defined by the user/model writer. I think it depends on the use case you have. You should be able to write a user-defined function like eps, if you truly want to make comparisons within the tolerance that eps is defined to be or compute a tolerance based on some model of accumulated errors. There are others who may offer specific cautions, but tolerance errors can accumulate depending on how expressions are computed and compilers have some freedom in evaluation order of operands of an operator. Regards, John 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 Wed Dec 20 17:31:58 2006
This archive was generated by hypermail 2.1.8 : Wed Dec 20 2006 - 17:32:01 PST