Skip to content

Commit 3c1782d

Browse files
committed
Address review feedback
1 parent 58a006c commit 3c1782d

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_binary_arithmetic.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2022, Oracle and/or its affiliates.
22
# Copyright (c) 2013, Regents of the University of California
33
#
44
# All rights reserved.
@@ -195,6 +195,15 @@ def test_floor_div():
195195
assert_exception(lambda: 5.4 // 0.0, ZeroDivisionError)
196196

197197

198+
def test_true_div():
199+
assert 1 / 2 == 0.5
200+
assert 108086391056891904 / 30023997515803307 == 3.6
201+
assert 295147905179352825856 / 2 == 1.4757395258967641e+20
202+
assert_exception(lambda: 1 / 0, ZeroDivisionError)
203+
assert_exception(lambda: 108086391056891904 / 0, ZeroDivisionError)
204+
assert_exception(lambda: 295147905179352825856 / 0, ZeroDivisionError)
205+
206+
198207
def test_int_rfloor_div():
199208
assert int.__rfloordiv__(2, 5) == 2
200209
assert int.__rfloordiv__(2, 0x8000000000000001) == 0x4000000000000000

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,17 @@ public abstract static class TrueDivNode extends PythonBinaryBuiltinNode {
519519
return divDD(x, y);
520520
}
521521

522-
@Specialization
522+
@Specialization(guards = {"fitsIntoDouble(x)", "fitsIntoDouble(y)"})
523523
double divLL(long x, long y) {
524-
if (fitsIntoDouble(x) && fitsIntoDouble(y)) {
525-
return divDD(x, y);
526-
} else {
527-
return op(PInt.longToBigInteger(x), PInt.longToBigInteger(y), getRaiseNode());
524+
return divDD(x, y);
525+
}
526+
527+
@Specialization(guards = {"!fitsIntoDouble(x) || !fitsIntoDouble(y)"})
528+
double divLLLarge(long x, long y) {
529+
if (y == 0) {
530+
throw raise(PythonErrorType.ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO);
528531
}
532+
return op(PInt.longToBigInteger(x), PInt.longToBigInteger(y), getRaiseNode());
529533
}
530534

531535
double divDD(double x, double y) {
@@ -581,7 +585,7 @@ private static double op(BigInteger a, BigInteger b, PRaiseNode raiseNode) {
581585
return d;
582586
}
583587

584-
private static boolean fitsIntoDouble(long x) {
588+
protected static boolean fitsIntoDouble(long x) {
585589
return x < (1L << 52) && x > -(1L << 52);
586590
}
587591

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/keywords/NonMappingException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@
4040
*/
4141
package com.oracle.graal.python.nodes.argument.keywords;
4242

43-
public class NonMappingException extends RuntimeException {
43+
public final class NonMappingException extends RuntimeException {
4444

4545
private static final long serialVersionUID = -5215981713505181732L;
4646

4747
private final Object object;
4848

4949
public NonMappingException(Object object) {
50-
super();
50+
super(null, null);
5151
this.object = object;
5252
}
5353

@@ -57,7 +57,7 @@ public Object getObject() {
5757

5858
@SuppressWarnings("sync-override")
5959
@Override
60-
public final Throwable fillInStackTrace() {
60+
public Throwable fillInStackTrace() {
6161
return this;
6262
}
6363
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/keywords/SameDictKeyException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@
4040
*/
4141
package com.oracle.graal.python.nodes.argument.keywords;
4242

43-
public class SameDictKeyException extends RuntimeException {
43+
public final class SameDictKeyException extends RuntimeException {
4444

4545
private static final long serialVersionUID = 301451134733299948L;
4646

4747
private final Object key;
4848

4949
public SameDictKeyException(Object key) {
50-
super();
50+
super(null, null);
5151
this.key = key;
5252
}
5353

@@ -57,7 +57,7 @@ public Object getKey() {
5757

5858
@SuppressWarnings("sync-override")
5959
@Override
60-
public final Throwable fillInStackTrace() {
60+
public Throwable fillInStackTrace() {
6161
return this;
6262
}
6363
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NativeLibrary.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,17 @@ enum NFIBackend {
110110
* This is a helper exception that will be thrown in case a library is {@link #optional} and not
111111
* available.
112112
*/
113-
public static class NativeLibraryCannotBeLoaded extends RuntimeException {
113+
public static final class NativeLibraryCannotBeLoaded extends RuntimeException {
114114
private static final NativeLibraryCannotBeLoaded INSTANCE = new NativeLibraryCannotBeLoaded();
115115
private static final long serialVersionUID = 6066722947025284374L;
116116

117117
private NativeLibraryCannotBeLoaded() {
118+
super(null, null);
118119
}
119120

120121
@SuppressWarnings("sync-override")
121122
@Override
122-
public final Throwable fillInStackTrace() {
123+
public Throwable fillInStackTrace() {
123124
return this;
124125
}
125126
}

graalpython/lib-python/3/test/test_int.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ def test_basic(self):
214214
self.assertEqual(int('2br45qc', 35), 4294967297)
215215
self.assertEqual(int('1z141z5', 36), 4294967297)
216216

217-
self.assertEqual(108086391056891904 / 30023997515803307, 3.6)
218-
219217
def test_underscores(self):
220218
for lit in VALID_UNDERSCORE_LITERALS:
221219
if any(ch in lit for ch in '.eEjJ'):

0 commit comments

Comments
 (0)