Пример #1
0
 def test_atan(self):
     pi4p = helpers.nudge(math.pi / 2, +1)
     self.assertEqual(imath.atan(interval[-fpu.infinity, fpu.infinity]),
                      interval([-pi4p, pi4p]))
     self.assertEqual(imath.atan(1),
                      interval[math.pi / 4,
                               helpers.nudge(math.pi / 4, +1)])
Пример #2
0
 def test_sinpi(self):
     assert imath.sinpi(fpu.infinity) == interval[-1, 1]
     assert imath.sinpi(-fpu.infinity) == interval[-1, 1]
     assert imath.sinpi(interval[0, 1]) == interval[0, 1]
     assert imath.sinpi(interval[-1, 0]) == interval[-1, 0]
     assert imath.sinpi(1/interval[6]) == interval[helpers.nudge(0.5,-1), helpers.nudge(0.5, 1)]
     assert imath.sinpi(1/interval[-6]) == interval[helpers.nudge(-0.5,-1), helpers.nudge(-0.5, 1)]
Пример #3
0
 def test_log(self):
     assert imath.log(1)                == interval[0]
     assert imath.log(0)                == interval[-fpu.infinity]
     assert imath.log(imath.exp(1))     == interval[helpers.nudge(1, -1), helpers.nudge(1, +1)]
     assert imath.log(0)                == interval[-fpu.infinity]
     assert imath.log(interval[0, 1])   == interval[-fpu.infinity, 0]
     assert imath.log(interval[-1, 1])  == interval[-fpu.infinity, 0]
     assert imath.log(interval[-2, -1]) == interval()
Пример #4
0
 def test_log(self):
     self.assertEqual(imath.log(1), interval[0])
     self.assertEqual(imath.log(0), interval[-fpu.infinity])
     self.assertEqual(imath.log(imath.exp(1)), interval[helpers.nudge(1, -1), helpers.nudge(1, +1)])
     self.assertEqual(imath.log(0), interval[-fpu.infinity])
     self.assertEqual(imath.log(interval[0, 1]), interval[-fpu.infinity, 0])
     self.assertEqual(imath.log(interval[-1, 1]), interval[-fpu.infinity, 0])
     self.assertEqual(imath.log(interval[-2, -1]), interval())
Пример #5
0
 def test_log(self):
     assert imath.log(1) == interval[0]
     assert imath.log(0) == interval[-fpu.infinity]
     assert imath.log(imath.exp(1)) == interval[helpers.nudge(1, -1),
                                                helpers.nudge(1, +1)]
     assert imath.log(0) == interval[-fpu.infinity]
     assert imath.log(interval[0, 1]) == interval[-fpu.infinity, 0]
     assert imath.log(interval[-1, 1]) == interval[-fpu.infinity, 0]
     assert imath.log(interval[-2, -1]) == interval()
Пример #6
0
 def test_sinpi(self):
     assert imath.sinpi(fpu.infinity) == interval[-1, 1]
     assert imath.sinpi(-fpu.infinity) == interval[-1, 1]
     assert imath.sinpi(interval[0, 1]) == interval[0, 1]
     assert imath.sinpi(interval[-1, 0]) == interval[-1, 0]
     assert imath.sinpi(1 / interval[6]) == interval[helpers.nudge(0.5, -1),
                                                     helpers.nudge(0.5, 1)]
     assert imath.sinpi(1 /
                        interval[-6]) == interval[helpers.nudge(-0.5, -1),
                                                  helpers.nudge(-0.5, 1)]
Пример #7
0
 def test_log(self):
     self.assertEqual(imath.log(1), interval[0])
     self.assertEqual(imath.log(0), interval[-fpu.infinity])
     self.assertEqual(imath.log(imath.exp(1)),
                      interval[helpers.nudge(1, -1),
                               helpers.nudge(1, +1)])
     self.assertEqual(imath.log(0), interval[-fpu.infinity])
     self.assertEqual(imath.log(interval[0, 1]), interval[-fpu.infinity, 0])
     self.assertEqual(imath.log(interval[-1, 1]), interval[-fpu.infinity,
                                                           0])
     self.assertEqual(imath.log(interval[-2, -1]), interval())
