#include #include #include #include #include #include #include #include #include namespace Poincare { Layout CeilingNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return CeilingLayout(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits)); } int CeilingNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } template Complex CeilingNode::computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit) { if (c.imag() != 0) { return Complex::Undefined(); } return Complex(std::ceil(c.real())); } Expression CeilingNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { return Ceiling(this).shallowReduce(context, angleUnit); } Ceiling::Ceiling() : Expression(TreePool::sharedPool()->createTreeNode()) {} Expression Ceiling::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { { Expression e = Expression::defaultShallowReduce(context, angleUnit); if (e.isUndefined()) { return e; } } Expression c = childAtIndex(0); #if MATRIX_EXACT_REDUCING if (c.type() == ExpressionNode::Type::Matrix) { return SimplificationHelper::Map(*this, context, angleUnit); } #endif if (c.type() == ExpressionNode::Type::Symbol) { Symbol s = static_cast(c); Expression result; if (s.name() == Ion::Charset::SmallPi) { result = Rational(4); } if (s.name() == Ion::Charset::Exponential) { result = Rational(3); } if (!result.isUninitialized()) { replaceWithInPlace(result); return result; } return *this; } if (c.type() != ExpressionNode::Type::Rational) { return *this; } Rational r = c.convert(); IntegerDivision div = Integer::Division(r.signedIntegerNumerator(), r.integerDenominator()); assert(!div.remainder.isInfinity()); if (div.remainder.isZero()) { Expression result = Rational(div.quotient); replaceWithInPlace(result); return result; } Integer result = Integer::Addition(div.quotient, Integer(1)); if (result.isInfinity()) { return *this; } Expression rationalResult = Rational(result); replaceWithInPlace(rationalResult); return rationalResult; } }