diff --git a/include/fintamath/numbers/RealFunctions.hpp b/include/fintamath/numbers/RealFunctions.hpp index d037f8fbf..85ece19b4 100644 --- a/include/fintamath/numbers/RealFunctions.hpp +++ b/include/fintamath/numbers/RealFunctions.hpp @@ -28,6 +28,10 @@ Real tan(const Real &rhs); Real cot(const Real &rhs); +Real sec(const Real &rhs); + +Real csc(const Real &rhs); + Real asin(const Real &rhs); Real acos(const Real &rhs); @@ -36,6 +40,10 @@ Real atan(const Real &rhs); Real acot(const Real &rhs); +Real asec(const Real &rhs); + +Real acsc(const Real &rhs); + Real sinh(const Real &rhs); Real cosh(const Real &rhs); @@ -44,6 +52,10 @@ Real tanh(const Real &rhs); Real coth(const Real &rhs); +Real sech(const Real &rhs); + +Real csch(const Real &rhs); + Real asinh(const Real &rhs); Real acosh(const Real &rhs); @@ -52,6 +64,10 @@ Real atanh(const Real &rhs); Real acoth(const Real &rhs); +Real asech(const Real &rhs); + +Real acsch(const Real &rhs); + Real getE(); Real getPi(); diff --git a/src/fintamath/numbers/RealFunctions.cpp b/src/fintamath/numbers/RealFunctions.cpp index 5b669f99d..4b1116377 100644 --- a/src/fintamath/numbers/RealFunctions.cpp +++ b/src/fintamath/numbers/RealFunctions.cpp @@ -90,6 +90,19 @@ Real cot(const Real &rhs) { } } +Real sec(const Real &rhs) { + return 1 / cos(rhs); +} + +Real csc(const Real &rhs) { + try { + return 1 / sin(rhs); + } + catch (const UndefinedException &) { + throw UndefinedFunctionException("csc", {rhs.toString()}); + } +} + Real asin(const Real &rhs) { cpp_dec_float_100 res = asin(rhs.getBackend()); @@ -123,6 +136,24 @@ Real acot(const Real &rhs) { } } +Real asec(const Real &rhs) { + try { + return acos(1 / rhs); + } + catch (const UndefinedException &) { + throw UndefinedFunctionException("asec", {rhs.toString()}); + } +} + +Real acsc(const Real &rhs) { + try { + return asin(1 / rhs); + } + catch (const UndefinedException &) { + throw UndefinedFunctionException("acsc", {rhs.toString()}); + } +} + Real sinh(const Real &rhs) { return {sinh(rhs.getBackend())}; } @@ -144,6 +175,24 @@ Real coth(const Real &rhs) { } } +Real sech(const Real &rhs) { + try { + return 1 / cosh(rhs); + } + catch (const UndefinedException &) { + throw UndefinedFunctionException("sech", {rhs.toString()}); + } +} + +Real csch(const Real &rhs) { + try { + return 1 / sinh(rhs); + } + catch (const UndefinedException &) { + throw UndefinedFunctionException("csch", {rhs.toString()}); + } +} + Real asinh(const Real &rhs) { return boost::math::asinh(rhs.getBackend()); } @@ -178,6 +227,24 @@ Real acoth(const Real &rhs) { } } +Real asech(const Real &rhs) { + try { + return acosh(1 / rhs); + } + catch (const UndefinedException &) { + throw UndefinedFunctionException("asech", {rhs.toString()}); + } +} + +Real acsch(const Real &rhs) { + try { + return asinh(1 / rhs); + } + catch (const UndefinedException &) { + throw UndefinedFunctionException("acsch", {rhs.toString()}); + } +} + Real getE() { using boost::multiprecision::default_ops::get_constant_e; return {cpp_dec_float_100(get_constant_e())}; diff --git a/tests/src/numbers/RealFunctionsTests.cpp b/tests/src/numbers/RealFunctionsTests.cpp index 5e68656f5..195d71d0f 100644 --- a/tests/src/numbers/RealFunctionsTests.cpp +++ b/tests/src/numbers/RealFunctionsTests.cpp @@ -134,6 +134,29 @@ TEST(RealFunctionsTests, cotTest) { EXPECT_THROW(cot(Real("0")), UndefinedFunctionException); } +TEST(RealFunctionsTests, secTest) { + EXPECT_EQ(sec(Real("0")).toString(), "1.0"); + EXPECT_EQ(sec(Real("1")).toString(), + "1.8508157176809256179117532413986501934703966550940092988351582778588154112615967"); + EXPECT_EQ(sec(Real("1.6")).toString(), + "-34.247135610018689205295461483291306219436082882081545055042205706353264742234617"); + EXPECT_EQ(sec(Real("125")).toString(), + "1.2694954638805676703376706923632363680417203139865889801435769773818587224340106"); +} + +TEST(RealFunctionsTests, cscTest) { + EXPECT_EQ(csc(Real("1")).toString(), + "1.1883951057781212162615994523745510035278298340979626252652536663591843673571905"); + EXPECT_EQ(csc(Real("-1")).toString(), + "-1.1883951057781212162615994523745510035278298340979626252652536663591843673571905"); + EXPECT_EQ(csc(Real("3.2")).toString(), + "-17.130872356878680929063816308707772644748981698069414677586948372772984323565408"); + EXPECT_EQ(csc(Real("360")).toString(), + "1.0428445123825993746264366840754767090833603173462451344005105419339646525772189"); + + EXPECT_THROW(csc(Real("0")), UndefinedFunctionException); +} + TEST(RealFunctionsTests, asinTest) { EXPECT_EQ(asin(Real("0")).toString(), "0.0"); EXPECT_EQ(