Пример #8
0
 def test_nudge(self):
     self.assertEqual(helpers.nudge(5249383869325653 * 2.0 ** -51, +1), 5249383869325654 * 2.0 ** -51)
     self.assertEqual(helpers.nudge(5249383869325653 * 2.0 ** -51, -1), 5249383869325652 * 2.0 ** -51)
     self.assertEqual(helpers.nudge(5249383869325652 * 2.0 ** -51, +2), 5249383869325654 * 2.0 ** -51)
     self.assertEqual(helpers.nudge(5249383869325654 * 2.0 ** -51, -2), 5249383869325652 * 2.0 ** -51)
     self.assertEqual(helpers.nudge(-5249383869325653 * 2.0 ** -51, +1), -5249383869325652 * 2.0 ** -51)
     self.assertEqual(helpers.nudge(-5249383869325653 * 2.0 ** -51, -1), -5249383869325654 * 2.0 ** -51)
     self.assertEqual(helpers.nudge(9007199254740991 * 2.0 ** -51, +1), 4503599627370496 * 2.0 ** -50)
     self.assertEqual(helpers.nudge(16.0, -1), 9007199254740991 * 2.0 ** -49)
     self.assertEqual(helpers.nudge(9007199254740991 * 2.0 ** -49, +1), 16.0)
     self.assertEqual(helpers.nudge(0, +1), 2.0 ** -1074)
Пример #9
0
 def test_nudge(self):
     assert helpers.nudge(5249383869325653 * 2.0 ** -51, +1)  ==  5249383869325654 * 2.0 ** -51
     assert helpers.nudge(5249383869325653 * 2.0 ** -51, -1)  ==  5249383869325652 * 2.0 ** -51
     assert helpers.nudge(5249383869325652 * 2.0 ** -51, +2)  ==  5249383869325654 * 2.0 ** -51
     assert helpers.nudge(5249383869325654 * 2.0 ** -51, -2)  ==  5249383869325652 * 2.0 ** -51
     assert helpers.nudge(-5249383869325653 * 2.0 ** -51, +1) == -5249383869325652 * 2.0 ** -51
     assert helpers.nudge(-5249383869325653 * 2.0 ** -51, -1) == -5249383869325654 * 2.0 ** -51
     assert helpers.nudge(9007199254740991 * 2.0 ** -51, +1)  ==  4503599627370496 * 2.0 ** -50
     assert helpers.nudge(16.0, -1)                           ==  9007199254740991 * 2.0 ** -49
     assert helpers.nudge(9007199254740991 * 2.0 ** -49, +1)  ==  16.0
     assert helpers.nudge(0, +1)                              ==  2.0 ** -1074
Пример #10
0
    def test_tanh(self):
        tanh = imath.tanh
        inf = fpu.infinity
        assert tanh(0) == interval[0]
        assert tanh(inf) == interval[1.0]
        assert tanh(-inf) == interval[-1.0]
        assert tanh(-12347.1234) == interval[-1, helpers.nudge(-1.0,+1)]

        def check(x):
            x = interval(x)
            z = tanh(x)
            assert z in imath.sinh(x)/imath.cosh(x)

        check(1)
        check(-0.123)
        check(9.9873e20)
        check(-12347.1234)
        check(interval[1,2])
        check(interval[-5.1, 1.2])

        from random import seed, random
        seed(123456)
        for i in xrange(100):
            x = random()
            check(x)
            check(1/x)
            check(-x)
            check(-1/x)
Пример #11
0
    def test_tanh(self):
        tanh = imath.tanh
        inf = fpu.infinity
        assert tanh(0) == interval[0]
        assert tanh(inf) == interval[1.0]
        assert tanh(-inf) == interval[-1.0]
        assert tanh(-12347.1234) == interval[-1, helpers.nudge(-1.0, +1)]

        def check(x):
            x = interval(x)
            z = tanh(x)
            assert z in imath.sinh(x) / imath.cosh(x)

        check(1)
        check(-0.123)
        check(9.9873e20)
        check(-12347.1234)
        check(interval[1, 2])
        check(interval[-5.1, 1.2])

        from random import seed, random
        seed(123456)
        for i in xrange(100):
            x = random()
            check(x)
            check(1 / x)
            check(-x)
            check(-1 / x)
Пример #12
0
 def test_atanpi(self):
     assert imath.atanpi(interval[-fpu.infinity,
                                  fpu.infinity]) == interval[-0.5, 0.5]
     # The following fails on Win at 32 bits
     if not (platform.system() == 'Windows'
             and platform.architecture()[0] == '32bit'):
         assert imath.atanpi(1) == interval[0.25, helpers.nudge(0.25, +1)]
