mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-25 16:50:50 +01:00
[poincare] Turn i into unreal when complexFormat is Real
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <poincare/layout_helper.h>
|
||||
#include <poincare/complex_cartesian.h>
|
||||
#include <poincare/rational.h>
|
||||
#include <poincare/unreal.h>
|
||||
#include <ion.h>
|
||||
#include <cmath>
|
||||
#include <assert.h>
|
||||
@@ -54,10 +55,15 @@ Constant::Constant(char name) : SymbolAbstract(TreePool::sharedPool()->createTre
|
||||
}
|
||||
|
||||
Expression Constant::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) {
|
||||
if (target == ExpressionNode::ReductionTarget::User && isIComplex()) {
|
||||
ComplexCartesian c = ComplexCartesian::Builder(Rational(0), Rational(1));
|
||||
replaceWithInPlace(c);
|
||||
return c;
|
||||
Expression result;
|
||||
if (complexFormat == Preferences::ComplexFormat::Real && isIComplex()) {
|
||||
result = Unreal();
|
||||
} else if (target == ExpressionNode::ReductionTarget::User && isIComplex()) {
|
||||
result = ComplexCartesian::Builder(Rational(0), Rational(1));
|
||||
}
|
||||
if (!result.isUninitialized()) {
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Poincare {
|
||||
double NumberNode::doubleApproximation() const {
|
||||
switch (type()) {
|
||||
case Type::Undefined:
|
||||
case Type::Unreal:
|
||||
return NAN;
|
||||
case Type::Infinity:
|
||||
return Number(this).sign() == Sign::Negative ? -INFINITY : INFINITY;
|
||||
|
||||
@@ -56,6 +56,7 @@ QUIZ_CASE(poincare_polynomial_degree) {
|
||||
assert_parsed_expression_polynomial_degree("prediction(0.2,10)+1", -1);
|
||||
assert_parsed_expression_polynomial_degree("2-x-x^3", 3);
|
||||
assert_parsed_expression_polynomial_degree("P*x", 1);
|
||||
assert_parsed_expression_polynomial_degree("R(-1)*x", -1, "x", Real);
|
||||
// f: x->x^2+Px+1
|
||||
assert_simplify("1+P*x+x^2>f(x)");
|
||||
assert_parsed_expression_polynomial_degree("f(x)", 2);
|
||||
@@ -157,4 +158,8 @@ QUIZ_CASE(poincare_get_polynomial_coefficients) {
|
||||
const char * coefficient4[] = {"1", "P", "1", 0}; //x^2+Pi*x+1
|
||||
assert_simplify("1+P*x+x^2>f(x)");
|
||||
assert_parsed_expression_has_polynomial_coefficient("f(x)", "x", coefficient4);
|
||||
const char * coefficient5[] = {"0", "I", 0}; //R(-1)x
|
||||
assert_parsed_expression_has_polynomial_coefficient("R(-1)x", "x", coefficient5);
|
||||
const char * coefficient6[] = {0}; //R(-1)x
|
||||
assert_parsed_expression_has_polynomial_coefficient("R(-1)x", "x", coefficient6, Real);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user