Skip to content

Commit 43fbfb2

Browse files
Tan bug fixed (#570)
So basically, before that `tan` checked if the angle is divided by `pi / 2`. If yes, it should be zero. But it misses a condition: it also should not be integer. Basically, whenever you get `pi / 2` as a modulo of dividing the angle by `pi`, then `tan` turns into NaN. Whereas it just checked dividing by `pi / 2` and did not care about case when `angle` is `pi` or any integer by `pi`. Issue #568
1 parent 2accea2 commit 43fbfb2

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

Sources/AngouriMath/AngouriMath/Functions/Evaluation/Evaluation.Continuous/Evaluation.Continuous.Trigonometry.Classes.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ internal static bool IsCosDefinitelyZero(Entity angle)
2525
// is it of the form n / m * pi?
2626
&& MathS.UnsafeAndInternal.DivideByEntityStrict(angle, MathS.pi)?.Evaled is Rational angleRat
2727

28-
// if n / m is integer, it is definitely 0
29-
&& angleRat % TrigonometricAngleExpansion.OneHalf == 0;
28+
// if n / m is integer + 1/2
29+
30+
// if it's divided by 1/2
31+
&& angleRat % TrigonometricAngleExpansion.OneHalf == 0
32+
33+
// but is not integer
34+
&& angleRat is not Integer;
3035
}
3136

3237
partial record Entity

Sources/Tests/UnitTests/PatternsTest/TrigTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ public void SymbolicCosineFormTest(string angle)
255255
.ShouldBeNotNull()
256256
.ShouldApproximatelyEqual(MathS.Cos(angle))
257257
);
258+
259+
[Fact]
260+
public void TestTan1() => "tan(pi)".ToEntity().InnerSimplified.ShouldBe(0);
261+
262+
[Fact]
263+
public void TestTan2() => "tan(pi / 1)".ToEntity().InnerSimplified.ShouldBe(0);
258264
}
259265
}
260266

0 commit comments

Comments
 (0)