Skip to content

Commit 7e0ecb2

Browse files
committed
[GR-23291] Fixed float.__trunc__
PullRequest: graalpython/1185
2 parents a63def1 + 72bb3ab commit 7e0ecb2

File tree

2 files changed

+2
-38
lines changed

2 files changed

+2
-38
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_fractions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*graalpython.lib-python.3.test.test_fractions.FractionTest.testApproximatePi
33
*graalpython.lib-python.3.test.test_fractions.FractionTest.testArithmetic
44
*graalpython.lib-python.3.test.test_fractions.FractionTest.testBigComplexComparisons
5+
*graalpython.lib-python.3.test.test_fractions.FractionTest.testBigFloatComparisons
56
*graalpython.lib-python.3.test.test_fractions.FractionTest.testBoolGuarateesBoolReturn
67
*graalpython.lib-python.3.test.test_fractions.FractionTest.testComparisons
78
*graalpython.lib-python.3.test.test_fractions.FractionTest.testComparisonsDummyFloat

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ boolean bool(double self) {
222222
}
223223

224224
@Builtin(name = __INT__, minNumOfPositionalArgs = 1)
225+
@Builtin(name = __TRUNC__, minNumOfPositionalArgs = 1)
225226
@GenerateNodeFactory
226227
@ImportStatic(MathGuards.class)
227228
@TypeSystemReference(PythonArithmeticTypes.class)
@@ -1563,44 +1564,6 @@ abstract static class ConjugateNode extends RealNode {
15631564

15641565
}
15651566

1566-
@Builtin(name = __TRUNC__, minNumOfPositionalArgs = 1)
1567-
@GenerateNodeFactory
1568-
abstract static class TruncNode extends PythonUnaryBuiltinNode {
1569-
1570-
@TruffleBoundary
1571-
protected static int truncate(double value) {
1572-
return (int) (value < 0 ? Math.ceil(value) : Math.floor(value));
1573-
}
1574-
1575-
@Specialization
1576-
int trunc(double value,
1577-
@Cached("createBinaryProfile()") ConditionProfile nanProfile,
1578-
@Cached("createBinaryProfile()") ConditionProfile infProfile) {
1579-
if (nanProfile.profile(Double.isNaN(value))) {
1580-
throw raise(PythonErrorType.ValueError, ErrorMessages.CANNOT_CONVERT_S_TO_INT, "float NaN");
1581-
}
1582-
if (infProfile.profile(Double.isInfinite(value))) {
1583-
throw raise(PythonErrorType.OverflowError, ErrorMessages.CANNOT_CONVERT_S_TO_INT, "float infinity");
1584-
}
1585-
return truncate(value);
1586-
}
1587-
1588-
@Specialization
1589-
int trunc(PFloat pValue,
1590-
@Cached("createBinaryProfile()") ConditionProfile nanProfile,
1591-
@Cached("createBinaryProfile()") ConditionProfile infProfile) {
1592-
double value = pValue.getValue();
1593-
if (nanProfile.profile(Double.isNaN(value))) {
1594-
throw raise(PythonErrorType.ValueError, ErrorMessages.CANNOT_CONVERT_S_TO_INT, "float NaN");
1595-
}
1596-
if (infProfile.profile(Double.isInfinite(value))) {
1597-
throw raise(PythonErrorType.OverflowError, ErrorMessages.CANNOT_CONVERT_S_TO_INT, "float infinity");
1598-
}
1599-
return truncate(value);
1600-
}
1601-
1602-
}
1603-
16041567
@Builtin(name = __GETFORMAT__, minNumOfPositionalArgs = 2, isClassmethod = true)
16051568
@GenerateNodeFactory
16061569
@TypeSystemReference(PythonArithmeticTypes.class)

0 commit comments

Comments
 (0)