コード例 #1
0
ファイル: test_extra.py プロジェクト: dpsanders/pyinterval
 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
ファイル: test_extra.py プロジェクト: dorellang/pyinterval
 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
ファイル: test_extra.py プロジェクト: akshatd/pyinterval
 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
ファイル: test_extra.py プロジェクト: dorellang/pyinterval
 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
ファイル: test_extra.py プロジェクト: dpsanders/pyinterval
 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
ファイル: test_extra.py プロジェクト: dpsanders/pyinterval
 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
ファイル: test_extra.py プロジェクト: dorellang/pyinterval
 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
ファイル: test_extra.py プロジェクト: akshatd/pyinterval
 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
ファイル: test_extra.py プロジェクト: dorellang/pyinterval
    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
ファイル: test_extra.py プロジェクト: dpsanders/pyinterval
    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
ファイル: test_extra.py プロジェクト: dpsanders/pyinterval
 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
ファイル: test_extra.py プロジェクト: dpsanders/pyinterval
    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
ファイル: test_extra.py プロジェクト: dpsanders/pyinterval
 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
ファイル: test_extra.py プロジェクト: dpsanders/pyinterval
 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
ファイル: test_extra.py プロジェクト: dorellang/pyinterval
 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
ファイル: test_extra.py プロジェクト: dpsanders/pyinterval
 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
ファイル: test_extra.py プロジェクト: dorellang/pyinterval
 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
ファイル: test_extra.py プロジェクト: dorellang/pyinterval
    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
ファイル: test_extra.py プロジェクト: dorellang/pyinterval
 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
ファイル: test_extra.py プロジェクト: dorellang/pyinterval
 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
ファイル: test_extra.py プロジェクト: dorellang/pyinterval
 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
ファイル: test_extra.py プロジェクト: akshatd/pyinterval
 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
ファイル: test_extra.py プロジェクト: akshatd/pyinterval
 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)]