Skip to content

Commit cffb867

Browse files
committed
Handle NaN result of unary math functions
1 parent 15ee0a6 commit cffb867

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,29 @@ public double count(@SuppressWarnings("unused") double value) {
122122

123123
@Specialization
124124
public double doL(long value) {
125-
return count(value);
125+
return op(value);
126126
}
127127

128128
@Specialization
129129
public double doD(double value) {
130-
return count(value);
130+
return op(value);
131131
}
132132

133133
@Specialization
134134
public double doPI(PInt value) {
135-
return count(value.doubleValueWithOverflow(getRaiseNode()));
135+
return op(value.doubleValueWithOverflow(getRaiseNode()));
136136
}
137137

138138
@Specialization(guards = "!isNumber(value)", limit = "1")
139139
public double doGeneral(Object value,
140140
@CachedLibrary("value") PythonObjectLibrary lib) {
141-
return count(lib.asJavaDouble(value));
141+
return op(lib.asJavaDouble(value));
142+
}
143+
144+
private double op(double arg) {
145+
double res = count(arg);
146+
checkMathDomainError(Double.isNaN(res) && !Double.isNaN(arg));
147+
return res;
142148
}
143149
}
144150

0 commit comments

Comments
 (0)