[poincare] Expression::CreateComplexExpression: fix crash when creating

Polar form
This commit is contained in:
Émilie Feral
2019-11-26 10:17:36 +01:00
committed by LeaNumworks
parent 4c11e73ad3
commit 984d1ff924
2 changed files with 8 additions and 2 deletions

View File

@@ -856,8 +856,13 @@ Expression Expression::CreateComplexExpression(Expression ra, Expression tb, Pre
Expression norm;
Expression exp;
if (!isOneRa || isZeroTb) {
assert(!isNegativeRa); // norm cannot be negative
norm = ra;
/* Norm cannot be negative but can be preceded by a negative sign (for
* instance "-log(0.3)") which would lead to isNegativeRa = True. */
if (isNegativeRa) {
norm = Opposite::Builder(ra);
} else {
norm = ra;
}
}
if (!isZeroRa && !isZeroTb) {
Expression arg;

View File

@@ -941,6 +941,7 @@ QUIZ_CASE(poincare_simplification_complex_format) {
assert_parsed_expression_simplify_to("[[1,√(-1)]]", "[[1,^\u0012π/2×𝐢\u0013]]", User, Radian, Polar);
assert_parsed_expression_simplify_to("atan(2)", "atan(2)", User, Radian, Polar);
assert_parsed_expression_simplify_to("atan(-2)", "atan(2)×^\u0012π×𝐢\u0013", User, Radian, Polar);
assert_parsed_expression_simplify_to("cos(42π)", "-cos(42×π)×^\x12π×𝐢\x13", User, Degree, Polar);
// User defined variable
assert_parsed_expression_simplify_to("a", "a", User, Radian, Polar);