Пример #13
0
 def test_exp(self):
     self.assertEqual(imath.exp(0), interval[1])
     self.assertEqual(imath.exp(1), interval[math.e,
                                             helpers.nudge(math.e, +1)])
     self.assertEqual(
         imath.exp(interval([-fpu.infinity, 0], [1, fpu.infinity])),
         interval([0, 1], [math.e, fpu.infinity]))
Пример #14
0
    def test_exp(self):
        z = interval[-100, 100].newton(lambda x: imath.exp(x) + x,
                                       lambda x: imath.exp(x) + 1)
        assert z == interval[-0.56714329040978395,
                             helpers.nudge(-0.56714329040978395, +1)]

        w = interval[-100, 100].newton(lambda x: imath.exp(-x) * x + 1,
                                       lambda x: imath.exp(-x) * (1 - x))
        assert z == w
Пример #15
0
 def test_nudge(self):
     self.assertEqual(helpers.nudge(5249383869325653 * 2.0**-51, +1),
                      5249383869325654 * 2.0**-51)
     self.assertEqual(helpers.nudge(5249383869325653 * 2.0**-51, -1),
                      5249383869325652 * 2.0**-51)
     self.assertEqual(helpers.nudge(5249383869325652 * 2.0**-51, +2),
                      5249383869325654 * 2.0**-51)
     self.assertEqual(helpers.nudge(5249383869325654 * 2.0**-51, -2),
                      5249383869325652 * 2.0**-51)
     self.assertEqual(helpers.nudge(-5249383869325653 * 2.0**-51, +1),
                      -5249383869325652 * 2.0**-51)
     self.assertEqual(helpers.nudge(-5249383869325653 * 2.0**-51, -1),
                      -5249383869325654 * 2.0**-51)
     self.assertEqual(helpers.nudge(9007199254740991 * 2.0**-51, +1),
                      4503599627370496 * 2.0**-50)
     self.assertEqual(helpers.nudge(16.0, -1), 9007199254740991 * 2.0**-49)
     self.assertEqual(helpers.nudge(9007199254740991 * 2.0**-49, +1), 16.0)
     self.assertEqual(helpers.nudge(0, +1), 2.0**-1074)
Пример #16
0
 def test_nudge(self):
     assert helpers.nudge(5249383869325653 * 2.0**-51,
                          +1) == 5249383869325654 * 2.0**-51
     assert helpers.nudge(5249383869325653 * 2.0**-51,
                          -1) == 5249383869325652 * 2.0**-51
     assert helpers.nudge(5249383869325652 * 2.0**-51,
                          +2) == 5249383869325654 * 2.0**-51
     assert helpers.nudge(5249383869325654 * 2.0**-51,
                          -2) == 5249383869325652 * 2.0**-51
     assert helpers.nudge(-5249383869325653 * 2.0**-51,
                          +1) == -5249383869325652 * 2.0**-51
     assert helpers.nudge(-5249383869325653 * 2.0**-51,
                          -1) == -5249383869325654 * 2.0**-51
     assert helpers.nudge(9007199254740991 * 2.0**-51,
                          +1) == 4503599627370496 * 2.0**-50
     assert helpers.nudge(16.0, -1) == 9007199254740991 * 2.0**-49
     assert helpers.nudge(9007199254740991 * 2.0**-49, +1) == 16.0
     assert helpers.nudge(0, +1) == 2.0**-1074
Пример #17
0
 def test_trig(self):
     assert imath.sin(imath.pi / 2) == interval[helpers.nudge(1, -1), 1]
     assert imath.cos(imath.pi) == interval[-1, helpers.nudge(-1, +1)]
     assert imath.cos(imath.pi /
                      interval[3]) == interval[helpers.nudge(0.5, -6),
                                               helpers.nudge(0.5, 1)]
     assert imath.tan(imath.pi / 4) == interval[helpers.nudge(1, -1),
                                                helpers.nudge(1, +1)]
Пример #18
0
 def test_cospi(self):
     assert imath.cospi(fpu.infinity) == interval[-1, 1]
     assert imath.cospi(-fpu.infinity) == interval[-1, 1]
     assert imath.cospi(interval[0.5, 1.5]) == interval[-1, 0]
     assert imath.cospi(interval[-0.5, 0.5]) == interval[0, 1]
     assert imath.cospi(1/interval[3]) == interval[helpers.nudge(0.5,-2), helpers.nudge(0.5, 1)]
     assert imath.cospi(-1/interval[3]) == interval[helpers.nudge(0.5,-2), helpers.nudge(0.5, 1)]
     assert imath.cospi(2/interval[3]) == interval[helpers.nudge(-0.5,-2), helpers.nudge(-0.5,2)]
     assert imath.cospi(interval[6]**-1) == imath.sqrt(3)/2
