Skip to content

Commit 84e82a0

Browse files
committed
upgrade most of the math module to 2.6
1 parent 661d87f commit 84e82a0

5 files changed

Lines changed: 536 additions & 69 deletions

File tree

Lib/test/test_math_jy.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from test import test_support
88

99
inf = float('inf')
10+
ninf = float('-inf')
1011
nan = float('nan')
1112

1213
class MathTestCase(unittest.TestCase):
@@ -17,6 +18,16 @@ def test_frexp(self):
1718
self.assertNotEqual(mantissa, mantissa)
1819
self.assertEqual(exponent, 0)
1920

21+
def test_fmod(self):
22+
self.assertEqual(-1e-100, math.fmod(-1e-100, 1e100))
23+
24+
def test_hypot(self):
25+
self.assert_(math.isnan(math.hypot(nan, nan)))
26+
self.assertEqual(inf, math.hypot(inf, 4))
27+
self.assertEqual(inf, math.hypot(4, inf))
28+
self.assertEqual(inf, math.hypot(ninf, 4))
29+
self.assertEqual(inf, math.hypot(4, ninf))
30+
2031

2132
def test_main():
2233
test_support.run_unittest(MathTestCase)

src/org/python/compiler/Module.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public boolean equals(Object o) {
7272
}
7373

7474
class PyFloatConstant extends Constant implements ClassConstants, Opcodes {
75-
75+
private static final double ZERO = 0.0;
76+
7677
final double value;
7778

7879
PyFloatConstant(double value) {
@@ -98,10 +99,14 @@ public int hashCode() {
9899
@Override
99100
public boolean equals(Object o) {
100101
if (o instanceof PyFloatConstant) {
101-
return ((PyFloatConstant) o).value == value;
102-
} else {
103-
return false;
102+
double oVal = ((PyFloatConstant)o).value;
103+
if (ZERO == value) {
104+
// math.copysign() needs to distinguish signs of zeroes
105+
return oVal == value && Double.toString(oVal).equals(Double.toString(value));
106+
}
107+
return oVal == value;
104108
}
109+
return false;
105110
}
106111
}
107112

0 commit comments

Comments
 (0)