Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions mpfdtype/mpfdtype/src/ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ absolute(mpfr_t op, mpfr_t out)
static inline int
sqrt(mpfr_t op, mpfr_t out)
{
return mpfr_pow_si(out, op, 2, MPFR_RNDN);
return mpfr_sqrt(out, op, MPFR_RNDN);
}

static inline int
square(mpfr_t op, mpfr_t out)
{
return mpfr_sqrt(out, op, MPFR_RNDN);
return mpfr_pow_si(out, op, 2, MPFR_RNDN);
}

static inline int
Expand Down Expand Up @@ -140,7 +140,7 @@ arccos(mpfr_t op, mpfr_t out)
static inline int
arctan(mpfr_t op, mpfr_t out)
{
return mpfr_tan(out, op, MPFR_RNDN);
return mpfr_atan(out, op, MPFR_RNDN);
}


Expand Down
11 changes: 10 additions & 1 deletion mpfdtype/mpfdtype/src/umath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,21 @@ int init_unary_ops(PyObject *numpy)
if (create_unary_ufunc<exp>(numpy, "exp") < 0) {
return -1;
}
if (create_unary_ufunc<exp>(numpy, "exp2") < 0) {
if (create_unary_ufunc<exp2>(numpy, "exp2") < 0) {
return -1;
}
if (create_unary_ufunc<expm1>(numpy, "expm1") < 0) {
return -1;
}
if (create_unary_ufunc<sin>(numpy, "sin") < 0) {
return -1;
}
if (create_unary_ufunc<cos>(numpy, "cos") < 0) {
return -1;
}
if (create_unary_ufunc<tan>(numpy, "tan") < 0) {
return -1;
}
if (create_unary_ufunc<arcsin>(numpy, "arcsin") < 0) {
return -1;
}
Expand Down
17 changes: 17 additions & 0 deletions mpfdtype/mpfdtype/tests/test_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ def test_scalar_repr(val):
expected = f"MPFloat('{val_repr}', prec=20)"
assert repr(MPFloat(val, prec=20)) == expected

@pytest.mark.parametrize("op",
["negative", "positive", "absolute",
"rint", "trunc", "floor", "ceil",
"sqrt", "square",
"log", "log2", "log10", "log1p",
"exp", "exp2", "expm1",
"sin", "cos", "tan",
"arcsin", "arccos", "arctan"])
@pytest.mark.parametrize("val", [0.5, 3., 12.5, 100., np.nan, np.inf])
def test_unary_ops(op, val):
op = getattr(np, op)
expected = op(val)
if np.isnan(expected):
assert op(MPFloat(val)) != op(MPFloat(val))
else:
assert op(MPFloat(val)) == expected

@pytest.mark.parametrize("op",
["add", "sub", "mul", "pow"])
@pytest.mark.parametrize("other", [3., 12.5, 100., np.nan, np.inf])
Expand Down
Loading