Пример #19
0
 def test_cospi(self):
     assert imath.cospi(fpu.infinity) == interval[-1, 1]
     assert imath.cospi(-fpu.infinity) == interval[-1, 1]
     assert imath.cospi(interval[0.5, 1.5]) == interval[-1, 0]
     assert imath.cospi(interval[-0.5, 0.5]) == interval[0, 1]
     assert imath.cospi(1 / interval[3]) == interval[helpers.nudge(0.5, -2),
                                                     helpers.nudge(0.5, 1)]
     assert imath.cospi(-1 /
                        interval[3]) == interval[helpers.nudge(0.5, -2),
                                                 helpers.nudge(0.5, 1)]
     assert imath.cospi(2 /
                        interval[3]) == interval[helpers.nudge(-0.5, -2),
                                                 helpers.nudge(-0.5, 2)]
     assert imath.cospi(interval[6]**-1) == imath.sqrt(3) / 2
Пример #20
0
 def test_exp(self):
     assert imath.exp(0) == interval[1]
     assert imath.exp(1) == interval[math.e, helpers.nudge(math.e, +1)]
     assert (imath.exp(interval([-fpu.infinity, 0],
                                [1, fpu.infinity])) == interval(
                                    [0, 1], [math.e, fpu.infinity]))
Пример #21
0
 def test_exp(self):
     self.assertEqual(imath.exp(0), interval[1])
     self.assertEqual(imath.exp(1), interval[math.e, helpers.nudge(math.e, +1)])
     self.assertEqual(imath.exp(interval([-fpu.infinity, 0], [1, fpu.infinity])),
                      interval([0, 1], [math.e, fpu.infinity]))
Пример #22
0
    def test_exp(self):
        z = interval[-100, 100].newton(lambda x: imath.exp(x) + x, lambda x: imath.exp(x) + 1)
        assert z == interval[-0.56714329040978395, helpers.nudge(-0.56714329040978395, +1)]

        w = interval[-100, 100].newton(lambda x: imath.exp(-x)*x + 1, lambda x: imath.exp(-x)*(1-x))
        assert z == w
Пример #23
0
 def test_trig(self):
     assert imath.sin(imath.pi/2) == interval[helpers.nudge(1, -1), 1]
     assert imath.cos(imath.pi) == interval[-1, helpers.nudge(-1, +1)]
     assert imath.cos(imath.pi/interval[3]) == interval[helpers.nudge(0.5,-6), helpers.nudge(0.5, 1)]
     assert imath.tan(imath.pi/4) == interval[helpers.nudge(1,-1), helpers.nudge(1, +1)]
Пример #24
0
 def test_atan(self):
     pi4p = helpers.nudge(math.pi / 2, +1)
     assert imath.atan(interval[-fpu.infinity,
                                fpu.infinity]) == interval([-pi4p, pi4p])
     assert imath.atan(1) == interval[math.pi / 4,
                                      helpers.nudge(math.pi / 4, +1)]
Пример #25
0
 def test_atanpi(self):
     self.assertEqual(imath.atanpi(interval[-fpu.infinity, fpu.infinity]), interval[-0.5, 0.5])
     # The following fails on Win at 32 bits
     if not (platform.system() == 'Windows' and platform.architecture()[0] == '32bit'):
         self.assertEqual(imath.atanpi(1), interval[0.25, helpers.nudge(0.25, +1)])
Пример #26
0
 def test_atan(self):
     pi4p = helpers.nudge(math.pi / 2, +1)
     self.assertEqual(imath.atan(interval[-fpu.infinity, fpu.infinity]),
                      interval([-pi4p, pi4p]))
     self.assertEqual(imath.atan(1), interval[math.pi / 4, helpers.nudge(math.pi / 4, +1)])
Пример #27
0
 def test_exp(self):
     assert imath.exp(0) == interval[1]
     assert imath.exp(1) == interval[math.e, helpers.nudge(math.e, +1)]
     assert (
         imath.exp(interval([-fpu.infinity, 0], [1, fpu.infinity])) ==
         interval([0, 1], [math.e, fpu.infinity]))
Пример #28
0
 def test_atan(self):
     pi4p = helpers.nudge(math.pi / 2, +1)
     assert imath.atan(interval[-fpu.infinity, fpu.infinity]) == interval([-pi4p, pi4p])
     assert imath.atan(1)                                     == interval[math.pi / 4, helpers.nudge(math.pi / 4, +1)]