From e2d86aa685685a03e8ab2b2bddebb4d3db17e7f7 Mon Sep 17 00:00:00 2001 From: Shaun Moss Date: Wed, 26 Oct 2022 17:06:09 +1000 Subject: [PATCH] Added hyperbolic trig functions, which were needed for my DecimalComplex class. --- .gitignore | 4 ++++ DecimalEx/DecimalEx.cs | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/.gitignore b/.gitignore index b248083..c004aef 100644 --- a/.gitignore +++ b/.gitignore @@ -347,3 +347,7 @@ healthchecksdb # Backup folder for Package Reference Convert tool in Visual Studio 2017 MigrationBackup/ + +# JetBrains settings +.idea + diff --git a/DecimalEx/DecimalEx.cs b/DecimalEx/DecimalEx.cs index 9adaa65..30b0cd7 100644 --- a/DecimalEx/DecimalEx.cs +++ b/DecimalEx/DecimalEx.cs @@ -629,5 +629,31 @@ public static decimal Remainder(decimal d1, decimal d2) return d1; } + + /// + /// Hyperbolic sine. + /// + /// The hyperbolic angle. + /// The hyperbolic sine of the given angle. + public static decimal Sinh(decimal x) => (Exp(x) - Exp(-x)) / 2; + + /// + /// Hyperbolic cosine. + /// + /// The hyperbolic angle. + /// The hyperbolic cosine of the given angle. + public static decimal Cosh(decimal x) => (Exp(x) + Exp(-x)) / 2; + + /// + /// Hyperbolic tangent. + /// + /// The hyperbolic angle. + /// The hyperbolic tangent of the given angle. + public static decimal Tanh(decimal x) + { + decimal a = Exp(x); + decimal b = Exp(-x); + return (a - b) / (a + b); + } } }