diff --git a/MathTrigonometric.Tests/MathTrigTests.ComplexNumbers.cs b/MathTrigonometric.Tests/MathTrigTests.ComplexNumbers.cs index 20ccf12..b6c3731 100644 --- a/MathTrigonometric.Tests/MathTrigTests.ComplexNumbers.cs +++ b/MathTrigonometric.Tests/MathTrigTests.ComplexNumbers.cs @@ -2,6 +2,7 @@ namespace MathTrigonometric.Tests; +// ReSharper disable once InconsistentNaming public partial class MathTrigTests { [Theory] @@ -21,6 +22,12 @@ public partial class MathTrigTests [InlineData(Math.PI, 0d, 1.2246467991473532E-16d, 0d)] [InlineData(double.PositiveInfinity, 0d, double.NaN, double.NaN)] [InlineData(double.NegativeInfinity, 0d, double.NaN, double.NaN)] + [InlineData(double.PositiveInfinity, 2d, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, 2d, double.NaN, double.NaN)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, double.PositiveInfinity, double.NegativeInfinity)] + [InlineData(2d, double.NegativeInfinity, double.PositiveInfinity, double.PositiveInfinity)] [InlineData(2d, 3d, 9.15449914691143d, -4.168906959966565d)] [InlineData(2d, -3d, 9.15449914691143d, 4.168906959966565d)] [InlineData(-2d, 3d, -9.15449914691143d, -4.168906959966565d)] @@ -52,6 +59,12 @@ public void MathTrig_SinComplexNumbers_ExpectedValue(double a, double b, double [InlineData(Math.PI, 0d, -1d)] [InlineData(double.PositiveInfinity, 0d, double.NaN, double.NaN)] [InlineData(double.NegativeInfinity, 0d, double.NaN, double.NaN)] + [InlineData(double.PositiveInfinity, 2d, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, 2d, double.NaN, double.NaN)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, double.NegativeInfinity, double.NegativeInfinity)] + [InlineData(2d, double.NegativeInfinity, double.NegativeInfinity, double.PositiveInfinity)] [InlineData(2d, 3d, -4.189625690968807d, -9.109227893755337d)] [InlineData(2d, -3d, -4.189625690968807d, 9.109227893755337d)] [InlineData(-2d, 3d, -4.189625690968807d, 9.109227893755337d)] @@ -82,6 +95,12 @@ public void MathTrig_CosComplexParam_ExpectedValue(double a, double b, double ex [InlineData(Math.PI, 0d, 1.2246467991473532E-16d / -1d)] [InlineData(double.PositiveInfinity, 0d, double.NaN, double.NaN)] [InlineData(double.NegativeInfinity, 0d, double.NaN, double.NaN)] + [InlineData(double.PositiveInfinity, 2d, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, 2d, double.NaN, double.NaN)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, 0, 1)] + [InlineData(2d, double.NegativeInfinity, 0, -1)] [InlineData(2d, 3d, -0.0037640256415042484, 1.0032386273536098)] [InlineData(2d, -3d, -0.0037640256415042484, -1.0032386273536098)] [InlineData(-2d, 3d, 0.0037640256415042484, 1.0032386273536098)] @@ -113,6 +132,12 @@ public void MathTrig_TanComplexParam_ExpectedValue(double a, double b, double ex [InlineData(-Math.PI - Math.PI / 2, 0d, 1d)] [InlineData(double.PositiveInfinity, 0d, double.NaN, double.NaN)] [InlineData(double.NegativeInfinity, 0d, double.NaN, double.NaN)] + [InlineData(double.PositiveInfinity, 2d, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, 2d, double.NaN, double.NaN)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, 0)] + [InlineData(2d, double.NegativeInfinity, 0)] [InlineData(2d, 3d, 0.09047320975320743, 0.041200986288574125)] [InlineData(2d, -3d, 0.09047320975320743, -0.041200986288574125)] [InlineData(-2d, 3d, -0.09047320975320743, 0.041200986288574125)] @@ -144,6 +169,12 @@ public void MathTrig_CscComplexParam_ExpectedValue(double a, double b, double ex [InlineData(2 * Math.PI, 0d, 1d)] [InlineData(double.PositiveInfinity, 0d, double.NaN, double.NaN)] [InlineData(double.NegativeInfinity, 0d, double.NaN, double.NaN)] + [InlineData(double.PositiveInfinity, 2d, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, 2d, double.NaN, double.NaN)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, 0)] + [InlineData(2d, double.NegativeInfinity, 0)] [InlineData(2d, 3d, -0.041674964411144266, 0.0906111371962376)] [InlineData(2d, -3d, -0.041674964411144266, -0.0906111371962376)] [InlineData(-2d, 3d, -0.041674964411144266, -0.0906111371962376)] @@ -173,6 +204,12 @@ public void MathTrig_SecComplexParam_ExpectedValue(double a, double b, double ex [InlineData(Math.PI, 0d, -1d / 1.2246467991473532E-16d)] [InlineData(double.PositiveInfinity, 0d, double.NaN, double.NaN)] [InlineData(double.NegativeInfinity, 0d, double.NaN, double.NaN)] + [InlineData(double.PositiveInfinity, 2d, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, 2d, double.NaN, double.NaN)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, 0, -1)] + [InlineData(2d, double.NegativeInfinity, 0, 1)] [InlineData(2d, 3d, -0.003739710376336932, -0.9967577965693583)] [InlineData(2d, -3d, -0.003739710376336932, 0.9967577965693583)] [InlineData(-2d, 3d, 0.003739710376336932, -0.9967577965693583)] @@ -193,15 +230,28 @@ public void MathTrig_CotComplexParam_ExpectedValue(double a, double b, double ex [InlineData(0.5d, 0d, 0.52359877559829893d)] //PI / 6 [InlineData(1d, 0d, Math.PI / 2)] [InlineData(2d, 0d, Math.PI / 2, 1.3169578969248166d)] - [InlineData(double.PositiveInfinity, 0d, Math.PI / 2, double.PositiveInfinity)] [InlineData(-0.5d, 0d, -0.52359877559829893d)] //PI / 6 [InlineData(-1d, 0d, -Math.PI / 2, 0d)] [InlineData(-2d, 0d, -Math.PI / 2, 1.3169578969248166d)] + [InlineData(double.PositiveInfinity, 0d, Math.PI / 2, double.PositiveInfinity)] [InlineData(double.NegativeInfinity, 0d, -Math.PI / 2, double.PositiveInfinity)] + [InlineData(double.PositiveInfinity, 2d, Math.PI / 2, double.PositiveInfinity)] + [InlineData(double.NegativeInfinity, 2d, -Math.PI / 2, double.PositiveInfinity)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, 0, double.PositiveInfinity)] + [InlineData(2d, double.NegativeInfinity, 0, double.NegativeInfinity)] +#if NET9_0_OR_GREATER + [InlineData(2d, 3d, 0.5706527843210994, 1.9833870299165355)] + [InlineData(2d, -3d, 0.5706527843210994, -1.9833870299165355)] + [InlineData(-2d, 3d, -0.5706527843210994, 1.9833870299165355)] + [InlineData(-2d, -3d, -0.5706527843210994, -1.9833870299165355)] +#else [InlineData(2d, 3d, 0.5706527843210993, 1.9833870299165357)] [InlineData(2d, -3d, 0.5706527843210993, -1.9833870299165357)] [InlineData(-2d, 3d, -0.5706527843210993, 1.9833870299165357)] [InlineData(-2d, -3d, -0.5706527843210993, -1.9833870299165357)] +#endif public void MathTrig_AsinComplexParam_ExpectedValue(double a, double b, double expectedReal, double expectedImaginary = 0) { var expectedValue = new Complex(expectedReal, expectedImaginary); @@ -218,15 +268,28 @@ public void MathTrig_AsinComplexParam_ExpectedValue(double a, double b, double e [InlineData(0.5d, 0d, 1.0471975511965979d)] //PI / 3 [InlineData(1d, 0d, 0d)] [InlineData(2d, 0d, 0d, 1.3169578969248166d)] - [InlineData(double.PositiveInfinity, 0d, 0d, double.PositiveInfinity)] [InlineData(-0.5d, 0d, Math.PI * 2 / 3)] [InlineData(-1d, 0d, Math.PI)] [InlineData(-2d, 0d, Math.PI, 1.3169578969248166d)] + [InlineData(double.PositiveInfinity, 0d, 0d, double.PositiveInfinity)] [InlineData(double.NegativeInfinity, 0d, Math.PI, double.PositiveInfinity)] + [InlineData(double.PositiveInfinity, 2d, 0d, double.NegativeInfinity)] + [InlineData(double.NegativeInfinity, 2d, Math.PI, double.NegativeInfinity)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, Math.PI / 2, double.NegativeInfinity)] + [InlineData(2d, double.NegativeInfinity, Math.PI / 2, double.PositiveInfinity)] +#if NET9_0_OR_GREATER + [InlineData(2d, 3d, 1.0001435424737972, -1.9833870299165355)] + [InlineData(2d, -3d, 1.0001435424737972, 1.9833870299165355)] + [InlineData(-2d, 3d, 2.141449111115996, -1.9833870299165355)] + [InlineData(-2d, -3d, 2.141449111115996, 1.9833870299165355)] +#else [InlineData(2d, 3d, 1.0001435424737972, -1.9833870299165357)] [InlineData(2d, -3d, 1.0001435424737972, 1.9833870299165357)] [InlineData(-2d, 3d, 2.141449111115996, -1.9833870299165357)] [InlineData(-2d, -3d, 2.141449111115996, 1.9833870299165357)] +#endif public void MathTrig_AcosComplexParam_ExpectedValue(double a, double b, double expectedReal, double expectedImaginary = 0) { var expectedValue = new Complex(expectedReal, expectedImaginary); @@ -243,11 +306,17 @@ public void MathTrig_AcosComplexParam_ExpectedValue(double a, double b, double e [InlineData(0.5d, 0d, 0.46364760900080609d)] [InlineData(1d, 0d, Math.PI / 4)] [InlineData(2d, 0d, 1.1071487177940904d)] - [InlineData(double.PositiveInfinity, 0d, Math.PI / 2)] [InlineData(-0.5d, 0d, -0.46364760900080609d)] [InlineData(-1d, 0d, -Math.PI / 4)] [InlineData(-2d, 0d, -1.1071487177940904d)] + [InlineData(double.PositiveInfinity, 0d, Math.PI / 2)] [InlineData(double.NegativeInfinity, 0d, -Math.PI / 2)] + [InlineData(double.PositiveInfinity, 2d, Math.PI / 2)] + [InlineData(double.NegativeInfinity, 2d, -Math.PI / 2)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, Math.PI / 2)] + [InlineData(2d, double.NegativeInfinity, -Math.PI / 2)] [InlineData(2d, 3d, 1.4099210495965755, 0.22907268296853878)] [InlineData(2d, -3d, 1.4099210495965755, -0.22907268296853878)] [InlineData(-2d, 3d, -1.4099210495965755, 0.22907268296853878)] @@ -270,11 +339,17 @@ public void MathTrig_AtanComplexParam_ExpectedValue(double a, double b, double e [InlineData(0.5d, 0d, Math.PI / 2, 1.3169578969248166d)] [InlineData(1d, 0d, Math.PI / 2)] [InlineData(2d, 0d, 0.52359877559829893d)] //PI / 6 - [InlineData(double.PositiveInfinity, 0d, 0d)] [InlineData(-0.5d, 0d, -Math.PI / 2, 1.3169578969248166d)] [InlineData(-1d, 0d, -Math.PI / 2)] [InlineData(-2d, 0d, -0.52359877559829893d)] //PI / 6 + [InlineData(double.PositiveInfinity, 0d, 0d)] [InlineData(double.NegativeInfinity, 0d, 0d)] + [InlineData(double.PositiveInfinity, 2d, 0d)] + [InlineData(double.NegativeInfinity, 2d, 0d)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, 0)] + [InlineData(2d, double.NegativeInfinity, 0)] [InlineData(2d, 3d, 0.150385604327862, -0.23133469857397337)] [InlineData(2d, -3d, 0.150385604327862, 0.23133469857397337)] [InlineData(-2d, 3d, -0.150385604327862, -0.23133469857397337)] @@ -295,11 +370,17 @@ public void MathTrig_AcscComplexParam_ExpectedValue(double a, double b, double e [InlineData(0.5d, 0d, 0d, 1.3169578969248166d)] [InlineData(1d, 0d, 0d)] [InlineData(2d, 0d, 1.0471975511965979d)] //PI / 3 - [InlineData(double.PositiveInfinity, 0d, Math.PI / 2)] [InlineData(-0.5d, 0d, Math.PI, 1.3169578969248166d)] [InlineData(-1d, 0d, Math.PI)] [InlineData(-2d, 0d, Math.PI * 2 / 3)] + [InlineData(double.PositiveInfinity, 0d, Math.PI / 2)] [InlineData(double.NegativeInfinity, 0d, Math.PI / 2)] + [InlineData(double.PositiveInfinity, 2d, Math.PI / 2)] + [InlineData(double.NegativeInfinity, 2d, Math.PI / 2)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, Math.PI / 2)] + [InlineData(2d, double.NegativeInfinity, Math.PI / 2)] [InlineData(2d, 3d, 1.4204107224670346, 0.23133469857397337)] [InlineData(2d, -3d, 1.4204107224670346, -0.23133469857397337)] [InlineData(-2d, 3d, 1.7211819311227585, 0.23133469857397337)] @@ -323,11 +404,15 @@ public void MathTrig_AsecComplexParam_ExpectedValue(double a, double b, double e [InlineData(0.5d, 0d, 1.1071487177940904d)] [InlineData(1d, 0d, Math.PI / 4)] [InlineData(2d, 0d, 0.46364760900080609d)] - [InlineData(double.PositiveInfinity, 0d, 0d)] [InlineData(-0.5d, 0d, Math.PI - 1.1071487177940904d)] [InlineData(-1d, 0d, Math.PI - Math.PI / 4)] [InlineData(-2d, 0d, Math.PI - 0.46364760900080609d)] + [InlineData(double.PositiveInfinity, 0d, 0d)] [InlineData(double.NegativeInfinity, 0d, Math.PI)] + [InlineData(double.PositiveInfinity, 2d, 0d)] + [InlineData(double.NegativeInfinity, 2d, Math.PI)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] [InlineData(2d, 3d, 0.16087527719832112, -0.22907268296853883)] [InlineData(2d, -3d, 0.16087527719832112, 0.22907268296853883)] [InlineData(-2d, 3d, 2.980717376391472, -0.22907268296853883)] @@ -352,11 +437,17 @@ public void MathTrig_AcotComplexParam_ExpectedValue(double a, double b, double e [InlineData(2d, 0d, 3.6268604078470186d)] [InlineData(10, 0d, 11013.232874703393, 0d)] [InlineData(100, 0d, 1.3440585709080678E+43d, 0d)] - [InlineData(double.PositiveInfinity, 0d, double.PositiveInfinity)] [InlineData(-0.5d, 0d, -0.52109530549374738d)] [InlineData(-1d, 0d, -1.1752011936438014d)] [InlineData(-2d, 0d, -3.6268604078470186d)] + [InlineData(double.PositiveInfinity, 0d, double.PositiveInfinity)] [InlineData(double.NegativeInfinity, 0d, double.NegativeInfinity)] + [InlineData(double.PositiveInfinity, 2d, double.NegativeInfinity, double.PositiveInfinity)] + [InlineData(double.NegativeInfinity, 2d, double.PositiveInfinity, double.PositiveInfinity)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.NegativeInfinity, double.NaN, double.NaN)] [InlineData(2d, 3d, -3.5905645899857794d, 0.5309210862485197d)] [InlineData(2d, -3d, -3.5905645899857794d, -0.5309210862485197d)] [InlineData(-2d, 3d, 3.5905645899857794d, 0.5309210862485197d)] @@ -377,11 +468,17 @@ public void MathTrig_SinhComplexParam_ExpectedValue(double a, double b, double e [InlineData(0.5d, 0d, 1.1276259652063807d)] [InlineData(1d, 0d, 1.5430806348152437d)] [InlineData(2d, 0d, 3.7621956910836314d)] - [InlineData(double.PositiveInfinity, 0d, double.PositiveInfinity)] [InlineData(-0.5d, 0d, 1.1276259652063807d)] [InlineData(-1d, 0d, 1.5430806348152437d)] [InlineData(-2d, 0d, 3.7621956910836314d)] + [InlineData(double.PositiveInfinity, 0d, double.PositiveInfinity)] [InlineData(double.NegativeInfinity, 0d, double.PositiveInfinity)] + [InlineData(double.PositiveInfinity, 2d, double.NegativeInfinity, double.PositiveInfinity)] + [InlineData(double.NegativeInfinity, 2d, double.NegativeInfinity, double.NegativeInfinity)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.NegativeInfinity, double.NaN, double.NaN)] [InlineData(2d, 3d, -3.7245455049153224, 0.5118225699873845)] [InlineData(2d, -3d, -3.7245455049153224, -0.5118225699873845)] [InlineData(-2d, 3d, -3.7245455049153224, -0.5118225699873845)] @@ -402,11 +499,17 @@ public void MathTrig_CoshComplexParam_ExpectedValue(double a, double b, double e [InlineData(0.5d, 0d, 0.46211715726000974d)] [InlineData(1d, 0d, 0.76159415595576485d)] [InlineData(2d, 0d, 0.9640275800758169d)] - [InlineData(double.PositiveInfinity, 0d, 1d)] [InlineData(-0.5d, 0d, -0.46211715726000974d)] [InlineData(-1d, 0d, -0.76159415595576485d)] [InlineData(-2d, 0d, -0.9640275800758169d)] + [InlineData(double.PositiveInfinity, 0d, 1d)] [InlineData(double.NegativeInfinity, 0d, -1d)] + [InlineData(double.PositiveInfinity, 2d, 1d)] + [InlineData(double.NegativeInfinity, 2d, -1d)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.NegativeInfinity, double.NaN, double.NaN)] [InlineData(2d, 3d, 0.9653858790221331, -0.009884375038322494)] [InlineData(2d, -3d, 0.9653858790221331, 0.009884375038322494)] [InlineData(-2d, 3d, -0.9653858790221331, -0.009884375038322494)] @@ -427,11 +530,19 @@ public void MathTrig_TanhComplexParam_ExpectedValue(double a, double b, double e [InlineData(0.5d, 0d, 1 / 0.52109530549374738d)] [InlineData(1d, 0d, 1 / 1.1752011936438014d)] [InlineData(2d, 0d, 1 / 3.6268604078470186d)] - [InlineData(double.PositiveInfinity, 0d, 0d)] [InlineData(-0.5d, 0d, 1 / -0.52109530549374738d)] [InlineData(-1d, 0d, 1 / -1.1752011936438014d)] [InlineData(-2d, 0d, 1 / -3.6268604078470186d)] + [InlineData(double.PositiveInfinity, 0d, 0d)] [InlineData(double.NegativeInfinity, 0d, 0d)] + [InlineData(double.PositiveInfinity, 2d, 0d)] + [InlineData(double.NegativeInfinity, 2d, 0d)] + [InlineData(double.PositiveInfinity, -2d, 0d)] + [InlineData(double.NegativeInfinity, -2d, 0d)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.NegativeInfinity, double.NaN, double.NaN)] [InlineData(2d, 3d, -0.2725486614629402, -0.04030057885689153)] [InlineData(2d, -3d, -0.2725486614629402, 0.04030057885689153)] [InlineData(-2d, 3d, 0.2725486614629402, -0.04030057885689153)] @@ -452,11 +563,19 @@ public void MathTrig_CschComplexParam_ExpectedValue(double a, double b, double e [InlineData(0.5d, 0d, 1 / 1.1276259652063807d)] [InlineData(1d, 0d, 1 / 1.5430806348152437d)] [InlineData(2d, 0d, 1 / 3.7621956910836314d)] - [InlineData(double.PositiveInfinity, 0d, 0d)] [InlineData(-0.5d, 0d, 1 / 1.1276259652063807d)] [InlineData(-1d, 0d, 1 / 1.5430806348152437d)] [InlineData(-2d, 0d, 1 / 3.7621956910836314d)] + [InlineData(double.PositiveInfinity, 0d, 0d)] [InlineData(double.NegativeInfinity, 0d, 0d)] + [InlineData(double.PositiveInfinity, 2d, 0d)] + [InlineData(double.NegativeInfinity, 2d, 0d)] + [InlineData(double.PositiveInfinity, -2d, 0d)] + [InlineData(double.NegativeInfinity, -2d, 0d)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.NegativeInfinity, double.NaN, double.NaN)] [InlineData(2d, 3d, -0.2635129751583893, -0.036211636558768516)] [InlineData(2d, -3d, -0.2635129751583893, 0.036211636558768516)] [InlineData(-2d, 3d, -0.2635129751583893, 0.036211636558768516)] @@ -477,11 +596,17 @@ public void MathTrig_SechComplexParam_ExpectedValue(double a, double b, double e [InlineData(0.5d, 0d, 1 / 0.46211715726000974d)] [InlineData(1d, 0d, 1 / 0.76159415595576485d)] [InlineData(2d, 0d, 1 / 0.9640275800758169d)] - [InlineData(double.PositiveInfinity, 0d, 1d)] [InlineData(-0.5d, 0d, 1 / -0.46211715726000974d)] [InlineData(-1d, 0d, 1 / -0.76159415595576485d)] [InlineData(-2d, 0d, 1 / -0.9640275800758169d)] + [InlineData(double.PositiveInfinity, 0d, 1d)] [InlineData(double.NegativeInfinity, 0d, -1d)] + [InlineData(double.PositiveInfinity, 2d, 1d)] + [InlineData(double.NegativeInfinity, 2d, -1d)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.NegativeInfinity, double.NaN, double.NaN)] [InlineData(2d, 3d, 1.0357466377649955, 0.0106047834703371)] [InlineData(2d, -3d, 1.0357466377649955, -0.0106047834703371)] [InlineData(-2d, 3d, -1.0357466377649955, 0.0106047834703371)] @@ -502,11 +627,22 @@ public void MathTrig_CothComplexParam_ExpectedValue(double a, double b, double e [InlineData(0.5d, 0d, 0.48121182505960347d)] [InlineData(1d, 0d, 0.88137358701954294d)] [InlineData(2d, 0d, 1.4436354751788103d)] - [InlineData(double.PositiveInfinity, 0d, double.PositiveInfinity)] [InlineData(-0.5d, 0d, -0.48121182505960347d)] [InlineData(-1d, 0d, -0.88137358701954294d)] [InlineData(-2d, 0d, -1.4436354751788103d)] + [InlineData(double.PositiveInfinity, 0d, double.PositiveInfinity)] [InlineData(double.NegativeInfinity, 0d, double.NegativeInfinity)] + [InlineData(double.PositiveInfinity, 2d, double.PositiveInfinity)] + [InlineData(double.NegativeInfinity, 2d, double.NegativeInfinity)] +#if NET9_0_OR_GREATER + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.PositiveInfinity, -Math.PI / 4)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NegativeInfinity, Math.PI / 4)] +#else + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] +#endif + [InlineData(2d, double.PositiveInfinity, double.PositiveInfinity, Math.PI / 4)] + [InlineData(2d, double.NegativeInfinity, double.PositiveInfinity, -Math.PI / 4)] [InlineData(double.MinValue, 0d, double.NegativeInfinity)] [InlineData(double.MaxValue, 0d, double.PositiveInfinity)] [InlineData(2d, 3d, 1.9686379257930964, 0.9646585044076028)] @@ -526,20 +662,43 @@ public void MathTrig_AsinhComplexParam_ExpectedValue(double a, double b, double [InlineData(double.NaN, 0d, double.NaN, double.NaN)] [InlineData(0d, 0d, 0d, Math.PI / 2)] [InlineData(double.Epsilon, 0d, 0d, Math.PI / 2)] - [InlineData(0.5d, 0d, 0d, Math.PI / 3)] [InlineData(1d, 0d, 0d)] [InlineData(2d, 0d, 1.3169578969248166d)] - [InlineData(double.PositiveInfinity, 0d, double.PositiveInfinity)] - [InlineData(-0.5d, 0d, 0d, 2.0943951023931957d)] [InlineData(-1d, 0d, 0d, Math.PI)] [InlineData(-2d, 0d, -1.3169578969248164d, Math.PI)] - [InlineData(double.NegativeInfinity, 0d, double.PositiveInfinity)] + [InlineData(double.PositiveInfinity, 0d, double.PositiveInfinity)] + [InlineData(double.NegativeInfinity, 0d, double.PositiveInfinity, double.NaN)] + [InlineData(double.PositiveInfinity, 2d, double.PositiveInfinity, Math.PI / 4)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] //∞−2∞i−∞^2 + [InlineData(2d, double.PositiveInfinity, double.PositiveInfinity, Math.PI / 4)] + [InlineData(2d, double.NegativeInfinity, double.PositiveInfinity, -Math.PI / 4)] [InlineData(double.MinValue, 0d, double.PositiveInfinity)] [InlineData(double.MaxValue, 0d, double.PositiveInfinity)] [InlineData(2d, 3d, 1.9833870299165355, 1.0001435424737972)] [InlineData(2d, -3d, 1.9833870299165355, -1.0001435424737972)] +#if NET9_0_OR_GREATER + [InlineData(0.5d, 0d, -1.1102230246251565E-16, Math.PI / 3)] + [InlineData(-0.5d, 0d, -1.1102230246251565E-16, 2.0943951023931957d)] + [InlineData(-2d, double.PositiveInfinity, double.PositiveInfinity, double.NaN)] + [InlineData(-200d, double.PositiveInfinity, double.PositiveInfinity, double.NaN)] + [InlineData(-2d, double.NegativeInfinity, double.PositiveInfinity, double.NaN)] + [InlineData(-200d, double.NegativeInfinity, double.PositiveInfinity, double.NaN)] + [InlineData(double.NegativeInfinity, 2d, double.PositiveInfinity, double.NaN)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.PositiveInfinity, -Math.PI / 4)] + [InlineData(-2d, 3d, -1.9833870299165357, -2.1414491111159957)] + [InlineData(-2d, -3d, -1.9833870299165357, 2.1414491111159957)] +#else + [InlineData(0.5d, 0d, 0d, Math.PI / 3)] + [InlineData(-0.5d, 0d, 0d, 2.0943951023931957d)] + [InlineData(-2d, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(-200d, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(-2d, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(-200d, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, 2d, double.NaN, double.NaN)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] [InlineData(-2d, 3d, -1.9833870299165355, -2.1414491111159957)] [InlineData(-2d, -3d, -1.9833870299165355, 2.1414491111159957)] +#endif public void MathTrig_AcoshComplexParam_ExpectedValue(double a, double b, double expectedReal, double expectedImaginary = 0) { var expectedValue = new Complex(expectedReal, expectedImaginary); @@ -553,16 +712,26 @@ public void MathTrig_AcoshComplexParam_ExpectedValue(double a, double b, double [InlineData(double.NaN, 0d, double.NaN, double.NaN)] [InlineData(0d, 0d, 0d)] [InlineData(double.Epsilon, 0d, 0d)] - [InlineData(0.5d, 0d, 0.54930614433405489d)] [InlineData(1d, 0d, double.PositiveInfinity)] [InlineData(2d, 0d, 0.5493061443340549, -Math.PI / 2)] - [InlineData(double.PositiveInfinity, 0d, 0d, -Math.PI / 2)] + [InlineData(0.5d, 0d, 0.54930614433405489d)] [InlineData(-0.5d, 0d, -0.54930614433405489d)] [InlineData(-1d, 0d, double.NegativeInfinity)] [InlineData(-2d, 0d, -0.5493061443340549, Math.PI / 2)] + [InlineData(double.PositiveInfinity, 0d, 0d, -Math.PI / 2)] [InlineData(double.NegativeInfinity, 0d, 0d, Math.PI / 2)] + [InlineData(double.PositiveInfinity, 2d, 0d, -Math.PI / 2)] + [InlineData(double.NegativeInfinity, 2d, 0d, Math.PI / 2)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, 0d, Math.PI / 2)] + [InlineData(2d, double.NegativeInfinity, 0d, -Math.PI / 2)] [InlineData(double.MinValue, 0d, 0d, Math.PI / 2)] [InlineData(double.MaxValue, 0d, 0d, -Math.PI / 2)] + [InlineData(-2d, double.PositiveInfinity, 0d, Math.PI / 2)] + [InlineData(-200d, double.PositiveInfinity, 0d, Math.PI / 2)] + [InlineData(-2d, double.NegativeInfinity, 0d, -Math.PI / 2)] + [InlineData(-200d, double.NegativeInfinity, 0d, -Math.PI / 2)] [InlineData(2d, 3d, 0.14694666622552977, 1.3389725222944935)] [InlineData(2d, -3d, 0.14694666622552977, -1.3389725222944935)] [InlineData(-2d, 3d, -0.14694666622552977, 1.3389725222944935)] @@ -584,15 +753,34 @@ public void MathTrig_AtanhComplexParam_ExpectedValue(double a, double b, double [InlineData(0.5d, 0d, 1.4436354751788103d)] [InlineData(1d, 0d, 0.88137358701954294d)] [InlineData(2d, 0d, 0.48121182505960347d)] - [InlineData(double.PositiveInfinity, 0d, 0d)] [InlineData(-0.5d, 0d, -1.4436354751788103d)] [InlineData(-1d, 0d, -0.88137358701954294d)] [InlineData(-2d, 0d, -0.48121182505960347d)] + [InlineData(double.PositiveInfinity, 0d, 0d)] [InlineData(double.NegativeInfinity, 0d, 0d)] + [InlineData(double.PositiveInfinity, 2d, 0d)] + [InlineData(double.NegativeInfinity, 2d, 0d)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, 0d)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, 0d)] + [InlineData(2d, double.PositiveInfinity, 0d)] + [InlineData(2d, double.NegativeInfinity, 0d)] + [InlineData(double.MinValue, 0d, 0d)] + [InlineData(double.MaxValue, 0d, 0d)] + [InlineData(-2d, double.PositiveInfinity, 0d)] + [InlineData(-200d, double.PositiveInfinity, 0d)] + [InlineData(-2d, double.NegativeInfinity, 0d)] + [InlineData(-200d, double.NegativeInfinity, 0d)] +#if NET9_0_OR_GREATER + [InlineData(2d, 3d, 0.15735549884498545, -0.22996290237720785)] + [InlineData(2d, -3d, 0.15735549884498545, 0.22996290237720785)] + [InlineData(-2d, 3d, -0.15735549884498545, -0.22996290237720785)] + [InlineData(-2d, -3d, -0.15735549884498545, 0.22996290237720785)] +#else [InlineData(2d, 3d, 0.15735549884498526, -0.22996290237720785)] [InlineData(2d, -3d, 0.15735549884498526, 0.22996290237720785)] [InlineData(-2d, 3d, -0.15735549884498526, -0.22996290237720785)] [InlineData(-2d, -3d, -0.15735549884498526, 0.22996290237720785)] +#endif public void MathTrig_AcschComplexParam_ExpectedValue(double a, double b, double expectedReal, double expectedImaginary = 0) { var expectedValue = new Complex(expectedReal, expectedImaginary); @@ -609,14 +797,29 @@ public void MathTrig_AcschComplexParam_ExpectedValue(double a, double b, double [InlineData(-double.Epsilon, 0d, double.PositiveInfinity, Math.PI)] [InlineData(0.5d, 0d, 1.3169578969248166d)] [InlineData(1d, 0d, 0d)] - [InlineData(2d, 0d, 0d, Math.PI / 3)] - [InlineData(double.PositiveInfinity, 0d, 0d, Math.PI / 2)] [InlineData(-0.5d, 0d, -1.3169578969248164d, Math.PI)] [InlineData(-1d, 0d, 0d, Math.PI)] +#if NET9_0_OR_GREATER + [InlineData(2d, 0d, -1.1102230246251565E-16, Math.PI / 3)] + [InlineData(-2d, 0d, -1.1102230246251565E-16, 2.0943951023931957d)] //2PI / 3 +#else + [InlineData(2d, 0d, 0d, Math.PI / 3)] [InlineData(-2d, 0d, 0d, 2.0943951023931957d)] //2PI / 3 +#endif + [InlineData(double.PositiveInfinity, 0d, 0d, Math.PI / 2)] [InlineData(double.NegativeInfinity, 0d, 0d, Math.PI / 2)] + [InlineData(double.PositiveInfinity, 2d, 0d, Math.PI / 2)] + [InlineData(double.NegativeInfinity, 2d, 0d, Math.PI / 2)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] //∞−2∞i−∞^2 + [InlineData(2d, double.PositiveInfinity, 0d, -Math.PI / 2)] + [InlineData(2d, double.NegativeInfinity, 0d, Math.PI / 2)] [InlineData(double.MinValue, 0d, 0d, Math.PI / 2)] [InlineData(double.MaxValue, 0d, 0d, Math.PI / 2)] + [InlineData(-2d, double.PositiveInfinity, 0d, -Math.PI / 2)] + [InlineData(-200d, double.PositiveInfinity, 0d, -Math.PI / 2)] + [InlineData(-2d, double.NegativeInfinity, 0d, Math.PI / 2)] + [InlineData(-200d, double.NegativeInfinity, 0d, Math.PI / 2)] [InlineData(2d, 3d, 0.23133469857397337, -1.4204107224670346)] [InlineData(2d, -3d, 0.23133469857397337, 1.4204107224670346)] [InlineData(-2d, 3d, -0.23133469857397346, 1.7211819311227585)] @@ -637,11 +840,23 @@ public void MathTrig_AsechComplexParam_ExpectedValue(double a, double b, double [InlineData(0.5d, 0d, 0.5493061443340549, -Math.PI / 2)] [InlineData(1d, 0d, double.PositiveInfinity)] [InlineData(2d, 0d, 0.54930614433405489d)] - [InlineData(double.PositiveInfinity, 0d, 0d)] [InlineData(-0.5d, 0d, -0.5493061443340549, -Math.PI / 2)] [InlineData(-1d, 0d, double.NegativeInfinity)] [InlineData(-2d, 0d, -0.54930614433405489d)] + [InlineData(double.PositiveInfinity, 0d, 0d)] [InlineData(double.NegativeInfinity, 0d, 0d)] + [InlineData(double.PositiveInfinity, 2d, 0d)] + [InlineData(double.NegativeInfinity, 2d, 0d)] + [InlineData(double.PositiveInfinity, double.NegativeInfinity, double.NaN, double.NaN)] + [InlineData(double.NegativeInfinity, double.PositiveInfinity, double.NaN, double.NaN)] + [InlineData(2d, double.PositiveInfinity, 0d)] + [InlineData(2d, double.NegativeInfinity, 0d)] + [InlineData(double.MinValue, 0d, 0d)] + [InlineData(double.MaxValue, 0d, 0d)] + [InlineData(-2d, double.PositiveInfinity, 0d)] + [InlineData(-200d, double.PositiveInfinity, 0d)] + [InlineData(-2d, double.NegativeInfinity, 0d)] + [InlineData(-200d, double.NegativeInfinity, 0d)] [InlineData(2d, 3d, 0.14694666622552977, -0.23182380450040305)] [InlineData(2d, -3d, 0.14694666622552977, 0.23182380450040305)] [InlineData(-2d, 3d, -0.14694666622552977, -0.23182380450040305)] diff --git a/MathTrigonometric.Tests/MathTrigTests.cs b/MathTrigonometric.Tests/MathTrigTests.cs index c639227..500d321 100644 --- a/MathTrigonometric.Tests/MathTrigTests.cs +++ b/MathTrigonometric.Tests/MathTrigTests.cs @@ -1,5 +1,6 @@ namespace MathTrigonometric.Tests; +// ReSharper disable once InconsistentNaming public partial class MathTrigTests { [Theory] diff --git a/MathTrigonometric.Tests/MathTrigonometric.Tests.csproj b/MathTrigonometric.Tests/MathTrigonometric.Tests.csproj index 280346e..cc33a16 100644 --- a/MathTrigonometric.Tests/MathTrigonometric.Tests.csproj +++ b/MathTrigonometric.Tests/MathTrigonometric.Tests.csproj @@ -1,7 +1,7 @@ - + - net8.0 + net9.0 enable enable diff --git a/MathTrigonometric/MathTrig.cs b/MathTrigonometric/MathTrig.cs index c189644..b2280d7 100644 --- a/MathTrigonometric/MathTrig.cs +++ b/MathTrigonometric/MathTrig.cs @@ -1,6 +1,8 @@ using System; using System.Numerics; +// ReSharper disable InconsistentNaming + namespace MathTrigonometric; /// @@ -23,9 +25,7 @@ public static class MathTrig /// or . /// public static double Sin(double a) - { - return Math.Sin(a); - } + => Math.Sin(a); /// /// Sine of the specific complex number. @@ -54,9 +54,7 @@ public static Complex Sin(Complex z) /// or . /// public static double Cos(double a) - { - return Math.Cos(a); - } + => Math.Cos(a); /// /// Cosine of the specific complex number. @@ -113,20 +111,20 @@ public static Complex Tan(Complex z) // tan z = (sin(2x) / cosh(2y) + i \tanh(2y)) / (1 + cos(2x) / cosh(2y)) // which correctly computes the (tiny) real part and the (normal-sized) imaginary part. - double x2 = 2.0 * z.Real; - double y2 = 2.0 * z.Imaginary; + var x2 = 2.0 * z.Real; + var y2 = 2.0 * z.Imaginary; var sin = Math.Sin(x2); var cos = Math.Cos(x2); - double cosh = Math.Cosh(y2); + var cosh = Math.Cosh(y2); if (Math.Abs(z.Imaginary) <= 4.0) { - double D = cos + cosh; - return new Complex(sin / D, Math.Sinh(y2) / D); + var d = cos + cosh; + return new Complex(sin / d, Math.Sinh(y2) / d); } else { - double D = 1.0 + cos / cosh; - return new Complex(sin / cosh / D, Math.Tanh(y2) / D); + var d = 1.0 + cos / cosh; + return new Complex(sin / cosh / d, Math.Tanh(y2) / d); } } @@ -161,8 +159,9 @@ public static double Csc(double a) public static Complex Csc(Complex z) { var sin = Sin(z); - if (sin == Complex.Zero) - return new Complex(double.NaN, double.NaN); + + if (IsInfinity(sin)) + return Complex.Zero; return Complex.One / sin; } @@ -198,8 +197,9 @@ public static double Sec(double a) public static Complex Sec(Complex z) { var cos = Cos(z); - if (cos == Complex.Zero) - return new Complex(double.NaN, double.NaN); + + if (IsInfinity(cos)) + return Complex.Zero; return Complex.One / cos; } @@ -234,6 +234,15 @@ public static double Cot(double a) /// public static Complex Cot(Complex z) { + if (double.IsInfinity(z.Real) || double.IsNaN(z.Real)) + return new Complex(double.NaN, double.NaN); + + if (double.IsNegativeInfinity(z.Imaginary)) + return Complex.ImaginaryOne; + + if (double.IsPositiveInfinity(z.Imaginary)) + return new Complex(0d, -1d); + var sin = Math.Sin(z.Real); var cos = Math.Cos(z.Real); var coshI = Math.Cosh(z.Imaginary); @@ -256,9 +265,7 @@ public static Complex Cot(Complex z) /// or . /// public static double Asin(double d) - { - return Math.Asin(d); - } + => Math.Asin(d); /// /// Arc sine of the specific complex number. @@ -269,9 +276,7 @@ public static double Asin(double d) /// This method returns NaN if equals NaN. /// public static Complex Asin(Complex z) - { - return Complex.Asin(z); - } + => Complex.Asin(z); /// /// Arc cosine is inverse of the function. @@ -284,9 +289,7 @@ public static Complex Asin(Complex z) /// or . /// public static double Acos(double d) - { - return Math.Acos(d); - } + => Math.Acos(d); /// /// Arc cosine of the specific complex number. @@ -297,9 +300,7 @@ public static double Acos(double d) /// This method returns NaN if equals NaN. /// public static Complex Acos(Complex z) - { - return Complex.Acos(z); - } + => Complex.Acos(z); /// /// Arc tangent is inverse of the function. @@ -313,9 +314,7 @@ public static Complex Acos(Complex z) /// π/2 if equals . /// public static double Atan(double d) - { - return Math.Atan(d); - } + => Math.Atan(d); /// /// Arc tangent of the specific complex number. @@ -327,11 +326,14 @@ public static double Atan(double d) /// public static Complex Atan(Complex z) { - if (IsPositiveInfinity(z)) - return new Complex(Math.PI / 2, 0); - - if (IsNegativeInfinity(z)) - return new Complex(-Math.PI / 2, 0); + //TODO: create an issue for dotnet/runtime to fix Complex.Atan method + if ((double.IsInfinity(z.Real) && !double.IsInfinity(z.Imaginary)) || + (double.IsInfinity(z.Imaginary) && !double.IsInfinity(z.Real))) + { + return IsNegative(z.Real) || IsNegative(z.Imaginary) + ? new Complex(-Math.PI / 2, 0) + : new Complex(Math.PI / 2, 0); + } return Complex.Atan(z); } @@ -348,9 +350,7 @@ public static Complex Atan(Complex z) /// or . /// public static double Acsc(double d) - { - return Math.Asin(1.0 / d); - } + => Math.Asin(1.0 / d); /// /// Arc cosecant of the specific complex number. @@ -361,9 +361,7 @@ public static double Acsc(double d) /// This method returns NaN if equals Zero or NaN. /// public static Complex Acsc(Complex z) - { - return Complex.Asin(Complex.One / z); - } + => Complex.Asin(Complex.One / z); /// /// Arc secant is inverse of the function. @@ -377,9 +375,7 @@ public static Complex Acsc(Complex z) /// or . /// public static double Asec(double d) - { - return Math.Acos(1.0 / d); - } + => Math.Acos(1.0 / d); /// /// Arc secant of the specific complex number. @@ -390,9 +386,7 @@ public static double Asec(double d) /// This method returns NaN if equals Zero or NaN. /// public static Complex Asec(Complex z) - { - return Complex.Acos(Complex.One / z); - } + => Complex.Acos(Complex.One / z); /// /// Arc cotangent is inverse of the > function. @@ -456,9 +450,7 @@ public static Complex Acot(Complex z) /// . /// public static double Sinh(double x) - { - return Math.Sinh(x); - } + => Math.Sinh(x); /// /// Hyperbolic sine of the specific complex number. @@ -470,7 +462,8 @@ public static double Sinh(double x) /// public static Complex Sinh(Complex z) { - if (IsInfinity(z)) + //TODO: create an issue for dotnet/runtime to fix Complex.Sinh method + if (double.IsInfinity(z.Real) && z.Imaginary == 0d) return z; // Use sinh(z) = -i sin(iz) to compute via sin(z). @@ -492,9 +485,7 @@ public static Complex Sinh(Complex z) /// . /// public static double Cosh(double x) - { - return Math.Cosh(x); - } + => Math.Cosh(x); /// /// Hyperbolic cosine of the specific complex number. @@ -506,7 +497,8 @@ public static double Cosh(double x) /// public static Complex Cosh(Complex z) { - if (IsInfinity(z)) + //TODO: create an issue for dotnet/runtime to fix Complex.Cosh method + if (double.IsInfinity(z.Real) && z.Imaginary == 0d) return new Complex(double.PositiveInfinity, 0); // Use cosh(z) = cos(iz) to compute via cos(z). @@ -525,9 +517,7 @@ public static Complex Cosh(Complex z) /// 1 if equals . /// public static double Tanh(double x) - { - return Math.Tanh(x); - } + => Math.Tanh(x); /// /// Hyperbolic tangent of the specific complex number. @@ -575,8 +565,8 @@ public static double Csch(double x) public static Complex Csch(Complex z) { var sin = Sinh(z); - if (sin == Complex.Zero) - return new Complex(double.NaN, double.NaN); + if (double.IsInfinity(sin.Real) && double.IsInfinity(sin.Imaginary)) + return Complex.Zero; return Complex.One / sin; } @@ -609,6 +599,9 @@ public static double Sech(double x) public static Complex Sech(Complex z) { var cos = Cosh(z); + if (double.IsInfinity(cos.Real) && double.IsInfinity(cos.Imaginary)) + return Complex.Zero; + return Complex.One / cos; } @@ -641,10 +634,8 @@ public static double Coth(double x) /// public static Complex Coth(Complex z) { - if (z == Complex.Zero) - return new Complex(double.NaN, double.NaN); - - return Complex.One / Tanh(z); + var tanh = Tanh(z); + return Complex.One / tanh; } #endregion @@ -652,7 +643,8 @@ public static Complex Coth(Complex z) #region Inverse Hyperbolic Trigonometric Functions /// - /// Arc-hyperbolic sine is inverse of the function is defined as Arsinh(x) = ln[x + √(x^2 + 1)]. + /// Arc-hyperbolic sine is inverse of the function is defined as Arsinh(x) = ln[x + √(x^2 + + /// 1)]. /// /// Any real number. /// @@ -686,8 +678,11 @@ public static double Asinh(double x) /// public static Complex Asinh(Complex z) { - if (IsInfinity(z)) - return z; + if (double.IsPositiveInfinity(z.Real) && !double.IsInfinity(z.Imaginary)) + return new Complex(double.PositiveInfinity, 0d); + + if (double.IsNegativeInfinity(z.Real) && !double.IsInfinity(z.Imaginary)) + return new Complex(double.NegativeInfinity, 0d); //the Trigonometric Symmetry is applied: arsinh(−z)=−arsinh(z) if (IsNegative(z.Real)) @@ -697,7 +692,8 @@ public static Complex Asinh(Complex z) } /// - /// Arc-hyperbolic cosine is inverse of the function is defined as Arcosh(x) = ln[x + √(x^2 - 1)]. + /// Arc-hyperbolic cosine is inverse of the function is defined as Arcosh(x) = ln[x + √(x^2 + /// - 1)]. /// /// Value in range: [1, +∞). /// @@ -727,9 +723,12 @@ public static double Acosh(double x) /// public static Complex Acosh(Complex z) { - if (IsInfinity(z)) + if (IsPositiveInfinity(z)) return new Complex(double.PositiveInfinity, 0d); + if (IsNegativeInfinity(z)) + return new Complex(double.PositiveInfinity, double.NaN); + return Complex.Log(z + Complex.Sqrt(z * z - Complex.One)); } @@ -776,12 +775,18 @@ public static Complex Atanh(Complex z) if (z == -Complex.One) return new Complex(double.NegativeInfinity, 0d); - if (IsPositiveInfinity(z)) + if ((double.IsPositiveInfinity(z.Real) && !double.IsInfinity(z.Imaginary)) || + (!double.IsInfinity(z.Real) && double.IsNegativeInfinity(z.Imaginary))) return new Complex(0d, -Math.PI / 2); - if (IsNegativeInfinity(z)) + if ((double.IsNegativeInfinity(z.Real) && !double.IsInfinity(z.Imaginary)) || + (!double.IsInfinity(z.Real) && double.IsPositiveInfinity(z.Imaginary))) return new Complex(0d, Math.PI / 2); + //the Trigonometric Symmetry is applied: artanh(−x)=−artanh(x) + if (IsNegative(z.Real)) + return -Complex.Log((1.0 - z) / (1.0 + z)) / 2.0; + return Complex.Log((1.0 + z) / (1.0 - z)) / 2.0; } @@ -868,9 +873,13 @@ public static Complex Asech(Complex z) if (z == Complex.Zero) return new Complex(double.NaN, double.NaN); - if (IsInfinity(z)) + if ((double.IsInfinity(z.Real) && !double.IsInfinity(z.Imaginary)) || + (!double.IsInfinity(z.Real) && double.IsNegativeInfinity(z.Imaginary))) return new Complex(0d, Math.PI / 2); + if (!double.IsInfinity(z.Real) && double.IsPositiveInfinity(z.Imaginary)) + return new Complex(0d, -Math.PI / 2); + var zz = z * z; if (zz == Complex.Zero) return new Complex(double.PositiveInfinity, IsNegative(z.Real) ? Math.PI : 0d); @@ -917,9 +926,14 @@ public static Complex Acoth(Complex z) if (z == -Complex.One) return new Complex(double.NegativeInfinity, 0d); - if (IsInfinity(z)) + if ((double.IsInfinity(z.Real) && !double.IsInfinity(z.Imaginary)) || + (!double.IsInfinity(z.Real) && double.IsInfinity(z.Imaginary))) return Complex.Zero; + //the Trigonometric Symmetry is applied: arcoth(−x)=−arcoth(x) + if (IsNegative(z.Real)) + return -Complex.Log((z - 1.0) / (z + 1.0)) / 2.0; + return Complex.Log((z + 1.0) / (z - 1.0)) / 2.0; } @@ -931,9 +945,7 @@ public static Complex Acoth(Complex z) /// Angle in degrees (any real number). /// Angle in radians (any real number). public static double DegreesToRadians(double degrees) - { - return degrees * Math.PI / 180.0; - } + => degrees * Math.PI / 180.0; /// /// Converts radians to degrees. @@ -941,27 +953,17 @@ public static double DegreesToRadians(double degrees) /// Angle in radians (any real number). /// Angle in degrees (any real number). public static double RadiansToDegrees(double radians) - { - return radians * 180.0 / Math.PI; - } + => radians * 180.0 / Math.PI; private static bool IsNegative(double d) - { - return BitConverter.DoubleToInt64Bits(d) < 0; - } + => BitConverter.DoubleToInt64Bits(d) < 0; private static bool IsNegativeInfinity(Complex value) - { - return (value.Imaginary == 0.0) && double.IsNegativeInfinity(value.Real); - } + => value.Imaginary == 0.0 && double.IsNegativeInfinity(value.Real); private static bool IsPositiveInfinity(Complex value) - { - return (value.Imaginary == 0.0) && double.IsPositiveInfinity(value.Real); - } + => value.Imaginary == 0.0 && double.IsPositiveInfinity(value.Real); private static bool IsInfinity(Complex value) - { - return (value.Imaginary == 0.0) && double.IsInfinity(value.Real); - } + => double.IsInfinity(value.Real) || double.IsInfinity(value.Imaginary); } \ No newline at end of file diff --git a/MathTrigonometric/MathTrigonometric.csproj b/MathTrigonometric/MathTrigonometric.csproj index 480466d..01b1ee6 100644 --- a/MathTrigonometric/MathTrigonometric.csproj +++ b/MathTrigonometric/MathTrigonometric.csproj @@ -17,7 +17,7 @@ math; trigonometric; trigonometry; cot; sec; csc; acot; asec; acsc; coth; sech; csch; acoth; asech; acsch; It targets .NET Standard 2.0 and higher version. Supports double and complex numbers. LICENSE - 1.1.0 + 1.2.0