Skip to content

Commit 2a2df0b

Browse files
committed
Fixed math.asinh for special cases as required by cmath tests
1 parent 0070de4 commit 2a2df0b

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,12 +1568,35 @@ public double count(double value) {
15681568
@GenerateNodeFactory
15691569
public abstract static class AsinhNode extends MathDoubleUnaryBuiltinNode {
15701570

1571+
private static final double LN_2 = 6.93147180559945286227e-01;
1572+
private static final double TWO_POW_P28 = 0x1.0p28;
1573+
private static final double TWO_POW_M28 = 0x1.0p-28;
1574+
15711575
@Override
1576+
@TruffleBoundary
15721577
public double count(double value) {
1573-
if (Double.isInfinite(value)) {
1578+
double absx = Math.abs(value);
1579+
1580+
if (Double.isNaN(value) || Double.isInfinite(value)) {
1581+
return value + value;
1582+
}
1583+
if (absx < TWO_POW_M28) {
15741584
return value;
15751585
}
1576-
return Math.log(value + Math.sqrt(value * value + 1.0));
1586+
double w;
1587+
if (absx > TWO_POW_P28) {
1588+
w = Math.log(absx) + LN_2;
1589+
} else if (absx > 2.0) {
1590+
w = Math.log(2.0 * absx + 1.0 / (Math.sqrt(value * value + 1.0) + absx));
1591+
} else {
1592+
double t = value * value;
1593+
w = Math.log1p(absx + t / (1.0 + Math.sqrt(1.0 + t)));
1594+
}
1595+
return Math.copySign(w, value);
1596+
}
1597+
1598+
public static AsinhNode create() {
1599+
return MathModuleBuiltinsFactory.AsinhNodeFactory.create();
15771600
}
15781601
}
15791602

0 commit comments

Comments
 (0)