#include #include namespace Poincare { template Expression FloatNode::setSign(Sign s, ReductionContext reductionContext) { assert(s == ExpressionNode::Sign::Positive || s == ExpressionNode::Sign::Negative); Sign currentSign = m_value < 0 ? Sign::Negative : Sign::Positive; Expression thisExpr = Number(this); Expression result = Float::Builder(s == currentSign ? m_value : -m_value); thisExpr.replaceWithInPlace(result); return result; } template int FloatNode::simplificationOrderSameType(const ExpressionNode * e, bool ascending, bool canBeInterrupted, bool ignoreParentheses) const { if (!ascending) { return e->simplificationOrderSameType(this, true, canBeInterrupted, ignoreParentheses); } assert((e->type() == ExpressionNode::Type::Float && sizeof(T) == sizeof(float)) || (e->type() == ExpressionNode::Type::Double && sizeof(T) == sizeof(double))); const FloatNode * other = static_cast *>(e); if (value() < other->value()) { return -1; } if (value() > other->value()) { return 1; } return 0; } template int FloatNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return PrintFloat::ConvertFloatToText(m_value, buffer, bufferSize, PrintFloat::k_maxFloatGlyphLength, numberOfSignificantDigits, floatDisplayMode).CharLength; } template Layout FloatNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { char buffer[PrintFloat::k_maxFloatCharSize]; int numberOfChars = serialize(buffer, PrintFloat::k_maxFloatCharSize, floatDisplayMode, numberOfSignificantDigits); return LayoutHelper::String(buffer, numberOfChars); } template Float Float::Builder(T value) { void * bufferNode = TreePool::sharedPool()->alloc(sizeof(FloatNode)); FloatNode * node = new (bufferNode) FloatNode(value); TreeHandle h = TreeHandle::BuildWithGhostChildren(node); return static_cast(h); } template class FloatNode; template class FloatNode; template Float Float::Builder(float value); template Float Float::Builder(double value); }