Skip to content

Commit 57e90fc

Browse files
DreamPearlscopeInfinity
authored andcommitted
Add afterpoint argument in ftoa function
1 parent 90fe1cd commit 57e90fc

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/usr/include/stdlib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int atoi(const char *s);
1313
// for others the result can be undefined.
1414
// And only base 10 is considered as signed int.
1515
void itoa(int num, char *s, int base);
16-
void ftoa(double num, char *s);
16+
void ftoa(double num, char *s, int afterpoint);
1717
int min(int, int);
1818
int max(int, int);
1919
int abs(int a);

src/usr/lib/stdio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static int vsnprintf(char *s, size_t n, const char *fmt, va_list args) {
6161
}
6262
break;
6363
case 'f':
64-
ftoa(va_arg(args, double), sbuffer);
64+
ftoa(va_arg(args, double), sbuffer, 8);
6565
innerstr = sbuffer;
6666
while (len < n && (*innerstr) != '\0') {
6767
s[len++] = *(innerstr++);

src/usr/lib/stdlib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void itoa(int num, char *s, int base) {
6767
}
6868
}
6969

70-
void ftoa(double num, char *s) {
70+
void ftoa(double num, char *s, int afterpoint) {
7171
// not a good implementation
7272
if (isnan(num)) {
7373
*(s++) = 'n';
@@ -98,7 +98,7 @@ void ftoa(double num, char *s) {
9898
*(s++) = '0';
9999
*(s++) = '.';
100100

101-
for (int i = 0; i < 8; i++) {
101+
for (int i = 0; i < afterpoint; i++) {
102102
num *= 10;
103103
int msb = num;
104104
*(s++) = '0' + msb;

0 commit comments

Comments
 (0)