Skip to content

Commit ac85722

Browse files
committed
Add the copysign ufunc
1 parent 4e49714 commit ac85722

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

quaddtype/numpy_quaddtype/src/ops.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ quad_atan2(Sleef_quad *in1, Sleef_quad *in2)
339339
return Sleef_atan2q1_u10(*in1, *in2);
340340
}
341341

342+
static inline Sleef_quad
343+
quad_copysign(Sleef_quad *in1, Sleef_quad *in2)
344+
{
345+
return Sleef_copysignq1(*in1, *in2);
346+
}
347+
342348
// Binary long double operations
343349
typedef long double (*binary_op_longdouble_def)(long double *, long double *);
344350

@@ -396,6 +402,12 @@ ld_atan2(long double *in1, long double *in2)
396402
return atan2l(*in1, *in2);
397403
}
398404

405+
static inline long double
406+
ld_copysign(long double *in1, long double *in2)
407+
{
408+
return copysignl(*in1, *in2);
409+
}
410+
399411
// comparison quad functions
400412
typedef npy_bool (*cmp_quad_def)(const Sleef_quad *, const Sleef_quad *);
401413

quaddtype/numpy_quaddtype/src/umath.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ init_quad_binary_ops(PyObject *numpy)
556556
if (create_quad_binary_ufunc<quad_atan2, ld_atan2>(numpy, "arctan2") < 0) {
557557
return -1;
558558
}
559+
if (create_quad_binary_ufunc<quad_copysign, ld_copysign>(numpy, "copysign") < 0) {
560+
return -1;
561+
}
559562
return 0;
560563
}
561564

quaddtype/tests/test_quaddtype.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ def test_basic_equality():
1717
"12.0") == QuadPrecision("12.00")
1818

1919

20-
@pytest.mark.parametrize("op", ["add", "sub", "mul", "truediv", "pow"])
20+
@pytest.mark.parametrize("op", ["add", "sub", "mul", "truediv", "pow", "copysign"])
2121
@pytest.mark.parametrize("other", ["3.0", "12.5", "100.0", "0.0", "-0.0", "inf", "-inf", "nan", "-nan"])
2222
def test_binary_ops(op, other):
2323
if op == "truediv" and float(other) == 0:
2424
pytest.xfail("float division by zero")
2525

26-
op_func = getattr(operator, op)
26+
op_func = getattr(operator, op, None) or getattr(np, op)
2727
quad_a = QuadPrecision("12.5")
2828
quad_b = QuadPrecision(other)
2929
float_a = 12.5

0 commit comments

Comments
 (0)