|
| 1 | +// |
| 2 | +// Copyright (c) 2019-2026 Angouri. |
| 3 | +// AngouriMath is licensed under MIT. |
| 4 | +// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. |
| 5 | +// Website: https://am.angouri.org. |
| 6 | +// |
| 7 | + |
| 8 | +using System.Numerics; |
| 9 | +using AngouriMath; |
| 10 | +using AngouriMath.Extensions; |
| 11 | +using Xunit; |
| 12 | + |
| 13 | +namespace AngouriMath.Tests.Convenience |
| 14 | +{ |
| 15 | + /// <summary> |
| 16 | + /// <c>arcsin</c> and <c>arccos</c> of a real number past 1 have their value, <c>sign(x) pi/2 - i arccosh|x|</c> and |
| 17 | + /// <c>pi/2 - arcsin(x)</c>, where for one argument in ten they were NaN: the rounded <c>(|w + 1| - |w - 1|) / 2</c> |
| 18 | + /// came out a little past 1, whose decimal arcsine is NaN. <c>arcsin(6 + pi)</c> was one. |
| 19 | + /// <a href="https://github.com/asc-community/AngouriMath/issues/2244">#2244</a> |
| 20 | + /// </summary> |
| 21 | + [Trait("Area", "Convenience")] |
| 22 | + public sealed class ArcsineOfARealPastOneTest |
| 23 | + { |
| 24 | + private static double Arccosh(double x) => System.Math.Log(x + System.Math.Sqrt(x * x - 1)); |
| 25 | + |
| 26 | + private static bool Agree(Complex expected, Complex actual) => Complex.Abs(expected - actual) <= 1e-12 * System.Math.Max(1, Complex.Abs(expected)); |
| 27 | + |
| 28 | + [Theory] |
| 29 | + [InlineData("pi")] |
| 30 | + [InlineData("e")] |
| 31 | + [InlineData("sqrt(2)")] |
| 32 | + [InlineData("sqrt(3)")] |
| 33 | + [InlineData("ln(3)")] |
| 34 | + public void BothHaveTheirValue(string constant) |
| 35 | + { |
| 36 | + for (var k = 1; k <= 40; k++) |
| 37 | + foreach (var sign in new[] { "", "-" }) |
| 38 | + { |
| 39 | + var argument = $"{sign}({k} + {constant})"; |
| 40 | + var x = ((Entity.Number.Complex)argument.ToEntity().Evaled).ToNumerics().Real; |
| 41 | + if (System.Math.Abs(x) <= 1) |
| 42 | + continue; |
| 43 | + var arcsin = ((Entity.Number.Complex)$"arcsin({argument})".ToEntity().Evaled).ToNumerics(); |
| 44 | + var arccos = ((Entity.Number.Complex)$"arccos({argument})".ToEntity().Evaled).ToNumerics(); |
| 45 | + var expectedArcsin = new Complex(System.Math.Sign(x) * System.Math.PI / 2, -Arccosh(System.Math.Abs(x))); |
| 46 | + var expectedArccos = new Complex(x > 0 ? 0 : System.Math.PI, Arccosh(System.Math.Abs(x))); |
| 47 | + Assert.True(Agree(expectedArcsin, arcsin), $"arcsin({argument}): {arcsin}, where {expectedArcsin}"); |
| 48 | + Assert.True(Agree(expectedArccos, arccos), $"arccos({argument}): {arccos}, where {expectedArccos}"); |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments