6663b6c9
adorian
projet complet av...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#include <poincare/print_float.h>
extern "C" {
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
}
#include <cmath>
#include <ion.h>
#include <stdio.h>
namespace Poincare {
void PrintFloat::printBase10IntegerWithDecimalMarker(char * buffer, int bufferLength, Integer 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
* always > 0 as we asserted a minimal number of available chars. */
assert(bufferLength > 0 && decimalMarkerPosition != 0);
char tempBuffer[PrintFloat::k_maxFloatBufferLength];
int intLength = i.writeTextInBuffer(tempBuffer, PrintFloat::k_maxFloatBufferLength);
int firstDigitChar = tempBuffer[0] == '-' ? 1 : 0;
for (int k = bufferLength-1; k >= firstDigitChar; k--) {
if (k == decimalMarkerPosition) {
buffer[k] = '.';
continue;
}
if (intLength > firstDigitChar) {
buffer[k] = tempBuffer[--intLength];
continue;
}
buffer[k] = '0';
}
if (firstDigitChar == 1) {
buffer[0] = tempBuffer[0];
}
}
}
|