mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Power: implement (±inf)^x
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <poincare/constant.h>
|
||||
#include <poincare/cosine.h>
|
||||
#include <poincare/division.h>
|
||||
#include <poincare/infinity.h>
|
||||
#include <poincare/nth_root.h>
|
||||
#include <poincare/opposite.h>
|
||||
#include <poincare/parenthesis.h>
|
||||
@@ -386,6 +387,29 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU
|
||||
return result.shallowReduce(context, angleUnit);
|
||||
}
|
||||
}
|
||||
|
||||
// (±inf)^x
|
||||
if (childAtIndex(0).type() == ExpressionNode::Type::Infinity) {
|
||||
Expression result;
|
||||
if (childAtIndex(1).sign() == ExpressionNode::Sign::Negative) {
|
||||
// --> 0 if x < 0
|
||||
result = Rational(0);
|
||||
} else if (childAtIndex(1).sign() == ExpressionNode::Sign::Positive) {
|
||||
// --> (±inf) if x > 0
|
||||
result = Infinity(false);
|
||||
if (childAtIndex(0).sign() == ExpressionNode::Sign::Negative) {
|
||||
// (-inf)^x --> (-1)^x*inf
|
||||
Power p(Rational(-1), childAtIndex(1));
|
||||
result = Multiplication(p, result);
|
||||
p.shallowReduce(context, angleUnit);
|
||||
}
|
||||
}
|
||||
if (!result.isUninitialized()) {
|
||||
replaceWithInPlace(result);
|
||||
return result.shallowReduce(context, angleUnit);
|
||||
}
|
||||
}
|
||||
|
||||
bool letPowerAtRoot = parentIsALogarithmOfSameBase();
|
||||
if (childAtIndex(0).type() == ExpressionNode::Type::Rational) {
|
||||
Rational a = childAtIndex(0).convert<Rational>();
|
||||
|
||||
@@ -17,10 +17,22 @@ QUIZ_CASE(poincare_infinity) {
|
||||
assert_parsed_expression_simplify_to("0/inf", "0");
|
||||
assert_parsed_expression_simplify_to("inf/0", Undefined::Name());
|
||||
assert_parsed_expression_simplify_to("0*inf", Undefined::Name());
|
||||
assert_parsed_expression_simplify_to("3*inf/inf", "inf/inf"); //TODO undef would be better
|
||||
assert_parsed_expression_simplify_to("3*inf/inf", "undef");
|
||||
assert_parsed_expression_simplify_to("1E1000", "inf");
|
||||
assert_parsed_expression_simplify_to("-1E1000", "-inf");
|
||||
assert_parsed_expression_simplify_to("-1E-1000", "0");
|
||||
assert_parsed_expression_simplify_to("1E-1000", "0");
|
||||
assert_parsed_expression_evaluates_to<double>("1*10^1000", "inf");
|
||||
|
||||
assert_parsed_expression_simplify_to("inf^(-1)", "0");
|
||||
assert_parsed_expression_simplify_to("(-inf)^(-1)", "0");
|
||||
assert_parsed_expression_simplify_to("inf^(-R(2))", "0");
|
||||
assert_parsed_expression_simplify_to("(-inf)^(-R(2))", "0");
|
||||
assert_parsed_expression_simplify_to("inf^2", "inf");
|
||||
assert_parsed_expression_simplify_to("(-inf)^2", "inf");
|
||||
assert_parsed_expression_simplify_to("inf^R(2)", "inf");
|
||||
assert_parsed_expression_simplify_to("(-inf)^R(2)", "inf*(-1)^R(2)");
|
||||
assert_parsed_expression_simplify_to("inf^x", "inf^x");
|
||||
assert_parsed_expression_simplify_to("1/inf+24", "24");
|
||||
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ QUIZ_CASE(poincare_rational_simplify) {
|
||||
assert_parsed_expression_simplify_to(buffer, buffer);
|
||||
// 1/OverflowedIntegerString()
|
||||
strlcpy(buffer+2, BigOverflowedIntegerString(), 400-2);
|
||||
assert_parsed_expression_simplify_to(buffer, "1/inf");
|
||||
assert_parsed_expression_simplify_to(buffer, "0");
|
||||
// MaxIntegerString()
|
||||
assert_parsed_expression_simplify_to(MaxIntegerString(), MaxIntegerString());
|
||||
// OverflowedIntegerString()
|
||||
|
||||
Reference in New Issue
Block a user