[poincare/print_float] convertFloatToText -> ConvertFloatToText

This commit is contained in:
Léa Saviot
2019-08-07 14:30:21 +02:00
committed by Émilie Feral
parent e75701f0fa
commit b0b10f184e
15 changed files with 25 additions and 25 deletions

View File

@@ -47,7 +47,7 @@ void BatteryTestController::updateBatteryState(float batteryLevel, bool batteryC
char bufferLevel[bufferLevelSize];
const char * legend = "Battery level: ";
int legendLength = strlcpy(bufferLevel, legend, bufferLevelSize);
PrintFloat::convertFloatToText<float>(batteryLevel, bufferLevel+legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
PrintFloat::ConvertFloatToText<float>(batteryLevel, bufferLevel+legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
m_view.batteryLevelTextView()->setText(bufferLevel);
constexpr size_t bufferChargingSize = ContentView::k_maxNumberOfCharacters + PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits);

View File

@@ -184,7 +184,7 @@ void CalculationController::willDisplayCellAtLocation(HighlightCell * cell, int
constexpr int precision = Constant::LargeNumberOfSignificantDigits;
constexpr int bufferSize = PrintFloat::bufferSizeForFloatsWithPrecision(precision);
char buffer[bufferSize];
PrintFloat::convertFloatToText<double>(m_calculation->parameterAtIndex(i-1), buffer, bufferSize, precision, Preferences::PrintFloatMode::Decimal);
PrintFloat::ConvertFloatToText<double>(m_calculation->parameterAtIndex(i-1), buffer, bufferSize, precision, Preferences::PrintFloatMode::Decimal);
field->setText(buffer);
}
}
@@ -287,7 +287,7 @@ void CalculationController::updateTitle() {
constexpr int precision = Constant::ShortNumberOfSignificantDigits;
constexpr size_t bufferSize = PrintFloat::bufferSizeForFloatsWithPrecision(precision);
char buffer[bufferSize];
PrintFloat::convertFloatToText<double>(m_law->parameterValueAtIndex(index), buffer, bufferSize, precision, Preferences::PrintFloatMode::Decimal);
PrintFloat::ConvertFloatToText<double>(m_law->parameterValueAtIndex(index), buffer, bufferSize, precision, Preferences::PrintFloatMode::Decimal);
currentChar += strlcpy(m_titleBuffer+currentChar, buffer, k_titleBufferSize - currentChar);
if (currentChar >= k_titleBufferSize) {
break;

View File

@@ -116,7 +116,7 @@ void GraphController::reloadBannerView() {
legend = I18n::translate(I18n::Message::Reg);
numberOfChar += strlcpy(buffer + numberOfChar, legend, bufferSize - numberOfChar);
} else {
numberOfChar += PrintFloat::convertFloatToText<float>(std::round((float)*m_selectedDotIndex+1.0f), buffer + numberOfChar, bufferSize - numberOfChar, Constant::ShortNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
numberOfChar += PrintFloat::ConvertFloatToText<float>(std::round((float)*m_selectedDotIndex+1.0f), buffer + numberOfChar, bufferSize - numberOfChar, Constant::ShortNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
}
legend = ") ";
strlcpy(buffer + numberOfChar, legend, bufferSize - numberOfChar);

View File

@@ -192,7 +192,7 @@ void CurveView::computeLabels(Axis axis) {
* from overprinting one another. */
char * labelBuffer = label(axis, i);
PrintFloat::convertFloatToText<float>(
PrintFloat::ConvertFloatToText<float>(
labelValue,
labelBuffer,
labelMaxSize,
@@ -785,7 +785,7 @@ void CurveView::computeHorizontalExtremaLabels(bool increaseNumberOfSignificantD
int minMax[] = {firstLabel, lastLabel};
for (int i : minMax) {
// Compute the minimal and maximal label
PrintFloat::convertFloatToText<float>(
PrintFloat::ConvertFloatToText<float>(
labelValueAtIndex(axis, i),
label(axis, i),
k_labelBufferMaxSize,

View File

@@ -78,7 +78,7 @@ void EditableCellTableViewController::willDisplayCellAtLocationWithDisplayMode(H
}
if (!myEditableValueCell->editableTextCell()->textField()->isEditing()) {
myCell->setEven(j%2 == 0);
PrintFloat::convertFloatToText<double>(dataAtLocation(i, j), buffer, cellBufferSize(i), Constant::LargeNumberOfSignificantDigits, floatDisplayMode);
PrintFloat::ConvertFloatToText<double>(dataAtLocation(i, j), buffer, cellBufferSize(i), Constant::LargeNumberOfSignificantDigits, floatDisplayMode);
myEditableValueCell->editableTextCell()->textField()->setText(buffer);
}
return;

View File

@@ -109,7 +109,7 @@ void FloatParameterController::willDisplayCellForIndex(HighlightCell * cell, int
return;
}
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
PrintFloat::convertFloatToText<double>(parameterAtIndex(index), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
PrintFloat::ConvertFloatToText<double>(parameterAtIndex(index), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
myCell->setAccessoryText(buffer);
}

View File

@@ -16,7 +16,7 @@ inline Poincare::Layout CreateLayout(const Poincare::Expression e) {
template <class T>
inline int ConvertFloatToText(T d, char * buffer, int bufferSize, int numberOfSignificantDigits) {
return Poincare::PrintFloat::convertFloatToText(d, buffer, bufferSize, numberOfSignificantDigits, Poincare::Preferences::sharedPreferences()->displayMode());
return Poincare::PrintFloat::ConvertFloatToText(d, buffer, bufferSize, numberOfSignificantDigits, Poincare::Preferences::sharedPreferences()->displayMode());
}
inline int Serialize(const Poincare::Expression e, char * buffer, int bufferSize, int numberOfSignificantDigits = Poincare::PrintFloat::k_numberOfStoredSignificantDigits) {

View File

@@ -178,7 +178,7 @@ void SumGraphController::LegendView::setLegendMessage(I18n::Message message, Ste
void SumGraphController::LegendView::setEditableZone(double d) {
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits)];
PrintFloat::convertFloatToText<double>(d, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
PrintFloat::ConvertFloatToText<double>(d, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
m_editableZone.setText(buffer);
}
@@ -190,16 +190,16 @@ void SumGraphController::LegendView::setSumSymbol(Step step, double start, doubl
m_sumLayout = LayoutHelper::CodePointString(sigma, sigmaLength);
} else if (step == Step::SecondParameter) {
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits)];
PrintFloat::convertFloatToText<double>(start, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
PrintFloat::ConvertFloatToText<double>(start, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
m_sumLayout = CondensedSumLayout::Builder(
LayoutHelper::CodePointString(sigma, sigmaLength),
LayoutHelper::String(buffer, strlen(buffer), k_font),
EmptyLayout::Builder(EmptyLayoutNode::Color::Yellow, false, k_font, false));
} else {
char buffer[2+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
PrintFloat::convertFloatToText<double>(start, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
PrintFloat::ConvertFloatToText<double>(start, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
Layout start = LayoutHelper::String(buffer, strlen(buffer), k_font);
PrintFloat::convertFloatToText<double>(end, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
PrintFloat::ConvertFloatToText<double>(end, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
Layout end = LayoutHelper::String(buffer, strlen(buffer), k_font);
m_sumLayout = CondensedSumLayout::Builder(
LayoutHelper::CodePointString(sigma, sigmaLength),

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::PrintFloat::convertFloatToText<float>(result, responseBuffer+4, bufferSize, precision, Poincare::Preferences::PrintFloatMode::Decimal);
Poincare::PrintFloat::ConvertFloatToText<float>(result, responseBuffer+4, bufferSize, precision, Poincare::Preferences::PrintFloatMode::Decimal);
reply(responseBuffer);
}

View File

@@ -31,7 +31,7 @@ public:
* ConvertFloatToText returns the number of characters that have been written
* in buffer (excluding the last \0 character). */
template <class T>
static int convertFloatToText(T d, char * buffer, int bufferSize, int numberOfSignificantDigits, Preferences::PrintFloatMode mode, bool allowRounding = true); //TODO LEA put upperCase
static int ConvertFloatToText(T d, char * buffer, int bufferSize, int numberOfSignificantDigits, Preferences::PrintFloatMode mode, bool allowRounding = true);
private:
template <class T>

View File

@@ -31,7 +31,7 @@ int FloatNode<T>::simplificationOrderSameType(const ExpressionNode * e, bool asc
template<typename T>
int FloatNode<T>::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
return PrintFloat::convertFloatToText(m_value, buffer, bufferSize, numberOfSignificantDigits, floatDisplayMode);
return PrintFloat::ConvertFloatToText(m_value, buffer, bufferSize, numberOfSignificantDigits, floatDisplayMode);
}
template<typename T>

View File

@@ -24,7 +24,7 @@ int InfinityNode::serialize(char * buffer, int bufferSize, Preferences::PrintFlo
if (bufferSize == 0) {
return -1;
}
return PrintFloat::convertFloatToText<float>(m_negative ? -INFINITY : INFINITY, buffer, bufferSize, numberOfSignificantDigits, floatDisplayMode);
return PrintFloat::ConvertFloatToText<float>(m_negative ? -INFINITY : INFINITY, buffer, bufferSize, numberOfSignificantDigits, floatDisplayMode);
}
template<typename T> Evaluation<T> InfinityNode::templatedApproximate() const {

View File

@@ -166,7 +166,7 @@ int Integer::serialize(char * buffer, int bufferSize) const {
return 0;
}
if (isOverflow()) {
return PrintFloat::convertFloatToText<float>(m_negative ? -INFINITY : INFINITY, buffer, bufferSize, PrintFloat::k_numberOfStoredSignificantDigits, Preferences::PrintFloatMode::Decimal);
return PrintFloat::ConvertFloatToText<float>(m_negative ? -INFINITY : INFINITY, buffer, bufferSize, PrintFloat::k_numberOfStoredSignificantDigits, Preferences::PrintFloatMode::Decimal);
}
Integer base(10);
@@ -185,7 +185,7 @@ int Integer::serialize(char * buffer, int bufferSize) const {
d.quotient.isZero())) {
char c = char_from_digit(d.remainder.isZero() ? 0 : d.remainder.digit(0));
if (length >= bufferSize-1) {
return PrintFloat::convertFloatToText<float>(NAN, buffer, bufferSize, PrintFloat::k_numberOfStoredSignificantDigits, Preferences::PrintFloatMode::Decimal);
return PrintFloat::ConvertFloatToText<float>(NAN, buffer, bufferSize, PrintFloat::k_numberOfStoredSignificantDigits, Preferences::PrintFloatMode::Decimal);
}
length += SerializationHelper::CodePoint(buffer + length, bufferSize - length, c);
d = udiv(d.quotient, base);

View File

@@ -93,7 +93,7 @@ int PrintFloat::Long::serialize(char * buffer, int bufferSize) const {
void PrintFloat::PrintLongWithDecimalMarker(char * buffer, int bufferLength, Long & i, int decimalMarkerPosition) {
/* The decimal marker position is always preceded by a char, thus, it is never
* in first position. When called by convertFloatToText, the buffer length is
* in first position. When called by ConvertFloatToText, the buffer length is
* always > 0 as we asserted a minimal number of available chars. */
assert(bufferLength > 0 && decimalMarkerPosition != 0);
constexpr int tempBufferSize = PrintFloat::k_maxFloatBufferLength;
@@ -124,7 +124,7 @@ void PrintFloat::PrintLongWithDecimalMarker(char * buffer, int bufferLength, Lon
}
template <class T>
int PrintFloat::convertFloatToText(T f, char * buffer, int bufferSize,
int PrintFloat::ConvertFloatToText(T f, char * buffer, int bufferSize,
int numberOfSignificantDigits, Preferences::PrintFloatMode mode, bool allowRounding)
{
assert(numberOfSignificantDigits > 0);
@@ -227,7 +227,7 @@ int PrintFloat::ConvertFloatToTextPrivate(T f, char * buffer, int bufferSize, in
if (mode == Preferences::PrintFloatMode::Decimal && exponentInBase10 >= numberOfSignificantDigits) {
/* Exception 1: avoid inventing digits to fill the printed float: when
* displaying 12345 with 2 significant digis in Decimal mode for instance.
* This exception is caught by convertFloatToText and forces the mode to
* This exception is caught by ConvertFloatToText and forces the mode to
* Scientific */
assert(!returnTrueRequiredLength);
return bufferSize + 1;
@@ -339,7 +339,7 @@ int PrintFloat::ConvertFloatToTextPrivate(T f, char * buffer, int bufferSize, in
return currentNumberOfChar + numberOfCharExponent;
}
template int PrintFloat::convertFloatToText<float>(float, char*, int, int, Preferences::Preferences::PrintFloatMode, bool);
template int PrintFloat::convertFloatToText<double>(double, char*, int, int, Preferences::Preferences::PrintFloatMode, bool);
template int PrintFloat::ConvertFloatToText<float>(float, char*, int, int, Preferences::Preferences::PrintFloatMode, bool);
template int PrintFloat::ConvertFloatToText<double>(double, char*, int, int, Preferences::Preferences::PrintFloatMode, bool);
}

View File

@@ -20,7 +20,7 @@ void assert_float_prints_to(T a, const char * result, Preferences::PrintFloatMod
memset(taggedBuffer, tag, bufferSize+2*tagSize);
char * buffer = taggedBuffer + tagSize;
PrintFloat::convertFloatToText<T>(a, buffer, bufferSize, significantDigits, mode);
PrintFloat::ConvertFloatToText<T>(a, buffer, bufferSize, significantDigits, mode);
for (int i=0; i<tagSize; i++) {
quiz_assert(taggedBuffer[i] == tag);