Exemple #1
0
    def ftest(self, name, value, expected, ulps_err=1):

        if expected != 0.:
            # Tolerate small deviation in proportion to expected
            ulp_unit = Math.ulp(expected)
        else:
            # On zero, allow 2**-52. Maybe allow different slack based on name
            ulp_unit = Math.ulp(1.)

        # Complex expressions accumulate errors
        if name in ('cosh(2)-2*cosh(1)**2', 'sinh(1)**2-cosh(1)**2'):
            # ... quite steeply in these cases
            ulps_err *= 5

        err = value - expected

        if abs(err) > ulps_err * ulp_unit:
            # Use %r to display full precision.
            message = '%s returned %r, expected %r (%r ulps)' % \
                (name, value, expected, round(err/ulp_unit, 1))
            self.fail(message)
Exemple #2
0
    def ftest(self, name, value, expected, ulps_err=1):

        if expected != 0. :
            # Tolerate small deviation in proportion to expected
            ulp_unit = Math.ulp(expected)
        else :
            # On zero, allow 2**-52. Maybe allow different slack based on name
            ulp_unit = Math.ulp(1.)

        # Complex expressions accumulate errors
        if name in ('cosh(2)-2*cosh(1)**2', 'sinh(1)**2-cosh(1)**2') :
            # ... quite steeply in these cases
            ulps_err *= 5

        err = value-expected

        if abs(err) > ulps_err * ulp_unit:
            # Use %r to display full precision.
            message = '%s returned %r, expected %r (%r ulps)' % \
                (name, value, expected, round(err/ulp_unit, 1))
            self.fail(message)