Python cmath.isnan() Examples
The following are 30
code examples of cmath.isnan().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cmath
, or try the search function
.
Example #1
Source File: test_cmath.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_abs(self): # zeros for z in complex_zeros: self.assertEqual(abs(z), 0.0) # infinities for z in complex_infinities: self.assertEqual(abs(z), INF) # real or imaginary part NaN self.assertEqual(abs(complex(NAN, -INF)), INF) self.assertTrue(math.isnan(abs(complex(NAN, -2.3)))) self.assertTrue(math.isnan(abs(complex(NAN, -0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 2.3)))) self.assertEqual(abs(complex(NAN, INF)), INF) self.assertEqual(abs(complex(-INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(-2.3, NAN)))) self.assertTrue(math.isnan(abs(complex(-0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(2.3, NAN)))) self.assertEqual(abs(complex(INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(NAN, NAN))))
Example #2
Source File: test_cmath.py From ironpython3 with Apache License 2.0 | 6 votes |
def assertFloatIdentical(self, x, y): """Fail unless floats x and y are identical, in the sense that: (1) both x and y are nans, or (2) both x and y are infinities, with the same sign, or (3) both x and y are zeros, with the same sign, or (4) x and y are both finite and nonzero, and x == y """ msg = 'floats {!r} and {!r} are not identical' if math.isnan(x) or math.isnan(y): if math.isnan(x) and math.isnan(y): return elif x == y: if x != 0.0: return # both zero; check that signs match elif math.copysign(1.0, x) == math.copysign(1.0, y): return else: msg += ': zeros have different signs' self.fail(msg.format(x, y))
Example #3
Source File: test_cmath.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_abs(self): # zeros for z in complex_zeros: self.assertEqual(abs(z), 0.0) # infinities for z in complex_infinities: self.assertEqual(abs(z), INF) # real or imaginary part NaN self.assertEqual(abs(complex(NAN, -INF)), INF) self.assertTrue(math.isnan(abs(complex(NAN, -2.3)))) self.assertTrue(math.isnan(abs(complex(NAN, -0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 2.3)))) self.assertEqual(abs(complex(NAN, INF)), INF) self.assertEqual(abs(complex(-INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(-2.3, NAN)))) self.assertTrue(math.isnan(abs(complex(-0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(2.3, NAN)))) self.assertEqual(abs(complex(INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(NAN, NAN))))
Example #4
Source File: test_cmath.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def assertFloatIdentical(self, x, y): """Fail unless floats x and y are identical, in the sense that: (1) both x and y are nans, or (2) both x and y are infinities, with the same sign, or (3) both x and y are zeros, with the same sign, or (4) x and y are both finite and nonzero, and x == y """ msg = 'floats {!r} and {!r} are not identical' if math.isnan(x) or math.isnan(y): if math.isnan(x) and math.isnan(y): return elif x == y: if x != 0.0: return # both zero; check that signs match elif math.copysign(1.0, x) == math.copysign(1.0, y): return else: msg += ': zeros have different signs' self.fail(msg.format(x, y))
Example #5
Source File: test_cmath.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_abs(self): # zeros for z in complex_zeros: self.assertEqual(abs(z), 0.0) # infinities for z in complex_infinities: self.assertEqual(abs(z), INF) # real or imaginary part NaN self.assertEqual(abs(complex(NAN, -INF)), INF) self.assertTrue(math.isnan(abs(complex(NAN, -2.3)))) self.assertTrue(math.isnan(abs(complex(NAN, -0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 2.3)))) self.assertEqual(abs(complex(NAN, INF)), INF) self.assertEqual(abs(complex(-INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(-2.3, NAN)))) self.assertTrue(math.isnan(abs(complex(-0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(2.3, NAN)))) self.assertEqual(abs(complex(INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(NAN, NAN))))
Example #6
Source File: test_cmath.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def assertFloatIdentical(self, x, y): """Fail unless floats x and y are identical, in the sense that: (1) both x and y are nans, or (2) both x and y are infinities, with the same sign, or (3) both x and y are zeros, with the same sign, or (4) x and y are both finite and nonzero, and x == y """ msg = 'floats {!r} and {!r} are not identical' if math.isnan(x) or math.isnan(y): if math.isnan(x) and math.isnan(y): return elif x == y: if x != 0.0: return # both zero; check that signs match elif math.copysign(1.0, x) == math.copysign(1.0, y): return else: msg += ': zeros have different signs' self.fail(msg.format(x, y))
Example #7
Source File: test_cmath.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_phase(self): self.assertAlmostEqual(phase(0), 0.) self.assertAlmostEqual(phase(1.), 0.) self.assertAlmostEqual(phase(-1.), pi) self.assertAlmostEqual(phase(-1.+1E-300j), pi) self.assertAlmostEqual(phase(-1.-1E-300j), -pi) self.assertAlmostEqual(phase(1j), pi/2) self.assertAlmostEqual(phase(-1j), -pi/2) # zeros self.assertEqual(phase(complex(0.0, 0.0)), 0.0) self.assertEqual(phase(complex(0.0, -0.0)), -0.0) self.assertEqual(phase(complex(-0.0, 0.0)), pi) self.assertEqual(phase(complex(-0.0, -0.0)), -pi) # infinities self.assertAlmostEqual(phase(complex(-INF, -0.0)), -pi) self.assertAlmostEqual(phase(complex(-INF, -2.3)), -pi) self.assertAlmostEqual(phase(complex(-INF, -INF)), -0.75*pi) self.assertAlmostEqual(phase(complex(-2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(-0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(INF, -INF)), -pi/4) self.assertEqual(phase(complex(INF, -2.3)), -0.0) self.assertEqual(phase(complex(INF, -0.0)), -0.0) self.assertEqual(phase(complex(INF, 0.0)), 0.0) self.assertEqual(phase(complex(INF, 2.3)), 0.0) self.assertAlmostEqual(phase(complex(INF, INF)), pi/4) self.assertAlmostEqual(phase(complex(2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(-INF, INF)), 0.75*pi) self.assertAlmostEqual(phase(complex(-INF, 2.3)), pi) self.assertAlmostEqual(phase(complex(-INF, 0.0)), pi) # real or imaginary part NaN for z in complex_nans: self.assertTrue(math.isnan(phase(z)))
Example #8
Source File: test_cmath.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_isnan(self): self.assertFalse(cmath.isnan(1)) self.assertFalse(cmath.isnan(1j)) self.assertFalse(cmath.isnan(INF)) self.assertTrue(cmath.isnan(NAN)) self.assertTrue(cmath.isnan(complex(NAN, 0))) self.assertTrue(cmath.isnan(complex(0, NAN))) self.assertTrue(cmath.isnan(complex(NAN, NAN))) self.assertTrue(cmath.isnan(complex(NAN, INF))) self.assertTrue(cmath.isnan(complex(INF, NAN)))
Example #9
Source File: test_cmath.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_phase(self): self.assertAlmostEqual(phase(0), 0.) self.assertAlmostEqual(phase(1.), 0.) self.assertAlmostEqual(phase(-1.), pi) self.assertAlmostEqual(phase(-1.+1E-300j), pi) self.assertAlmostEqual(phase(-1.-1E-300j), -pi) self.assertAlmostEqual(phase(1j), pi/2) self.assertAlmostEqual(phase(-1j), -pi/2) # zeros self.assertEqual(phase(complex(0.0, 0.0)), 0.0) self.assertEqual(phase(complex(0.0, -0.0)), -0.0) self.assertEqual(phase(complex(-0.0, 0.0)), pi) self.assertEqual(phase(complex(-0.0, -0.0)), -pi) # infinities self.assertAlmostEqual(phase(complex(-INF, -0.0)), -pi) self.assertAlmostEqual(phase(complex(-INF, -2.3)), -pi) self.assertAlmostEqual(phase(complex(-INF, -INF)), -0.75*pi) self.assertAlmostEqual(phase(complex(-2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(-0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(INF, -INF)), -pi/4) self.assertEqual(phase(complex(INF, -2.3)), -0.0) self.assertEqual(phase(complex(INF, -0.0)), -0.0) self.assertEqual(phase(complex(INF, 0.0)), 0.0) self.assertEqual(phase(complex(INF, 2.3)), 0.0) self.assertAlmostEqual(phase(complex(INF, INF)), pi/4) self.assertAlmostEqual(phase(complex(2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(-INF, INF)), 0.75*pi) self.assertAlmostEqual(phase(complex(-INF, 2.3)), pi) self.assertAlmostEqual(phase(complex(-INF, 0.0)), pi) # real or imaginary part NaN for z in complex_nans: self.assertTrue(math.isnan(phase(z)))
Example #10
Source File: test_cmath.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_abs(self): # zeros for z in complex_zeros: self.assertEqual(abs(z), 0.0) # infinities for z in complex_infinities: self.assertEqual(abs(z), INF) # real or imaginary part NaN self.assertEqual(abs(complex(NAN, -INF)), INF) self.assertTrue(math.isnan(abs(complex(NAN, -2.3)))) self.assertTrue(math.isnan(abs(complex(NAN, -0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 2.3)))) self.assertEqual(abs(complex(NAN, INF)), INF) self.assertEqual(abs(complex(-INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(-2.3, NAN)))) self.assertTrue(math.isnan(abs(complex(-0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(2.3, NAN)))) self.assertEqual(abs(complex(INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(NAN, NAN)))) # result overflows if float.__getformat__("double").startswith("IEEE"): self.assertRaises(OverflowError, abs, complex(1.4e308, 1.4e308))
Example #11
Source File: test_cmath.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_isnan(self): self.assertFalse(cmath.isnan(1)) self.assertFalse(cmath.isnan(1j)) self.assertFalse(cmath.isnan(INF)) self.assertTrue(cmath.isnan(NAN)) self.assertTrue(cmath.isnan(complex(NAN, 0))) self.assertTrue(cmath.isnan(complex(0, NAN))) self.assertTrue(cmath.isnan(complex(NAN, NAN))) self.assertTrue(cmath.isnan(complex(NAN, INF))) self.assertTrue(cmath.isnan(complex(INF, NAN)))
Example #12
Source File: test_cmath.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_phase(self): self.assertAlmostEqual(phase(0), 0.) self.assertAlmostEqual(phase(1.), 0.) self.assertAlmostEqual(phase(-1.), pi) self.assertAlmostEqual(phase(-1.+1E-300j), pi) self.assertAlmostEqual(phase(-1.-1E-300j), -pi) self.assertAlmostEqual(phase(1j), pi/2) self.assertAlmostEqual(phase(-1j), -pi/2) # zeros self.assertEqual(phase(complex(0.0, 0.0)), 0.0) self.assertEqual(phase(complex(0.0, -0.0)), -0.0) self.assertEqual(phase(complex(-0.0, 0.0)), pi) self.assertEqual(phase(complex(-0.0, -0.0)), -pi) # infinities self.assertAlmostEqual(phase(complex(-INF, -0.0)), -pi) self.assertAlmostEqual(phase(complex(-INF, -2.3)), -pi) self.assertAlmostEqual(phase(complex(-INF, -INF)), -0.75*pi) self.assertAlmostEqual(phase(complex(-2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(-0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(INF, -INF)), -pi/4) self.assertEqual(phase(complex(INF, -2.3)), -0.0) self.assertEqual(phase(complex(INF, -0.0)), -0.0) self.assertEqual(phase(complex(INF, 0.0)), 0.0) self.assertEqual(phase(complex(INF, 2.3)), 0.0) self.assertAlmostEqual(phase(complex(INF, INF)), pi/4) self.assertAlmostEqual(phase(complex(2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(-INF, INF)), 0.75*pi) self.assertAlmostEqual(phase(complex(-INF, 2.3)), pi) self.assertAlmostEqual(phase(complex(-INF, 0.0)), pi) # real or imaginary part NaN for z in complex_nans: self.assertTrue(math.isnan(phase(z)))
Example #13
Source File: test_cmath.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_isnan(self): self.assertFalse(cmath.isnan(1)) self.assertFalse(cmath.isnan(1j)) self.assertFalse(cmath.isnan(INF)) self.assertTrue(cmath.isnan(NAN)) self.assertTrue(cmath.isnan(complex(NAN, 0))) self.assertTrue(cmath.isnan(complex(0, NAN))) self.assertTrue(cmath.isnan(complex(NAN, NAN))) self.assertTrue(cmath.isnan(complex(NAN, INF))) self.assertTrue(cmath.isnan(complex(INF, NAN)))
Example #14
Source File: test_cmath.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_phase(self): self.assertAlmostEqual(phase(0), 0.) self.assertAlmostEqual(phase(1.), 0.) self.assertAlmostEqual(phase(-1.), pi) self.assertAlmostEqual(phase(-1.+1E-300j), pi) self.assertAlmostEqual(phase(-1.-1E-300j), -pi) self.assertAlmostEqual(phase(1j), pi/2) self.assertAlmostEqual(phase(-1j), -pi/2) # zeros self.assertEqual(phase(complex(0.0, 0.0)), 0.0) self.assertEqual(phase(complex(0.0, -0.0)), -0.0) self.assertEqual(phase(complex(-0.0, 0.0)), pi) self.assertEqual(phase(complex(-0.0, -0.0)), -pi) # infinities self.assertAlmostEqual(phase(complex(-INF, -0.0)), -pi) self.assertAlmostEqual(phase(complex(-INF, -2.3)), -pi) self.assertAlmostEqual(phase(complex(-INF, -INF)), -0.75*pi) self.assertAlmostEqual(phase(complex(-2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(-0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(INF, -INF)), -pi/4) self.assertEqual(phase(complex(INF, -2.3)), -0.0) self.assertEqual(phase(complex(INF, -0.0)), -0.0) self.assertEqual(phase(complex(INF, 0.0)), 0.0) self.assertEqual(phase(complex(INF, 2.3)), 0.0) self.assertAlmostEqual(phase(complex(INF, INF)), pi/4) self.assertAlmostEqual(phase(complex(2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(-INF, INF)), 0.75*pi) self.assertAlmostEqual(phase(complex(-INF, 2.3)), pi) self.assertAlmostEqual(phase(complex(-INF, 0.0)), pi) # real or imaginary part NaN for z in complex_nans: self.assertTrue(math.isnan(phase(z)))
Example #15
Source File: test_cmath.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_abs(self): # zeros for z in complex_zeros: self.assertEqual(abs(z), 0.0) # infinities for z in complex_infinities: self.assertEqual(abs(z), INF) # real or imaginary part NaN self.assertEqual(abs(complex(NAN, -INF)), INF) self.assertTrue(math.isnan(abs(complex(NAN, -2.3)))) self.assertTrue(math.isnan(abs(complex(NAN, -0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 2.3)))) self.assertEqual(abs(complex(NAN, INF)), INF) self.assertEqual(abs(complex(-INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(-2.3, NAN)))) self.assertTrue(math.isnan(abs(complex(-0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(2.3, NAN)))) self.assertEqual(abs(complex(INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(NAN, NAN)))) # result overflows if float.__getformat__("double").startswith("IEEE"): self.assertRaises(OverflowError, abs, complex(1.4e308, 1.4e308))
Example #16
Source File: test_cmath.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_isnan(self): self.assertFalse(cmath.isnan(1)) self.assertFalse(cmath.isnan(1j)) self.assertFalse(cmath.isnan(INF)) self.assertTrue(cmath.isnan(NAN)) self.assertTrue(cmath.isnan(complex(NAN, 0))) self.assertTrue(cmath.isnan(complex(0, NAN))) self.assertTrue(cmath.isnan(complex(NAN, NAN))) self.assertTrue(cmath.isnan(complex(NAN, INF))) self.assertTrue(cmath.isnan(complex(INF, NAN)))
Example #17
Source File: test_cmath.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_phase(self): self.assertAlmostEqual(phase(0), 0.) self.assertAlmostEqual(phase(1.), 0.) self.assertAlmostEqual(phase(-1.), pi) self.assertAlmostEqual(phase(-1.+1E-300j), pi) self.assertAlmostEqual(phase(-1.-1E-300j), -pi) self.assertAlmostEqual(phase(1j), pi/2) self.assertAlmostEqual(phase(-1j), -pi/2) # zeros self.assertEqual(phase(complex(0.0, 0.0)), 0.0) self.assertEqual(phase(complex(0.0, -0.0)), -0.0) self.assertEqual(phase(complex(-0.0, 0.0)), pi) self.assertEqual(phase(complex(-0.0, -0.0)), -pi) # infinities self.assertAlmostEqual(phase(complex(-INF, -0.0)), -pi) self.assertAlmostEqual(phase(complex(-INF, -2.3)), -pi) self.assertAlmostEqual(phase(complex(-INF, -INF)), -0.75*pi) self.assertAlmostEqual(phase(complex(-2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(-0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(INF, -INF)), -pi/4) self.assertEqual(phase(complex(INF, -2.3)), -0.0) self.assertEqual(phase(complex(INF, -0.0)), -0.0) self.assertEqual(phase(complex(INF, 0.0)), 0.0) self.assertEqual(phase(complex(INF, 2.3)), 0.0) self.assertAlmostEqual(phase(complex(INF, INF)), pi/4) self.assertAlmostEqual(phase(complex(2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(-INF, INF)), 0.75*pi) self.assertAlmostEqual(phase(complex(-INF, 2.3)), pi) self.assertAlmostEqual(phase(complex(-INF, 0.0)), pi) # real or imaginary part NaN for z in complex_nans: self.assertTrue(math.isnan(phase(z)))
Example #18
Source File: test_cmath.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_abs(self): # zeros for z in complex_zeros: self.assertEqual(abs(z), 0.0) # infinities for z in complex_infinities: self.assertEqual(abs(z), INF) # real or imaginary part NaN self.assertEqual(abs(complex(NAN, -INF)), INF) self.assertTrue(math.isnan(abs(complex(NAN, -2.3)))) self.assertTrue(math.isnan(abs(complex(NAN, -0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 2.3)))) self.assertEqual(abs(complex(NAN, INF)), INF) self.assertEqual(abs(complex(-INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(-2.3, NAN)))) self.assertTrue(math.isnan(abs(complex(-0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(2.3, NAN)))) self.assertEqual(abs(complex(INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(NAN, NAN)))) # result overflows if float.__getformat__("double").startswith("IEEE"): self.assertRaises(OverflowError, abs, complex(1.4e308, 1.4e308))
Example #19
Source File: test_cmath.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_isnan(self): self.assertFalse(cmath.isnan(1)) self.assertFalse(cmath.isnan(1j)) self.assertFalse(cmath.isnan(INF)) self.assertTrue(cmath.isnan(NAN)) self.assertTrue(cmath.isnan(complex(NAN, 0))) self.assertTrue(cmath.isnan(complex(0, NAN))) self.assertTrue(cmath.isnan(complex(NAN, NAN))) self.assertTrue(cmath.isnan(complex(NAN, INF))) self.assertTrue(cmath.isnan(complex(INF, NAN)))
Example #20
Source File: test_cmath.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_phase(self): self.assertAlmostEqual(phase(0), 0.) self.assertAlmostEqual(phase(1.), 0.) self.assertAlmostEqual(phase(-1.), pi) self.assertAlmostEqual(phase(-1.+1E-300j), pi) self.assertAlmostEqual(phase(-1.-1E-300j), -pi) self.assertAlmostEqual(phase(1j), pi/2) self.assertAlmostEqual(phase(-1j), -pi/2) # zeros self.assertEqual(phase(complex(0.0, 0.0)), 0.0) self.assertEqual(phase(complex(0.0, -0.0)), -0.0) self.assertEqual(phase(complex(-0.0, 0.0)), pi) self.assertEqual(phase(complex(-0.0, -0.0)), -pi) # infinities self.assertAlmostEqual(phase(complex(-INF, -0.0)), -pi) self.assertAlmostEqual(phase(complex(-INF, -2.3)), -pi) self.assertAlmostEqual(phase(complex(-INF, -INF)), -0.75*pi) self.assertAlmostEqual(phase(complex(-2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(-0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(INF, -INF)), -pi/4) self.assertEqual(phase(complex(INF, -2.3)), -0.0) self.assertEqual(phase(complex(INF, -0.0)), -0.0) self.assertEqual(phase(complex(INF, 0.0)), 0.0) self.assertEqual(phase(complex(INF, 2.3)), 0.0) self.assertAlmostEqual(phase(complex(INF, INF)), pi/4) self.assertAlmostEqual(phase(complex(2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(-INF, INF)), 0.75*pi) self.assertAlmostEqual(phase(complex(-INF, 2.3)), pi) self.assertAlmostEqual(phase(complex(-INF, 0.0)), pi) # real or imaginary part NaN for z in complex_nans: self.assertTrue(math.isnan(phase(z)))
Example #21
Source File: test_cmath.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_isnan(self): self.assertFalse(cmath.isnan(1)) self.assertFalse(cmath.isnan(1j)) self.assertFalse(cmath.isnan(INF)) self.assertTrue(cmath.isnan(NAN)) self.assertTrue(cmath.isnan(complex(NAN, 0))) self.assertTrue(cmath.isnan(complex(0, NAN))) self.assertTrue(cmath.isnan(complex(NAN, NAN))) self.assertTrue(cmath.isnan(complex(NAN, INF))) self.assertTrue(cmath.isnan(complex(INF, NAN)))
Example #22
Source File: test_cmath.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_abs(self): # zeros for z in complex_zeros: self.assertEqual(abs(z), 0.0) # infinities for z in complex_infinities: self.assertEqual(abs(z), INF) # real or imaginary part NaN self.assertEqual(abs(complex(NAN, -INF)), INF) self.assertTrue(math.isnan(abs(complex(NAN, -2.3)))) self.assertTrue(math.isnan(abs(complex(NAN, -0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 2.3)))) self.assertEqual(abs(complex(NAN, INF)), INF) self.assertEqual(abs(complex(-INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(-2.3, NAN)))) self.assertTrue(math.isnan(abs(complex(-0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(2.3, NAN)))) self.assertEqual(abs(complex(INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(NAN, NAN)))) # result overflows if float.__getformat__("double").startswith("IEEE"): self.assertRaises(OverflowError, abs, complex(1.4e308, 1.4e308))
Example #23
Source File: test_cmath.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_phase(self): self.assertAlmostEqual(phase(0), 0.) self.assertAlmostEqual(phase(1.), 0.) self.assertAlmostEqual(phase(-1.), pi) self.assertAlmostEqual(phase(-1.+1E-300j), pi) self.assertAlmostEqual(phase(-1.-1E-300j), -pi) self.assertAlmostEqual(phase(1j), pi/2) self.assertAlmostEqual(phase(-1j), -pi/2) # zeros self.assertEqual(phase(complex(0.0, 0.0)), 0.0) self.assertEqual(phase(complex(0.0, -0.0)), -0.0) self.assertEqual(phase(complex(-0.0, 0.0)), pi) self.assertEqual(phase(complex(-0.0, -0.0)), -pi) # infinities self.assertAlmostEqual(phase(complex(-INF, -0.0)), -pi) self.assertAlmostEqual(phase(complex(-INF, -2.3)), -pi) self.assertAlmostEqual(phase(complex(-INF, -INF)), -0.75*pi) self.assertAlmostEqual(phase(complex(-2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(-0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(INF, -INF)), -pi/4) self.assertEqual(phase(complex(INF, -2.3)), -0.0) self.assertEqual(phase(complex(INF, -0.0)), -0.0) self.assertEqual(phase(complex(INF, 0.0)), 0.0) self.assertEqual(phase(complex(INF, 2.3)), 0.0) self.assertAlmostEqual(phase(complex(INF, INF)), pi/4) self.assertAlmostEqual(phase(complex(2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(-INF, INF)), 0.75*pi) self.assertAlmostEqual(phase(complex(-INF, 2.3)), pi) self.assertAlmostEqual(phase(complex(-INF, 0.0)), pi) # real or imaginary part NaN for z in complex_nans: self.assertTrue(math.isnan(phase(z)))
Example #24
Source File: test_cmath.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_isnan(self): self.assertFalse(cmath.isnan(1)) self.assertFalse(cmath.isnan(1j)) self.assertFalse(cmath.isnan(INF)) self.assertTrue(cmath.isnan(NAN)) self.assertTrue(cmath.isnan(complex(NAN, 0))) self.assertTrue(cmath.isnan(complex(0, NAN))) self.assertTrue(cmath.isnan(complex(NAN, NAN))) self.assertTrue(cmath.isnan(complex(NAN, INF))) self.assertTrue(cmath.isnan(complex(INF, NAN)))
Example #25
Source File: test_cmath.py From oss-ftp with MIT License | 5 votes |
def test_isnan(self): self.assertFalse(cmath.isnan(1)) self.assertFalse(cmath.isnan(1j)) self.assertFalse(cmath.isnan(INF)) self.assertTrue(cmath.isnan(NAN)) self.assertTrue(cmath.isnan(complex(NAN, 0))) self.assertTrue(cmath.isnan(complex(0, NAN))) self.assertTrue(cmath.isnan(complex(NAN, NAN))) self.assertTrue(cmath.isnan(complex(NAN, INF))) self.assertTrue(cmath.isnan(complex(INF, NAN)))
Example #26
Source File: test_cmath.py From oss-ftp with MIT License | 5 votes |
def test_abs(self): # zeros for z in complex_zeros: self.assertEqual(abs(z), 0.0) # infinities for z in complex_infinities: self.assertEqual(abs(z), INF) # real or imaginary part NaN self.assertEqual(abs(complex(NAN, -INF)), INF) self.assertTrue(math.isnan(abs(complex(NAN, -2.3)))) self.assertTrue(math.isnan(abs(complex(NAN, -0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 2.3)))) self.assertEqual(abs(complex(NAN, INF)), INF) self.assertEqual(abs(complex(-INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(-2.3, NAN)))) self.assertTrue(math.isnan(abs(complex(-0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(2.3, NAN)))) self.assertEqual(abs(complex(INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(NAN, NAN)))) # result overflows if float.__getformat__("double").startswith("IEEE"): self.assertRaises(OverflowError, abs, complex(1.4e308, 1.4e308))
Example #27
Source File: test_cmath.py From oss-ftp with MIT License | 5 votes |
def test_phase(self): self.assertAlmostEqual(phase(0), 0.) self.assertAlmostEqual(phase(1.), 0.) self.assertAlmostEqual(phase(-1.), pi) self.assertAlmostEqual(phase(-1.+1E-300j), pi) self.assertAlmostEqual(phase(-1.-1E-300j), -pi) self.assertAlmostEqual(phase(1j), pi/2) self.assertAlmostEqual(phase(-1j), -pi/2) # zeros self.assertEqual(phase(complex(0.0, 0.0)), 0.0) self.assertEqual(phase(complex(0.0, -0.0)), -0.0) self.assertEqual(phase(complex(-0.0, 0.0)), pi) self.assertEqual(phase(complex(-0.0, -0.0)), -pi) # infinities self.assertAlmostEqual(phase(complex(-INF, -0.0)), -pi) self.assertAlmostEqual(phase(complex(-INF, -2.3)), -pi) self.assertAlmostEqual(phase(complex(-INF, -INF)), -0.75*pi) self.assertAlmostEqual(phase(complex(-2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(-0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(INF, -INF)), -pi/4) self.assertEqual(phase(complex(INF, -2.3)), -0.0) self.assertEqual(phase(complex(INF, -0.0)), -0.0) self.assertEqual(phase(complex(INF, 0.0)), 0.0) self.assertEqual(phase(complex(INF, 2.3)), 0.0) self.assertAlmostEqual(phase(complex(INF, INF)), pi/4) self.assertAlmostEqual(phase(complex(2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(-INF, INF)), 0.75*pi) self.assertAlmostEqual(phase(complex(-INF, 2.3)), pi) self.assertAlmostEqual(phase(complex(-INF, 0.0)), pi) # real or imaginary part NaN for z in complex_nans: self.assertTrue(math.isnan(phase(z)))
Example #28
Source File: test_cmath.py From BinderFilter with MIT License | 5 votes |
def test_isnan(self): self.assertFalse(cmath.isnan(1)) self.assertFalse(cmath.isnan(1j)) self.assertFalse(cmath.isnan(INF)) self.assertTrue(cmath.isnan(NAN)) self.assertTrue(cmath.isnan(complex(NAN, 0))) self.assertTrue(cmath.isnan(complex(0, NAN))) self.assertTrue(cmath.isnan(complex(NAN, NAN))) self.assertTrue(cmath.isnan(complex(NAN, INF))) self.assertTrue(cmath.isnan(complex(INF, NAN)))
Example #29
Source File: test_cmath.py From BinderFilter with MIT License | 5 votes |
def test_phase(self): self.assertAlmostEqual(phase(0), 0.) self.assertAlmostEqual(phase(1.), 0.) self.assertAlmostEqual(phase(-1.), pi) self.assertAlmostEqual(phase(-1.+1E-300j), pi) self.assertAlmostEqual(phase(-1.-1E-300j), -pi) self.assertAlmostEqual(phase(1j), pi/2) self.assertAlmostEqual(phase(-1j), -pi/2) # zeros self.assertEqual(phase(complex(0.0, 0.0)), 0.0) self.assertEqual(phase(complex(0.0, -0.0)), -0.0) self.assertEqual(phase(complex(-0.0, 0.0)), pi) self.assertEqual(phase(complex(-0.0, -0.0)), -pi) # infinities self.assertAlmostEqual(phase(complex(-INF, -0.0)), -pi) self.assertAlmostEqual(phase(complex(-INF, -2.3)), -pi) self.assertAlmostEqual(phase(complex(-INF, -INF)), -0.75*pi) self.assertAlmostEqual(phase(complex(-2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(-0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(0.0, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(2.3, -INF)), -pi/2) self.assertAlmostEqual(phase(complex(INF, -INF)), -pi/4) self.assertEqual(phase(complex(INF, -2.3)), -0.0) self.assertEqual(phase(complex(INF, -0.0)), -0.0) self.assertEqual(phase(complex(INF, 0.0)), 0.0) self.assertEqual(phase(complex(INF, 2.3)), 0.0) self.assertAlmostEqual(phase(complex(INF, INF)), pi/4) self.assertAlmostEqual(phase(complex(2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-0.0, INF)), pi/2) self.assertAlmostEqual(phase(complex(-2.3, INF)), pi/2) self.assertAlmostEqual(phase(complex(-INF, INF)), 0.75*pi) self.assertAlmostEqual(phase(complex(-INF, 2.3)), pi) self.assertAlmostEqual(phase(complex(-INF, 0.0)), pi) # real or imaginary part NaN for z in complex_nans: self.assertTrue(math.isnan(phase(z)))
Example #30
Source File: test_cmath.py From BinderFilter with MIT License | 5 votes |
def test_abs(self): # zeros for z in complex_zeros: self.assertEqual(abs(z), 0.0) # infinities for z in complex_infinities: self.assertEqual(abs(z), INF) # real or imaginary part NaN self.assertEqual(abs(complex(NAN, -INF)), INF) self.assertTrue(math.isnan(abs(complex(NAN, -2.3)))) self.assertTrue(math.isnan(abs(complex(NAN, -0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 0.0)))) self.assertTrue(math.isnan(abs(complex(NAN, 2.3)))) self.assertEqual(abs(complex(NAN, INF)), INF) self.assertEqual(abs(complex(-INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(-2.3, NAN)))) self.assertTrue(math.isnan(abs(complex(-0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(0.0, NAN)))) self.assertTrue(math.isnan(abs(complex(2.3, NAN)))) self.assertEqual(abs(complex(INF, NAN)), INF) self.assertTrue(math.isnan(abs(complex(NAN, NAN)))) # result overflows if float.__getformat__("double").startswith("IEEE"): self.assertRaises(OverflowError, abs, complex(1.4e308, 1.4e308))