Ah, I must have been unclear, I was not talking about comparing two floating
points, but rather if there were floating points in an expression.
Suppose for example, one had performed an analytic calculation and obtained,
f=8*x+y
but, then doing some involved calculation in sympy obtains
f=7.999999999999999*x+.999999999999999*y

Then I would like to claim that one would like to have the two expressions
are equivalent (for testing) within some accuracy.   One possibility I
suppose it to look at the difference between expressions and term by term
check all numbers and check to see if it's below some tolerance.....But, I
wanted to check if this is already in sympy, or if it is something that
should be in sympy.  I'm thinking about this for purposes of unit testing
code that relies on sympy.  One can use AssertAlmostEqual and specify a
tolerance for regular python unit tests, but for sympy, this currently will
not work.

Thanks,
William

On Sun, Jul 19, 2009 at 12:54 AM, Ondrej Certik <[email protected]> wrote:

>
> On Sat, Jul 18, 2009 at 10:49 PM, william
> ratcliff<[email protected]> wrote:
> > Related to this, how have people done unit testing of sympy related code?
> >  If for example, we expect a calculation to result in,
> > 8.0*J*S*(1-cos(q)),
> > and it instead results in:
> > 7.999999*J*S*(1-cos(q))
> > then unit tests will fail.  I assume that cmp is comparing hashes and as
> the
> > floating point numbers are different, the hashes must be different.  Is
> > there something close to the AssertAlmostEqual in unitTest.  My current
> > solution is to punt and just insert values for the symbols and test
> > numerically, but it would be nicer to test symbolically....
>
> In general we try to avoid floating point numbers as much as possible,
> e.g. instead of 8.0, we use just 8 and we don't have any problems.
>
> For floating point tests (e.g. if testing a numeric evaluation), you
> need to create (or reuse) a function like
>
> def eq(a, b, eps=1e-8):
>    return abs(a-b) < eps
>
>
> and use it like:
>
> assert eq(8, 7.999)
>
> That's a general approach for comparing floating point numbers, e.g.
> this is not specific to sympy.
>
> Ondrej
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to