Skip to content

Commit 9e5eff0

Browse files
committed
Implementation of float.is_integer()
1 parent e0d03ad commit 9e5eff0

File tree

1 file changed

+15
-0
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,4 +1575,19 @@ protected void raiseDivisionByZero(boolean cond) {
15751575
}
15761576
}
15771577
}
1578+
1579+
@Builtin(name = "is_integer", minNumOfPositionalArgs = 1)
1580+
@GenerateNodeFactory
1581+
abstract static class IsIntegerNode extends PythonUnaryBuiltinNode {
1582+
@Specialization
1583+
boolean isInteger(double value) {
1584+
return Double.isFinite(value) && (long) value == value;
1585+
}
1586+
1587+
@Specialization
1588+
boolean trunc(PFloat pValue) {
1589+
return isInteger(pValue.getValue());
1590+
}
1591+
1592+
}
15781593
}

0 commit comments

Comments
 (0)