At the risk of pointing out the obvious, there are 2 well known tests for the closeness of two numbers.
relative error and absolute error. abs( (a-b)/a) is relative error [assume a [or b] is not zero) and abs( a-b ) is absolute error. Defining another error measurement by "how many digits are the same when you print" is probably not very useful except if you are doing some kind of "look at me, let's be friends because we have the same color hair" test. By that test, 10.9 is much closer to 10.0 than 9.99 is to 10.0 . 9.99 has NO digits in common with 10.0 and in fact doesn't even have the same number of digits to the left of the decimal point, So how could it be close? Note, if you want to take high precision numbers and correctly round to just a few digits and compare the rounded values, you can do this arithmetically. You do not have to print them. RJF On Mar 14, 6:38 am, Nils Bruin <nbr...@sfu.ca> wrote: > On Mar 13, 4:34 pm, Julien PUYDT <julien.pu...@laposte.net> wrote: > > > Hi, > > > among the few failing tests with my ARM built, two are because of > > accuracy reasons : > > > File "/home/jpuydt/sage-4.6.2/devel/sage/sage/functions/other.py", line 497: > > sage: gamma1(float(6)) > > Expected: > > 120.0 > > Got: > > 119.99999999999997 > > Why are we even testing the behaviour on floats? Isn't sage's default > floating point type RDF? > > sage: a=float(119.99999999999997) > sage: a > 119.99999999999997 > sage: RDF(a) > 120.0 > sage: float(RDF(a)) > 119.99999999999997 > > CPython explicitly defers to the C it is compiled with to define the > behaviour or "float". See sys.float_info for more information. It's a > bit ridiculous to test verbatim behaviour for something that is > defined to be varying (although you may want to doctest exactly that > to be aware of possible sources of different behaviour on different > platforms). > > Anyway, "RDF" has a lot more tolerant printing behaviour than "float" > -- I guess Python's printing produces enough decimal digits to > faithfully reconstruct the binary representation? Doctesting > RDF(gamma1(float(6.0))) would probably test float arithmetic but print > the result in a way that it is easier to pass doctests, without > allowing for very big inaccuracies. -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org