[poincare] Clean: convertFloatToText should be in PrintFloat instead of

Complex
This commit is contained in:
Émilie Feral
2018-02-14 17:45:06 +01:00
committed by EmilieNumworks
parent d9150d4faa
commit 6de71ae145
118 changed files with 392 additions and 388 deletions

View File

@@ -98,7 +98,7 @@ Expression * Calculation::input() {
ExpressionLayout * Calculation::inputLayout() {
if (m_inputLayout == nullptr && input() != nullptr) {
m_inputLayout = input()->createLayout(Expression::FloatDisplayMode::Decimal, Expression::ComplexFormat::Cartesian);
m_inputLayout = input()->createLayout(PrintFloat::Mode::Decimal, Expression::ComplexFormat::Cartesian);
}
return m_inputLayout;
}

View File

@@ -25,7 +25,7 @@ void GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(Shar
buffer[0] = function->name()[0];
buffer[1] = '\'';
double y = function->approximateDerivative(cursor->x(), app->localContext());
numberOfChar += Complex<double>::convertFloatToText(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits);
numberOfChar += PrintFloat::convertFloatToText<double>(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits);
strlcpy(buffer+numberOfChar, space, spaceLength+1);
buffer[k_maxDigitLegendLength+6] = 0;
bannerView()->setLegendAtIndex(buffer, 2);

View File

@@ -30,7 +30,7 @@ void IntersectionGraphController::reloadBannerView() {
numberOfChar += legendLength;
buffer[0] = m_function->name()[0];
buffer[5] = m_intersectedFunction->name()[0];
numberOfChar += Complex<float>::convertFloatToText(m_cursor->y(), buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
numberOfChar += PrintFloat::convertFloatToText<double>(m_cursor->y(), buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
strlcpy(buffer+numberOfChar, space, spaceLength+1);
buffer[FunctionBannerDelegate::k_maxDigitLegendLength+legendLength] = 0;
bannerView()->setLegendAtIndex(buffer, 1);

View File

@@ -46,14 +46,14 @@ void TangentGraphController::reloadBannerView() {
int legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
double y = m_function->approximateDerivative(m_cursor->x(), myApp->localContext());
Complex<double>::convertFloatToText(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
PrintFloat::convertFloatToText<double>(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
m_bannerView->setLegendAtIndex(buffer, 4);
legend = "b=";
legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
y = -y*m_cursor->x()+m_function->evaluateAtAbscissa(m_cursor->x(), myApp->localContext());
Complex<double>::convertFloatToText(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
PrintFloat::convertFloatToText<double>(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
m_bannerView->setLegendAtIndex(buffer, 5);
}

View File

@@ -45,7 +45,7 @@ void BatteryTestController::updateBatteryState(float batteryLevel, bool batteryC
const char * legend = "Battery level: ";
int legendLength = strlen(legend);
strlcpy(bufferLevel, legend, legendLength+1);
Complex<float>::convertFloatToText(batteryLevel, bufferLevel+legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
PrintFloat::convertFloatToText<float>(batteryLevel, bufferLevel+legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
m_view.batteryLevelTextView()->setText(bufferLevel);
char bufferCharging[ContentView::k_maxNumberOfCharacters + PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];

View File

@@ -201,7 +201,7 @@ void CalculationController::willDisplayCellAtLocation(HighlightCell * cell, int
return;
}
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
Complex<double>::convertFloatToText(m_calculation->parameterAtIndex(i-1), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
PrintFloat::convertFloatToText<double>(m_calculation->parameterAtIndex(i-1), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, PrintFloat::Mode::Decimal);
field->setText(buffer);
}
}
@@ -296,7 +296,7 @@ void CalculationController::updateTitle() {
strlcpy(m_titleBuffer+currentChar, " = ", 4);
currentChar += 3;
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)];
Complex<double>::convertFloatToText(m_law->parameterValueAtIndex(index), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
PrintFloat::convertFloatToText<double>(m_law->parameterValueAtIndex(index), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits, PrintFloat::Mode::Decimal);
strlcpy(m_titleBuffer+currentChar, buffer, strlen(buffer)+1);
currentChar += strlen(buffer);
m_titleBuffer[currentChar++] = ' ';

View File

@@ -149,9 +149,9 @@ void CalculationController::willDisplayCellAtLocation(HighlightCell * cell, int
double calculation2 = (m_store->*calculationMethods[j-1])(1);
EvenOddDoubleBufferTextCell * myCell = (EvenOddDoubleBufferTextCell *)cell;
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
Complex<double>::convertFloatToText(calculation1, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
PrintFloat::convertFloatToText<double>(calculation1, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
myCell->setFirstText(buffer);
Complex<double>::convertFloatToText(calculation2, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
PrintFloat::convertFloatToText<double>(calculation2, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
myCell->setSecondText(buffer);
return;
}
@@ -167,7 +167,7 @@ void CalculationController::willDisplayCellAtLocation(HighlightCell * cell, int
double calculation = (m_store->*calculationMethods[j-k_totalNumberOfDoubleBufferRows-1])();
EvenOddBufferTextCell * myCell = (EvenOddBufferTextCell *)cell;
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
Complex<double>::convertFloatToText(calculation, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
PrintFloat::convertFloatToText<double>(calculation, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
myCell->setText(buffer);
return;
}

View File

@@ -82,7 +82,7 @@ void GraphController::reloadBannerView() {
strlcpy(buffer+numberOfChar, legend, legendLength+1);
numberOfChar += legendLength;
} else {
numberOfChar += Complex<float>::convertFloatToText(std::round((float)*m_selectedDotIndex+1.0f), buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
numberOfChar += PrintFloat::convertFloatToText<float>(std::round((float)*m_selectedDotIndex+1.0f), buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits, PrintFloat::Mode::Decimal);
}
legend = ") ";
legendLength = strlen(legend);
@@ -102,7 +102,7 @@ void GraphController::reloadBannerView() {
legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
numberOfChar += Complex<double>::convertFloatToText(x, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
numberOfChar += PrintFloat::convertFloatToText<double>(x, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
legend = " ";
legendLength = strlen(legend);
strlcpy(buffer+numberOfChar, legend, legendLength+1);
@@ -120,7 +120,7 @@ void GraphController::reloadBannerView() {
legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
numberOfChar += Complex<double>::convertFloatToText(y, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
numberOfChar += PrintFloat::convertFloatToText<double>(y, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
legend = " ";
legendLength = strlen(legend);
strlcpy(buffer+numberOfChar, legend, legendLength+1);
@@ -133,7 +133,7 @@ void GraphController::reloadBannerView() {
legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
numberOfChar += Complex<double>::convertFloatToText(slope, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
numberOfChar += PrintFloat::convertFloatToText<double>(slope, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
legend = " ";
legendLength = strlen(legend);
strlcpy(buffer+numberOfChar, legend, legendLength+1);
@@ -146,7 +146,7 @@ void GraphController::reloadBannerView() {
legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
numberOfChar += Complex<double>::convertFloatToText(yIntercept, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
numberOfChar += PrintFloat::convertFloatToText<double>(yIntercept, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
legend = " ";
legendLength = strlen(legend);
strlcpy(buffer+numberOfChar, legend, legendLength+1);
@@ -159,7 +159,7 @@ void GraphController::reloadBannerView() {
legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
numberOfChar += Complex<double>::convertFloatToText(r, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
numberOfChar += PrintFloat::convertFloatToText<double>(r, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
legend = " ";
legendLength = strlen(legend);
strlcpy(buffer+numberOfChar, legend, legendLength+1);
@@ -172,7 +172,7 @@ void GraphController::reloadBannerView() {
legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
numberOfChar += Complex<double>::convertFloatToText(r2, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
numberOfChar += PrintFloat::convertFloatToText<double>(r2, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
legend = " ";
legendLength = strlen(legend);
strlcpy(buffer+numberOfChar, legend, legendLength+1);

View File

@@ -165,7 +165,7 @@ Poincare::ExpressionLayout * Sequence::firstInitialConditionLayout() {
if (m_firstInitialConditionLayout == nullptr) {
Expression * nonSimplifedExpression = Expression::parse(m_firstInitialConditionText);
if (nonSimplifedExpression) {
m_firstInitialConditionLayout = nonSimplifedExpression->createLayout(Expression::FloatDisplayMode::Decimal);
m_firstInitialConditionLayout = nonSimplifedExpression->createLayout(PrintFloat::Mode::Decimal);
delete nonSimplifedExpression;
}
}
@@ -176,7 +176,7 @@ Poincare::ExpressionLayout * Sequence::secondInitialConditionLayout() {
if (m_secondInitialConditionLayout == nullptr) {
Expression * nonSimplifedExpression = Expression::parse(m_secondInitialConditionText);
if (nonSimplifedExpression) {
m_secondInitialConditionLayout = nonSimplifedExpression->createLayout(Expression::FloatDisplayMode::Decimal);
m_secondInitialConditionLayout = nonSimplifedExpression->createLayout(PrintFloat::Mode::Decimal);
delete nonSimplifedExpression;
}
}

View File

@@ -256,7 +256,7 @@ void SubController::setPreferenceWithValueIndex(I18n::Message message, int value
Preferences::sharedPreferences()->setAngleUnit((Expression::AngleUnit)valueIndex);
}
if (message == I18n::Message::DisplayMode) {
Preferences::sharedPreferences()->setDisplayMode((Expression::FloatDisplayMode)valueIndex);
Preferences::sharedPreferences()->setDisplayMode((PrintFloat::Mode)valueIndex);
}
if (message == I18n::Message::ComplexFormat) {
Preferences::sharedPreferences()->setComplexFormat((Expression::ComplexFormat)valueIndex);

View File

@@ -135,9 +135,9 @@ void CurveView::computeLabels(Axis axis) {
if (labelValue < step && labelValue > -step) {
labelValue = 0.0f;
}
Complex<float>::convertFloatToText(labelValue, buffer,
PrintFloat::convertFloatToText<float>(labelValue, buffer,
PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits),
Constant::ShortNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
Constant::ShortNumberOfSignificantDigits, PrintFloat::Mode::Decimal);
//TODO: check for size of label?
strlcpy(label(axis, index), buffer, strlen(buffer)+1);
}

View File

@@ -62,7 +62,7 @@ KDCoordinate EditableCellTableViewController::rowHeight(int j) {
return k_cellHeight;
}
void EditableCellTableViewController::willDisplayCellAtLocationWithDisplayMode(HighlightCell * cell, int i, int j, Expression::FloatDisplayMode floatDisplayMode) {
void EditableCellTableViewController::willDisplayCellAtLocationWithDisplayMode(HighlightCell * cell, int i, int j, PrintFloat::Mode floatDisplayMode) {
EvenOddCell * myCell = (EvenOddCell *)cell;
/* We set the cell even or odd state only if the cell is not being edited.
* Otherwise, the cell background is white whichever it is an odd or even cell
@@ -85,7 +85,7 @@ void EditableCellTableViewController::willDisplayCellAtLocationWithDisplayMode(H
}
if (!myEditableValueCell->editableTextCell()->textField()->isEditing()) {
myCell->setEven(j%2 == 0);
Complex<double>::convertFloatToText(dataAtLocation(i, j), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, floatDisplayMode);
PrintFloat::convertFloatToText<double>(dataAtLocation(i, j), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, floatDisplayMode);
myEditableValueCell->editableTextCell()->textField()->setText(buffer);
}
return;

View File

@@ -16,7 +16,7 @@ public:
bool textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) override;
int numberOfRows() override;
void willDisplayCellAtLocationWithDisplayMode(HighlightCell * cell, int i, int j, Poincare::Expression::FloatDisplayMode FloatDisplayMode);
void willDisplayCellAtLocationWithDisplayMode(HighlightCell * cell, int i, int j, Poincare::PrintFloat::Mode mode);
KDCoordinate rowHeight(int j) override;
void viewWillAppear() override;
void didBecomeFirstResponder() override;

View File

@@ -106,7 +106,7 @@ void FloatParameterController::willDisplayCellForIndex(HighlightCell * cell, int
return;
}
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
Complex<float>::convertFloatToText(parameterAtIndex(index), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
PrintFloat::convertFloatToText<double>(parameterAtIndex(index), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, PrintFloat::Mode::Decimal);
myCell->setAccessoryText(buffer);
}

View File

@@ -80,7 +80,7 @@ Poincare::ExpressionLayout * Function::layout() {
if (m_layout == nullptr) {
Expression * nonSimplifiedExpression = Expression::parse(m_text);
if (nonSimplifiedExpression != nullptr) {
m_layout = nonSimplifiedExpression->createLayout(Expression::FloatDisplayMode::Decimal);
m_layout = nonSimplifiedExpression->createLayout(PrintFloat::Mode::Decimal);
delete nonSimplifiedExpression;
}
}

View File

@@ -15,7 +15,7 @@ void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
buffer[0] = symbol;
numberOfChar += Complex<float>::convertFloatToText(cursor->x(), buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
numberOfChar += PrintFloat::convertFloatToText<double>(cursor->x(), buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
strlcpy(buffer+numberOfChar, space, spaceLength+1);
buffer[k_maxDigitLegendLength+2] = 0;
bannerView()->setLegendAtIndex(buffer, 0);
@@ -27,7 +27,7 @@ void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor
strlcpy(buffer, legend, legendLength+1);
buffer[2] = symbol;
buffer[0] = function->name()[0];
numberOfChar += Complex<float>::convertFloatToText(cursor->y(), buffer+legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
numberOfChar += PrintFloat::convertFloatToText<double>(cursor->y(), buffer+legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
strlcpy(buffer+numberOfChar, space, spaceLength+1);
buffer[k_maxDigitLegendLength+5] = 0;
bannerView()->setLegendAtIndex(buffer, 1);

View File

@@ -63,7 +63,7 @@ int StoreController::typeAtLocation(int i, int j) {
}
void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {
willDisplayCellAtLocationWithDisplayMode(cell, i, j, Expression::FloatDisplayMode::Decimal);
willDisplayCellAtLocationWithDisplayMode(cell, i, j, PrintFloat::Mode::Decimal);
}
void StoreController::didBecomeFirstResponder() {

View File

@@ -158,7 +158,7 @@ bool SumGraphController::textFieldDidAbortEditing(TextField * textField, const c
default:
assert(false);
}
Complex<double>::convertFloatToText(parameter, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
PrintFloat::convertFloatToText<double>(parameter, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits, PrintFloat::Mode::Decimal);
textField->setText(buffer);
return true;
}
@@ -233,7 +233,7 @@ void SumGraphController::LegendView::setLegendMessage(I18n::Message message, Ste
void SumGraphController::LegendView::setEditableZone(double d) {
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits)];
Complex<double>::convertFloatToText(d, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
PrintFloat::convertFloatToText<double>(d, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits, PrintFloat::Mode::Decimal);
m_editableZone.setText(buffer);
}
@@ -248,19 +248,19 @@ void SumGraphController::LegendView::setSumSymbol(Step step, double start, doubl
m_sumLayout = new StringLayout(sigma, sizeof(sigma));
} else if (step == Step::SecondParameter) {
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits)];
Complex<double>::convertFloatToText(start, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
PrintFloat::convertFloatToText<double>(start, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits, PrintFloat::Mode::Decimal);
m_sumLayout = new CondensedSumLayout(new StringLayout(sigma, sizeof(sigma)), new StringLayout(buffer, strlen(buffer), KDText::FontSize::Small), nullptr);
} else {
char buffer[2+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
Complex<double>::convertFloatToText(start, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
PrintFloat::convertFloatToText<double>(start, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, PrintFloat::Mode::Decimal);
ExpressionLayout * start = new StringLayout(buffer, strlen(buffer), KDText::FontSize::Small);
Complex<double>::convertFloatToText(end, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
PrintFloat::convertFloatToText<double>(end, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, PrintFloat::Mode::Decimal);
ExpressionLayout * end = new StringLayout(buffer, strlen(buffer), KDText::FontSize::Small);
m_sumLayout = new CondensedSumLayout(new StringLayout(sigma, sizeof(sigma)), start, end);
ExpressionLayout * childrenLayouts[3];
strlcpy(buffer, "= ", 3);
Complex<double>::convertFloatToText(result, buffer+2, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
PrintFloat::convertFloatToText<double>(result, buffer+2, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
childrenLayouts[2] = new StringLayout(buffer, strlen(buffer), KDText::FontSize::Small);
childrenLayouts[1] = functionLayout;
childrenLayouts[0] = m_sumLayout;

View File

@@ -123,7 +123,7 @@ Button * ValuesController::buttonAtIndex(int index, ButtonRowController::Positio
}
void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {
willDisplayCellAtLocationWithDisplayMode(cell, i, j, Expression::FloatDisplayMode::Default);
willDisplayCellAtLocationWithDisplayMode(cell, i, j, PrintFloat::Mode::Default);
if (cellAtLocationIsEditable(i, j)) {
return;
}
@@ -143,7 +143,7 @@ void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, in
// The cell is a value cell
EvenOddBufferTextCell * myValueCell = (EvenOddBufferTextCell *)cell;
double x = m_interval->element(j-1);
Complex<double>::convertFloatToText(evaluationOfAbscissaAtColumn(x, i), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
PrintFloat::convertFloatToText<double>(evaluationOfAbscissaAtColumn(x, i), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
myValueCell->setText(buffer);
}
}

View File

@@ -71,7 +71,7 @@ void BoxController::reloadBannerView() {
CalculPointer calculationMethods[5] = {&Store::minValue, &Store::firstQuartile, &Store::median, &Store::thirdQuartile,
&Store::maxValue};
double calculation = (m_store->*calculationMethods[(int)m_view.selectedQuantile()])();
Complex<double>::convertFloatToText(calculation, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
PrintFloat::convertFloatToText<double>(calculation, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
m_boxBannerView.setLegendAtIndex(buffer, 1);
}

View File

@@ -84,7 +84,7 @@ void CalculationController::willDisplayCellAtLocation(HighlightCell * cell, int
double calculation = (m_store->*calculationMethods[j])();
EvenOddBufferTextCell * myCell = (EvenOddBufferTextCell *)cell;
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
Complex<double>::convertFloatToText(calculation, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
PrintFloat::convertFloatToText<double>(calculation, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
myCell->setText(buffer);
}
}

View File

@@ -157,10 +157,10 @@ void HistogramController::reloadBannerView() {
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
double lowerBound = m_store->startOfBarAtIndex(*m_selectedBarIndex);
numberOfChar += Complex<double>::convertFloatToText(lowerBound, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
numberOfChar += PrintFloat::convertFloatToText<double>(lowerBound, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
buffer[numberOfChar++] = ';';
double upperBound = m_store->endOfBarAtIndex(*m_selectedBarIndex);
numberOfChar += Complex<double>::convertFloatToText(upperBound, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
numberOfChar += PrintFloat::convertFloatToText<double>(upperBound, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
buffer[numberOfChar++] = '[';
legend = " ";
legendLength = strlen(legend);
@@ -174,7 +174,7 @@ void HistogramController::reloadBannerView() {
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
double size = m_store->heightOfBarAtIndex(*m_selectedBarIndex);
numberOfChar += Complex<double>::convertFloatToText(size, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
numberOfChar += PrintFloat::convertFloatToText<double>(size, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
legend = " ";
legendLength = strlen(legend);
strlcpy(buffer+numberOfChar, legend, legendLength+1);
@@ -187,7 +187,7 @@ void HistogramController::reloadBannerView() {
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
double frequency = size/m_store->sumOfColumn(1);
numberOfChar += Complex<double>::convertFloatToText(frequency, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
numberOfChar += PrintFloat::convertFloatToText<double>(frequency, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
legend = " ";
legendLength = strlen(legend);
strlcpy(buffer+numberOfChar, legend, legendLength+1);

View File

@@ -84,7 +84,7 @@ void TitleBarView::layoutSubviews() {
void TitleBarView::refreshPreferences() {
char buffer[13];
int numberOfChar = 0;
if (Preferences::sharedPreferences()->displayMode() == Expression::FloatDisplayMode::Scientific) {
if (Preferences::sharedPreferences()->displayMode() == PrintFloat::Mode::Scientific) {
strlcpy(buffer, I18n::translate(I18n::Message::Sci), strlen(I18n::translate(I18n::Message::Sci))+1);
numberOfChar += strlen(I18n::translate(I18n::Message::Sci));
}

View File

@@ -154,9 +154,9 @@ void VariableBoxController::ContentViewController::willDisplayCellForIndex(Highl
const Matrix * matrixEvaluation = static_cast<const Matrix *>(evaluation);
myCell->setExpression(matrixEvaluation);
char buffer[2*PrintFloat::bufferSizeForFloatsWithPrecision(2)+1];
int numberOfChars = Complex<float>::convertFloatToText(matrixEvaluation->numberOfRows(), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(2), 2, Expression::FloatDisplayMode::Decimal);
int numberOfChars = PrintFloat::convertFloatToText<float>(matrixEvaluation->numberOfRows(), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(2), 2, PrintFloat::Mode::Decimal);
buffer[numberOfChars++] = 'x';
Complex<float>::convertFloatToText(matrixEvaluation->numberOfColumns(), buffer+numberOfChars, PrintFloat::bufferSizeForFloatsWithPrecision(2), 2, Expression::FloatDisplayMode::Decimal);
PrintFloat::convertFloatToText<float>(matrixEvaluation->numberOfColumns(), buffer+numberOfChars, PrintFloat::bufferSizeForFloatsWithPrecision(2), 2, PrintFloat::Mode::Decimal);
myCell->setSubtitle(buffer);
} else {
myCell->setExpression(nullptr);

View File

@@ -17,7 +17,7 @@ void ADC(const char * input) {
constexpr int precision = 8;
constexpr int bufferSize = Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(precision);
char responseBuffer[bufferSize+4] = {'A', 'D', 'C', '='}; // ADC=
Poincare::Complex<float>::convertFloatToText(result, responseBuffer+4, bufferSize, precision);
Poincare::PrintFloat::convertFloatToText<float>(result, responseBuffer+4, bufferSize, precision);
reply(responseBuffer);
}

View File

@@ -16,7 +16,7 @@ public:
private:
Expression * setSign(Sign s, Context & context, AngleUnit angleUnit) override;
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {
return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, "abs");
}

View File

@@ -30,7 +30,7 @@ public:
private:
/* Layout */
bool needParenthesisWithParent(const Expression * e) const override;
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createInfixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -15,7 +15,7 @@ public:
private:
constexpr static int k_maxNValue = 300;
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {
return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, "binomial");
}

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {
return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, name());
}

View File

@@ -40,22 +40,10 @@ public:
* because Complex expressions are always transformed into an addition of
* Decimal and I symbol before compared with another Expression. */
/* The parameter 'DisplayMode' refers to the way to display float 'scientific'
* or 'auto'. The scientific mode returns float with style -1.2E2 whereas
* the auto mode tries to return 'natural' float like (0.021) and switches
* to scientific mode if the float is too small or too big regarding the
* number of significant digits. If the buffer size is too small to display
* the right number of significant digits, the function forces the scientific
* mode and cap the number of significant digits to fit the buffer. If the
* buffer is too small to display any float, the text representing the float
* is truncated at the end of the buffer.
* ConvertFloat to Text return the number of characters that have been written
* in buffer (excluding the last \O character) */
static int convertFloatToText(T d, char * buffer, int bufferSize, int numberOfSignificantDigits, Expression::FloatDisplayMode mode = Expression::FloatDisplayMode::Default);
private:
Complex(T a, T b);
/* Layout */
ExpressionLayout * privateCreateLayout(Expression::FloatDisplayMode floatDisplayMode, Expression::ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, Expression::ComplexFormat complexFormat) const override;
/* Simplification */
static Expression * CreateDecimal(T f);
Expression * shallowReduce(Context & context, AngleUnit angleUnit) override;
@@ -65,10 +53,9 @@ private:
template<typename U> Complex<U> * templatedApproximate(Context& context, Expression::AngleUnit angleUnit) const;
/* convertComplexToText and convertFloatToTextPrivate return the string length
* of the buffer (does not count the 0 last char)*/
int convertComplexToText(char * buffer, int bufferSize, int numberOfSignificantDigits, Expression::FloatDisplayMode floatDisplayMode, Expression::ComplexFormat complexFormat, char multiplicationSign) const;
static int convertFloatToTextPrivate(T f, char * buffer, int numberOfSignificantDigits, Expression::FloatDisplayMode mode);
ExpressionLayout * createPolarLayout(Expression::FloatDisplayMode floatDisplayMode) const;
ExpressionLayout * createCartesianLayout(Expression::FloatDisplayMode floatDisplayMode) const;
int convertComplexToText(char * buffer, int bufferSize, int numberOfSignificantDigits, PrintFloat::Mode floatDisplayMode, Expression::ComplexFormat complexFormat, char multiplicationSign) const;
ExpressionLayout * createPolarLayout(PrintFloat::Mode floatDisplayMode) const;
ExpressionLayout * createCartesianLayout(PrintFloat::Mode floatDisplayMode) const;
T m_a;
T m_b;
};

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -13,7 +13,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {
return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, "conj");
}

View File

@@ -17,7 +17,7 @@ public:
template<typename T> static Complex<T> computeOnComplex(const Complex<T> c, AngleUnit angleUnit = AngleUnit::Radian);
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -33,7 +33,7 @@ private:
int simplificationOrderSameType(const Expression * e, bool canBeInterrupted) const override;
/* Layout */
bool needParenthesisWithParent(const Expression * e) const override;
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
/* Simplification */
Expression * shallowReduce(Context& context, AngleUnit angleUnit) override;
Expression * shallowBeautify(Context& context, AngleUnit angleUnit) override;

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -19,7 +19,7 @@ public:
private:
/* Layout */
bool needParenthesisWithParent(const Expression * e) const override;
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {
return LayoutEngine::writeInfixExpressionTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, "/");
}

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -145,11 +145,6 @@ public:
PredictionInterval,
SimplificationRoot,
};
enum class FloatDisplayMode {
Decimal = 0,
Scientific = 1,
Default = 2
};
enum class ComplexFormat {
Cartesian = 0,
Polar = 1,
@@ -214,7 +209,7 @@ public:
}
/* Layout Engine */
ExpressionLayout * createLayout(FloatDisplayMode floatDisplayMode = FloatDisplayMode::Default, ComplexFormat complexFormat = ComplexFormat::Default) const; // Returned object must be deleted
ExpressionLayout * createLayout(PrintFloat::Mode floatDisplayMode = PrintFloat::Mode::Default, ComplexFormat complexFormat = ComplexFormat::Default) const; // Returned object must be deleted
virtual int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const = 0;
/* Simplification */
@@ -267,7 +262,7 @@ private:
//TODO: What should be the implementation for complex?
virtual int simplificationOrderSameType(const Expression * e, bool canBeInterrupted) const { return 0; }
/* Layout Engine */
virtual ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const = 0;
virtual ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const = 0;
/* Simplification */
static void Reduce(Expression ** expressionAddress, Context & context, AngleUnit angleUnit, bool recursively = true);
Expression * deepBeautify(Context & context, AngleUnit angleUnit);

View File

@@ -17,7 +17,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -15,7 +15,7 @@ private:
constexpr static int k_maxOperandValue = 100;
/* Layout */
bool needParenthesisWithParent(const Expression * e) const override;
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override;
/* Simplication */
Expression * shallowReduce(Context& context, AngleUnit angleUnit) override;

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {
return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, name());
}

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -15,7 +15,7 @@ public:
template<typename T> static Complex<T> computeOnComplex(const Complex<T> c, AngleUnit angleUnit);
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -15,7 +15,7 @@ public:
template<typename T> static Complex<T> computeOnComplex(const Complex<T> c, AngleUnit angleUnit);
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -15,7 +15,7 @@ public:
template<typename T> static Complex<T> computeOnComplex(const Complex<T> c, AngleUnit angleUnit);
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -4,6 +4,7 @@
#include <assert.h>
#include <stdint.h>
#include <stddef.h>
#include <cmath>
namespace Poincare {
@@ -50,6 +51,28 @@ public:
exp -= exponentOffset();
return exp;
}
static int exponentBase10(T f) {
static T k_log10base2 = 3.321928094887362347870319429489390175864831393024580612054;
if (f == 0.0) {
return 0;
}
T exponentBase2 = exponent(f);
/* Compute the exponent in base 10 from exponent in base 2:
* f = m1*2^e1
* f = m2*10^e2
* --> f = m1*10^(e1/log(10,2))
* --> f = m1*10^x*10^(e1/log(10,2)-x), with x in [-1,1]
* Thus e2 = e1/log(10,2)-x,
* with x such as 1 <= m1*10^x < 9 and e1/log(10,2)-x is round.
* Knowing that the equation 1 <= m1*10^x < 10 with 1<=m1<2 has its solution
* in -0.31 < x < 1, we get:
* e2 = [e1/log(10,2)] or e2 = [e1/log(10,2)]-1 depending on m1. */
int exponentBase10 = std::round(exponentBase2/k_log10base2);
if (std::pow(10.0, exponentBase10) > std::fabs(f)) {
exponentBase10--;
}
return exponentBase10;
}
private:
union uint_float {
uint64_t ui;

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -15,7 +15,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {
return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, "int");
}

View File

@@ -7,8 +7,8 @@ namespace Poincare {
class LayoutEngine {
public:
static ExpressionLayout * createInfixLayout(const Expression * expression, Expression::FloatDisplayMode floatDisplayMode, Expression::ComplexFormat complexFormat, const char * operatorName);
static ExpressionLayout * createPrefixLayout(const Expression * expression, Expression::FloatDisplayMode floatDisplayMode, Expression::ComplexFormat complexFormat, const char * operatorName);
static ExpressionLayout * createInfixLayout(const Expression * expression, PrintFloat::Mode floatDisplayMode, Expression::ComplexFormat complexFormat, const char * operatorName);
static ExpressionLayout * createPrefixLayout(const Expression * expression, PrintFloat::Mode floatDisplayMode, Expression::ComplexFormat complexFormat, const char * operatorName);
static int writeInfixExpressionTextInBuffer(const Expression * expression, char * buffer, int bufferSize, int numberOfDigits, const char * operatorName);
static int writePrefixExpressionTextInBuffer(const Expression * expression, char * buffer, int bufferSize, int numberOfDigits, const char * operatorName);

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -15,7 +15,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {
return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, "log");
}

View File

@@ -31,7 +31,7 @@ public:
template<typename T> static Matrix * createApproximateIdentity(int dim);
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
/* Evaluation */
Expression * privateApproximate(SinglePrecision p, Context& context, AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
Expression * privateApproximate(DoublePrecision p, Context& context, AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Evaluation */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -33,7 +33,7 @@ private:
Expression * setSign(Sign s, Context & context, AngleUnit angleUnit) override;
/* Layout */
bool needParenthesisWithParent(const Expression * e) const override;
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override;
/* Simplification */
Expression * shallowReduce(Context& context, AngleUnit angleUnit) override;

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {
return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, "root");
}

View File

@@ -16,7 +16,7 @@ public:
private:
/* Layout */
bool needParenthesisWithParent(const Expression * e) const override;
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override;
/* Simplification */
Expression * shallowReduce(Context& context, AngleUnit angleUnit) override;

View File

@@ -14,7 +14,7 @@ public:
Type type() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {
return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, "");
}

View File

@@ -15,7 +15,7 @@ public:
private:
constexpr static int k_maxNValue = 100;
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -28,7 +28,7 @@ private:
/* Property */
Expression * setSign(Sign s, Context & context, AngleUnit angleUnit) override;
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
bool needParenthesisWithParent(const Expression * e) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {
return LayoutEngine::writeInfixExpressionTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, name());

View File

@@ -13,7 +13,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -11,15 +11,15 @@ public:
static Preferences * sharedPreferences();
Expression::AngleUnit angleUnit() const;
void setAngleUnit(Expression::AngleUnit angleUnit);
Expression::FloatDisplayMode displayMode() const;
void setDisplayMode(Expression::FloatDisplayMode FloatDisplayMode);
PrintFloat::Mode displayMode() const;
void setDisplayMode(PrintFloat::Mode mode);
Expression::ComplexFormat complexFormat() const;
void setComplexFormat(Expression::ComplexFormat complexFormat);
char numberOfSignificantDigits() const;
void setNumberOfSignificantDigits(char numberOfSignificantDigits);
private:
Expression::AngleUnit m_angleUnit;
Expression::FloatDisplayMode m_displayMode;
PrintFloat::Mode m_displayMode;
Expression::ComplexFormat m_complexFormat;
char m_numberOfSignificantDigits;
};

View File

@@ -7,6 +7,16 @@
namespace Poincare {
namespace PrintFloat {
/* The 'Mode' refers to the way to display float 'scientific' or 'auto'. The
* scientific mode returns float with style -1.2E2 whereas the auto mode
* tries to return 'natural' float like (0.021) and switches to scientific
* mode if the float is too small or too big regarding the number of
* significant digits. */
enum class Mode {
Decimal = 0,
Scientific = 1,
Default = 2
};
constexpr static int bufferSizeForFloatsWithPrecision(int numberOfSignificantDigits) {
// The wors case is -1.234E-38
return numberOfSignificantDigits + 7;
@@ -35,11 +45,17 @@ namespace PrintFloat {
* -1.99999999999999e-308*e^(-1.99999999999999e-308*i) (14+14+7+1 char) */
constexpr static int k_maxComplexBufferLength = k_maxFloatBufferLength-1+k_maxFloatBufferLength-1+7+1;
// TODO: move these two functions here. Watch out, Expression::FloatDisplayMode has also to be moved.
//int convertFloatToText(T d, char * buffer, int bufferSize, int numberOfSignificantDigits, Expression::FloatDisplayMode mode = Expression::FloatDisplayMode::Default);
//static int convertFloatToTextPrivate(T f, char * buffer, int numberOfSignificantDigits, Expression::FloatDisplayMode mode);
/* If the buffer size is too small to display the right number of significant
* digits, the function forces the scientific mode and cap the number of
* significant digits to fit the buffer. If the buffer is too small to
* display any float, the text representing the float is truncated at the end
* of the buffer.
* ConvertFloatToText return the number of characters that have been written
* in buffer (excluding the last \O character) */
template <class T>
int convertFloatToText(T d, char * buffer, int bufferSize, int numberOfSignificantDigits, Mode mode = Mode::Default);
template <class T>
static int convertFloatToTextPrivate(T f, char * buffer, int numberOfSignificantDigits, Mode mode);
}
}

View File

@@ -13,7 +13,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -17,7 +17,7 @@ public:
private:
Expression * setSign(Sign s, Context & context, AngleUnit angleUnit) override;
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -43,7 +43,7 @@ public:
static int NaturalOrder(const Rational & i, const Rational & j);
private:
bool needParenthesisWithParent(const Expression * e) const override;
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override;
Expression * privateApproximate(SinglePrecision p, Context& context, AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
Expression * privateApproximate(DoublePrecision p, Context& context, AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -10,7 +10,7 @@ namespace Poincare {
class Sequence : public StaticHierarchy<3> {
using StaticHierarchy<3>::StaticHierarchy;
private:
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {
return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, name());
}

View File

@@ -19,7 +19,7 @@ public:
}
Expression * clone() const override { return nullptr; }
Type type() const override { return Expression::Type::SimplificationRoot; }
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return nullptr;
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override { return 0; }

View File

@@ -17,7 +17,7 @@ public:
template<typename T> static Complex<T> computeOnComplex(const Complex<T> c, AngleUnit angleUnit = AngleUnit::Radian);
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -14,7 +14,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override;
/* Simplification */
Expression * shallowReduce(Context& context, AngleUnit angleUnit) override;

View File

@@ -17,7 +17,7 @@ private:
/* Simplification */
Expression * shallowReduce(Context& context, AngleUnit angleUnit) override;
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override;
/* Evalutation */
Expression * privateApproximate(SinglePrecision p, Context& context, AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }

View File

@@ -16,7 +16,7 @@ public:
private:
/* Layout */
bool needParenthesisWithParent(const Expression * e) const override;
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createInfixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -48,7 +48,7 @@ private:
/* Comparison */
int simplificationOrderSameType(const Expression * e, bool canBeInterrupted) const override;
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override;
/* Evaluation */
Expression * privateApproximate(SinglePrecision p, Context& context, AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }

View File

@@ -15,7 +15,7 @@ public:
Expression * clone() const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override {
return LayoutEngine::createPrefixLayout(this, floatDisplayMode, complexFormat, name());
}
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override {

View File

@@ -13,7 +13,7 @@ public:
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override;
private:
/* Layout */
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
ExpressionLayout * privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const override;
/* Evaluation */
Expression * privateApproximate(SinglePrecision p, Context& context, AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
Expression * privateApproximate(DoublePrecision p, Context& context, AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }

View File

@@ -24,8 +24,8 @@ Expression * AbsoluteValue::setSign(Sign s, Context & context, AngleUnit angleUn
return this;
}
ExpressionLayout * AbsoluteValue::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != FloatDisplayMode::Default);
ExpressionLayout * AbsoluteValue::privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != PrintFloat::Mode::Default);
assert(complexFormat != ComplexFormat::Default);
return new AbsoluteValueLayout(operand(0)->createLayout(floatDisplayMode, complexFormat));
}

View File

@@ -73,8 +73,8 @@ Expression * BinomialCoefficient::shallowReduce(Context& context, AngleUnit angl
return replaceWith(new Rational(result), true);
}
ExpressionLayout * BinomialCoefficient::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != FloatDisplayMode::Default);
ExpressionLayout * BinomialCoefficient::privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != PrintFloat::Mode::Default);
assert(complexFormat != ComplexFormat::Default);
ExpressionLayout * childrenLayouts[2];
childrenLayouts[0] = operand(0)->createLayout(floatDisplayMode, complexFormat);

View File

@@ -59,8 +59,8 @@ Complex<T> Ceiling::computeOnComplex(const Complex<T> c, AngleUnit angleUnit) {
return Complex<T>::Float(std::ceil(c.a()));
}
ExpressionLayout * Ceiling::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != FloatDisplayMode::Default);
ExpressionLayout * Ceiling::privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != PrintFloat::Mode::Default);
assert(complexFormat != ComplexFormat::Default);
return new CeilingLayout(m_operands[0]->createLayout(floatDisplayMode, complexFormat));
}

View File

@@ -19,30 +19,6 @@ extern "C" {
namespace Poincare {
template<typename T>
int exponent(T f) {
static T k_log10base2 = 3.321928094887362347870319429489390175864831393024580612054;
if (f == 0.0) {
return 0;
}
T exponentBase2 = IEEE754<T>::exponent(f);
/* Compute the exponent in base 10 from exponent in base 2:
* f = m1*2^e1
* f = m2*10^e2
* --> f = m1*10^(e1/log(10,2))
* --> f = m1*10^x*10^(e1/log(10,2)-x), with x in [-1,1]
* Thus e2 = e1/log(10,2)-x,
* with x such as 1 <= m1*10^x < 9 and e1/log(10,2)-x is round.
* Knowing that the equation 1 <= m1*10^x < 10 with 1<=m1<2 has its solution
* in -0.31 < x < 1, we get:
* e2 = [e1/log(10,2)] or e2 = [e1/log(10,2)]-1 depending on m1. */
int exponentBase10 = std::round(exponentBase2/k_log10base2);
if (std::pow(10.0, exponentBase10) > std::fabs(f)) {
exponentBase10--;
}
return exponentBase10;
}
template<typename T>
Complex<T> Complex<T>::Float(T x) {
return Complex(x,0);
@@ -224,32 +200,7 @@ bool Complex<T>::needParenthesisWithParent(const Expression * e) const {
}
}
template <class T>
int Complex<T>::convertFloatToText(T f, char * buffer, int bufferSize,
int numberOfSignificantDigits, Expression::FloatDisplayMode mode) {
assert(numberOfSignificantDigits > 0);
if (mode == Expression::FloatDisplayMode::Default) {
return convertFloatToText(f, buffer, bufferSize, numberOfSignificantDigits, Preferences::sharedPreferences()->displayMode());
}
char tempBuffer[PrintFloat::k_maxFloatBufferLength];
int requiredLength = convertFloatToTextPrivate(f, tempBuffer, numberOfSignificantDigits, mode);
/* if the required buffer size overflows the buffer size, we first force the
* display mode to scientific and decrease the number of significant digits to
* fit the buffer size. If the buffer size is still to small, we only write
* the beginning of the float and truncate it (which can result in a non sense
* text) */
if (mode == Expression::FloatDisplayMode::Decimal && requiredLength >= bufferSize) {
requiredLength = convertFloatToTextPrivate(f, tempBuffer, numberOfSignificantDigits, Expression::FloatDisplayMode::Scientific);
}
if (requiredLength >= bufferSize) {
int adjustedNumberOfSignificantDigits = numberOfSignificantDigits - requiredLength + bufferSize - 1;
adjustedNumberOfSignificantDigits = adjustedNumberOfSignificantDigits < 1 ? 1 : adjustedNumberOfSignificantDigits;
requiredLength = convertFloatToTextPrivate(f, tempBuffer, adjustedNumberOfSignificantDigits, Expression::FloatDisplayMode::Scientific);
}
requiredLength = requiredLength < bufferSize ? requiredLength : bufferSize;
strlcpy(buffer, tempBuffer, bufferSize);
return requiredLength;
}
template <class T>
Complex<T>::Complex(T a, T b) :
@@ -259,8 +210,8 @@ Complex<T>::Complex(T a, T b) :
}
template <class T>
ExpressionLayout * Complex<T>::privateCreateLayout(Expression::FloatDisplayMode floatDisplayMode, Expression::ComplexFormat complexFormat) const {
assert(floatDisplayMode != Expression::FloatDisplayMode::Default);
ExpressionLayout * Complex<T>::privateCreateLayout(PrintFloat::Mode floatDisplayMode, Expression::ComplexFormat complexFormat) const {
assert(floatDisplayMode != PrintFloat::Mode::Default);
if (complexFormat == Expression::ComplexFormat::Polar) {
return createPolarLayout(floatDisplayMode);
}
@@ -272,7 +223,7 @@ Expression * Complex<T>::CreateDecimal(T f) {
if (std::isnan(f) || std::isinf(f)) {
return new Undefined();
}
int e = exponent(f);
int e = IEEE754<T>::exponentBase10(f);
int64_t mantissaf = f * std::pow((T)10, -e+PrintFloat::k_numberOfStoredSignificantDigits+1);
return new Decimal(Integer(mantissaf), e);
}
@@ -296,15 +247,15 @@ Complex<U> * Complex<T>::templatedApproximate(Context& context, Expression::Angl
}
template <class T>
int Complex<T>::convertComplexToText(char * buffer, int bufferSize, int numberOfSignificantDigits, Expression::FloatDisplayMode displayMode, Expression::ComplexFormat complexFormat, char multiplicationSpecialChar) const {
assert(displayMode != Expression::FloatDisplayMode::Default);
int Complex<T>::convertComplexToText(char * buffer, int bufferSize, int numberOfSignificantDigits, PrintFloat::Mode displayMode, Expression::ComplexFormat complexFormat, char multiplicationSpecialChar) const {
assert(displayMode != PrintFloat::Mode::Default);
int numberOfChars = 0;
if (std::isnan(m_a) || std::isnan(m_b) || std::isinf(m_a) || std::isinf(m_b)) {
return convertFloatToText(NAN, buffer, bufferSize, numberOfSignificantDigits, displayMode);
return PrintFloat::convertFloatToText<T>(NAN, buffer, bufferSize, numberOfSignificantDigits, displayMode);
}
if (complexFormat == Expression::ComplexFormat::Polar) {
if (r() != 1 || th() == 0) {
numberOfChars = convertFloatToText(r(), buffer, bufferSize, numberOfSignificantDigits, displayMode);
numberOfChars = PrintFloat::convertFloatToText<T>(r(), buffer, bufferSize, numberOfSignificantDigits, displayMode);
if (r() != 0 && th() != 0 && bufferSize > numberOfChars+1) {
buffer[numberOfChars++] = multiplicationSpecialChar;
// Ensure that the string is null terminated even if buffer size is to small
@@ -319,7 +270,7 @@ int Complex<T>::convertComplexToText(char * buffer, int bufferSize, int numberOf
// Ensure that the string is null terminated even if buffer size is to small
buffer[numberOfChars] = 0;
}
numberOfChars += convertFloatToText(th(), buffer+numberOfChars, bufferSize-numberOfChars, numberOfSignificantDigits, displayMode);
numberOfChars += PrintFloat::convertFloatToText<T>(th(), buffer+numberOfChars, bufferSize-numberOfChars, numberOfSignificantDigits, displayMode);
if (bufferSize > numberOfChars+3) {
buffer[numberOfChars++] = multiplicationSpecialChar;
buffer[numberOfChars++] = Ion::Charset::IComplex;
@@ -331,7 +282,7 @@ int Complex<T>::convertComplexToText(char * buffer, int bufferSize, int numberOf
}
if (m_a != 0 || m_b == 0) {
numberOfChars = convertFloatToText(m_a, buffer, bufferSize, numberOfSignificantDigits, displayMode);
numberOfChars = PrintFloat::convertFloatToText<T>(m_a, buffer, bufferSize, numberOfSignificantDigits, displayMode);
if (m_b > 0 && !std::isnan(m_b) && bufferSize > numberOfChars+1) {
buffer[numberOfChars++] = '+';
// Ensure that the string is null terminated even if buffer size is to small
@@ -339,7 +290,7 @@ int Complex<T>::convertComplexToText(char * buffer, int bufferSize, int numberOf
}
}
if (m_b != 1 && m_b != -1 && m_b != 0) {
numberOfChars += convertFloatToText(m_b, buffer+numberOfChars, bufferSize-numberOfChars, numberOfSignificantDigits, displayMode);
numberOfChars += PrintFloat::convertFloatToText<T>(m_b, buffer+numberOfChars, bufferSize-numberOfChars, numberOfSignificantDigits, displayMode);
buffer[numberOfChars++] = multiplicationSpecialChar;
}
if (m_b == -1 && bufferSize > numberOfChars+1) {
@@ -353,143 +304,18 @@ int Complex<T>::convertComplexToText(char * buffer, int bufferSize, int numberOf
}
template <class T>
int Complex<T>::convertFloatToTextPrivate(T f, char * buffer, int numberOfSignificantDigits, Expression::FloatDisplayMode mode) {
assert(mode != Expression::FloatDisplayMode::Default);
assert(numberOfSignificantDigits > 0);
/*if (std::isinf(f)) {
int currentChar = 0;
if (f < 0) {
buffer[currentChar++] = '-';
}
buffer[currentChar++] = 'i';
buffer[currentChar++] = 'n';
buffer[currentChar++] = 'f';
buffer[currentChar] = 0;
return currentChar;
}*/
if (std::isinf(f) || std::isnan(f)) {
int currentChar = 0;
buffer[currentChar++] = 'u';
buffer[currentChar++] = 'n';
buffer[currentChar++] = 'd';
buffer[currentChar++] = 'e';
buffer[currentChar++] = 'f';
buffer[currentChar] = 0;
return currentChar;
}
int exponentInBase10 = exponent(f);
Expression::FloatDisplayMode displayMode = mode;
if ((exponentInBase10 >= numberOfSignificantDigits || exponentInBase10 <= -numberOfSignificantDigits) && mode == Expression::FloatDisplayMode::Decimal) {
displayMode = Expression::FloatDisplayMode::Scientific;
}
// Number of char available for the mantissa
int availableCharsForMantissaWithoutSign = numberOfSignificantDigits + 1;
int availableCharsForMantissaWithSign = f >= 0 ? availableCharsForMantissaWithoutSign : availableCharsForMantissaWithoutSign + 1;
// Compute mantissa
/* The number of digits in an mantissa is capped because the maximal int64_t
* is 2^63 - 1. As our mantissa is an integer built from an int64_t, we assert
* that we stay beyond this threshold during computation. */
assert(availableCharsForMantissaWithoutSign - 1 < std::log10(std::pow(2.0f, 63.0f)));
int numberOfDigitBeforeDecimal = exponentInBase10 >= 0 || displayMode == Expression::FloatDisplayMode::Scientific ?
exponentInBase10 + 1 : 1;
T unroundedMantissa = f * std::pow((T)10.0, (T)(availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal));
T mantissa = std::round(unroundedMantissa);
/* if availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal
* is too big (or too small), mantissa is now inf. We handle this case by
* using logarithm function. */
if (std::isnan(mantissa) || std::isinf(mantissa)) {
mantissa = std::round(std::pow(10, std::log10(std::fabs(f))+(T)(availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal)));
mantissa = std::copysign(mantissa, f);
}
/* We update the exponent in base 10 (if 0.99999999 was rounded to 1 for
* instance)
* NB: the following if-condition would rather be:
* "exponent(unroundedMantissa) != exponent(mantissa)",
* however, unroundedMantissa can have a different exponent than expected
* (ex: f = 1E13, unroundedMantissa = 99999999.99 and mantissa = 1000000000) */
if (f != 0 && exponent(mantissa)-exponentInBase10 != availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal) {
exponentInBase10++;
}
// Update the display mode if the exponent changed
if ((exponentInBase10 >= numberOfSignificantDigits || exponentInBase10 <= -numberOfSignificantDigits) && mode == Expression::FloatDisplayMode::Decimal) {
displayMode = Expression::FloatDisplayMode::Scientific;
}
int decimalMarkerPosition = exponentInBase10 < 0 || displayMode == Expression::FloatDisplayMode::Scientific ?
1 : exponentInBase10+1;
decimalMarkerPosition = f < 0 ? decimalMarkerPosition+1 : decimalMarkerPosition;
// Correct the number of digits in mantissa after rounding
int mantissaExponentInBase10 = exponentInBase10 > 0 || displayMode == Expression::FloatDisplayMode::Scientific ? availableCharsForMantissaWithoutSign - 1 : availableCharsForMantissaWithoutSign + exponentInBase10;
if (std::floor(std::fabs((T)mantissa) * std::pow((T)10, - mantissaExponentInBase10)) > 0) {
mantissa = mantissa/10;
}
int numberOfCharExponent = exponentInBase10 != 0 ? std::log10(std::fabs((T)exponentInBase10)) + 1 : 1;
if (exponentInBase10 < 0){
// If the exponent is < 0, we need a additional char for the sign
numberOfCharExponent++;
}
// Supress the 0 on the right side of the mantissa
Integer dividend = Integer((int64_t)std::fabs(mantissa));
Integer quotient = Integer::Division(dividend, Integer(10)).quotient;
Integer digit = Integer::Subtraction(dividend, Integer::Multiplication(quotient, Integer(10)));
int minimumNumberOfCharsInMantissa = 1;
while (digit.isZero() && availableCharsForMantissaWithoutSign > minimumNumberOfCharsInMantissa &&
(availableCharsForMantissaWithoutSign > exponentInBase10+2 || displayMode == Expression::FloatDisplayMode::Scientific)) {
mantissa = mantissa/10;
availableCharsForMantissaWithoutSign--;
availableCharsForMantissaWithSign--;
dividend = quotient;
quotient = Integer::Division(dividend, Integer(10)).quotient;
digit = Integer::Subtraction(dividend, Integer::Multiplication(quotient, Integer(10)));
}
// Suppress the decimal marker if no fractional part
if ((displayMode == Expression::FloatDisplayMode::Decimal && availableCharsForMantissaWithoutSign == exponentInBase10+2)
|| (displayMode == Expression::FloatDisplayMode::Scientific && availableCharsForMantissaWithoutSign == 2)) {
availableCharsForMantissaWithSign--;
}
// Print mantissa
assert(availableCharsForMantissaWithSign < PrintFloat::k_maxFloatBufferLength);
PrintFloat::printBase10IntegerWithDecimalMarker(buffer, availableCharsForMantissaWithSign, Integer((int64_t)mantissa), decimalMarkerPosition);
if (displayMode == Expression::FloatDisplayMode::Decimal || exponentInBase10 == 0) {
buffer[availableCharsForMantissaWithSign] = 0;
return availableCharsForMantissaWithSign;
}
// Print exponent
assert(availableCharsForMantissaWithSign < PrintFloat::k_maxFloatBufferLength);
buffer[availableCharsForMantissaWithSign] = Ion::Charset::Exponent;
assert(numberOfCharExponent+availableCharsForMantissaWithSign+1 < PrintFloat::k_maxFloatBufferLength);
PrintFloat::printBase10IntegerWithDecimalMarker(buffer+availableCharsForMantissaWithSign+1, numberOfCharExponent, Integer(exponentInBase10), -1);
buffer[availableCharsForMantissaWithSign+1+numberOfCharExponent] = 0;
return (availableCharsForMantissaWithSign+1+numberOfCharExponent);
}
template <class T>
ExpressionLayout * Complex<T>::createPolarLayout(Expression::FloatDisplayMode floatDisplayMode) const {
ExpressionLayout * Complex<T>::createPolarLayout(PrintFloat::Mode floatDisplayMode) const {
char bufferBase[PrintFloat::k_maxFloatBufferLength+2];
int numberOfCharInBase = 0;
char bufferSuperscript[PrintFloat::k_maxFloatBufferLength+2];
int numberOfCharInSuperscript = 0;
if (std::isnan(r()) || (std::isnan(th()) && r() != 0)) {
numberOfCharInBase = convertFloatToText(NAN, bufferBase, PrintFloat::k_maxComplexBufferLength, Preferences::sharedPreferences()->numberOfSignificantDigits(), floatDisplayMode);
numberOfCharInBase = PrintFloat::convertFloatToText<T>(NAN, bufferBase, PrintFloat::k_maxComplexBufferLength, Preferences::sharedPreferences()->numberOfSignificantDigits(), floatDisplayMode);
return new StringLayout(bufferBase, numberOfCharInBase);
}
if (r() != 1 || th() == 0) {
numberOfCharInBase = convertFloatToText(r(), bufferBase, PrintFloat::k_maxFloatBufferLength, Preferences::sharedPreferences()->numberOfSignificantDigits(), floatDisplayMode);
numberOfCharInBase = PrintFloat::convertFloatToText<T>(r(), bufferBase, PrintFloat::k_maxFloatBufferLength, Preferences::sharedPreferences()->numberOfSignificantDigits(), floatDisplayMode);
if (r() != 0 && th() != 0) {
bufferBase[numberOfCharInBase++] = Ion::Charset::MiddleDot;
}
@@ -500,7 +326,7 @@ ExpressionLayout * Complex<T>::createPolarLayout(Expression::FloatDisplayMode fl
}
if (r() != 0 && th() != 0) {
numberOfCharInSuperscript = convertFloatToText(th(), bufferSuperscript, PrintFloat::k_maxFloatBufferLength, Preferences::sharedPreferences()->numberOfSignificantDigits(), floatDisplayMode);
numberOfCharInSuperscript = PrintFloat::convertFloatToText<T>(th(), bufferSuperscript, PrintFloat::k_maxFloatBufferLength, Preferences::sharedPreferences()->numberOfSignificantDigits(), floatDisplayMode);
bufferSuperscript[numberOfCharInSuperscript++] = Ion::Charset::MiddleDot;
bufferSuperscript[numberOfCharInSuperscript++] = Ion::Charset::IComplex;
bufferSuperscript[numberOfCharInSuperscript] = 0;
@@ -512,7 +338,7 @@ ExpressionLayout * Complex<T>::createPolarLayout(Expression::FloatDisplayMode fl
}
template <class T>
ExpressionLayout * Complex<T>::createCartesianLayout(Expression::FloatDisplayMode floatDisplayMode) const {
ExpressionLayout * Complex<T>::createCartesianLayout(PrintFloat::Mode floatDisplayMode) const {
char buffer[PrintFloat::k_maxComplexBufferLength];
int numberOfChars = convertComplexToText(buffer, PrintFloat::k_maxComplexBufferLength, Preferences::sharedPreferences()->numberOfSignificantDigits(), floatDisplayMode, Expression::ComplexFormat::Cartesian, Ion::Charset::MiddleDot);
return new StringLayout(buffer, numberOfChars);

View File

@@ -19,8 +19,8 @@ Expression * Conjugate::clone() const {
return a;
}
ExpressionLayout * Conjugate::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != FloatDisplayMode::Default);
ExpressionLayout * Conjugate::privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != PrintFloat::Mode::Default);
assert(complexFormat != ComplexFormat::Default);
return new ConjugateLayout(operand(0)->createLayout(floatDisplayMode, complexFormat));
}

View File

@@ -217,7 +217,7 @@ bool Decimal::needParenthesisWithParent(const Expression * e) const {
return e->isOfType(types, 7);
}
ExpressionLayout * Decimal::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
ExpressionLayout * Decimal::privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const {
char buffer[255];
int numberOfChars = writeTextInBuffer(buffer, 255);
return new StringLayout(buffer, numberOfChars);

View File

@@ -90,8 +90,8 @@ Complex<T> Division::compute(const Complex<T> c, const Complex<T> d) {
return Complex<T>::Cartesian((temp*aa + ab) / norm, (temp*bb + ba) / norm);
}
ExpressionLayout * Division::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != FloatDisplayMode::Default);
ExpressionLayout * Division::privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != PrintFloat::Mode::Default);
assert(complexFormat != ComplexFormat::Default);
const Expression * numerator = operand(0)->type() == Type::Parenthesis ? operand(0)->operand(0) : operand(0);
const Expression * denominator = operand(1)->type() == Type::Parenthesis ? operand(1)->operand(0) : operand(1);

View File

@@ -213,9 +213,9 @@ int Expression::SimplificationOrder(const Expression * e1, const Expression * e2
/* Layout */
ExpressionLayout * Expression::createLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
ExpressionLayout * Expression::createLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const {
switch (floatDisplayMode) {
case FloatDisplayMode::Default:
case PrintFloat::Mode::Default:
switch (complexFormat) {
case ComplexFormat::Default:
return privateCreateLayout(Preferences::sharedPreferences()->displayMode(), Preferences::sharedPreferences()->complexFormat());

View File

@@ -81,8 +81,8 @@ Complex<T> Factorial::computeOnComplex(const Complex<T> c, AngleUnit angleUnit)
return Complex<T>::Float(std::round(result));
}
ExpressionLayout * Factorial::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != FloatDisplayMode::Default);
ExpressionLayout * Factorial::privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != PrintFloat::Mode::Default);
assert(complexFormat != ComplexFormat::Default);
ExpressionLayout * childrenLayouts[2];
childrenLayouts[0] = operand(0)->createLayout(floatDisplayMode, complexFormat);

View File

@@ -56,8 +56,8 @@ Complex<T> Floor::computeOnComplex(const Complex<T> c, AngleUnit angleUnit) {
return Complex<T>::Float(std::floor(c.a()));
}
ExpressionLayout * Floor::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != FloatDisplayMode::Default);
ExpressionLayout * Floor::privateCreateLayout(PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != PrintFloat::Mode::Default);
assert(complexFormat != ComplexFormat::Default);
return new FloorLayout(m_operands[0]->createLayout(floatDisplayMode, complexFormat));
}

Some files were not shown because too many files have changed in this diff Show More