mirror of
https://github.com/pocketpy/pocketpy
synced 2026-06-21 07:57:10 +08:00
fix round trip check
This commit is contained in:
parent
803e82e2f9
commit
db8d52cab0
@ -7,6 +7,7 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
void c11_sbuf__ctor(c11_sbuf* self) {
|
void c11_sbuf__ctor(c11_sbuf* self) {
|
||||||
@ -53,11 +54,14 @@ void c11_sbuf__write_f64(c11_sbuf* self, double val, int precision) {
|
|||||||
char b[32];
|
char b[32];
|
||||||
int size;
|
int size;
|
||||||
if(precision < 0) {
|
if(precision < 0) {
|
||||||
size = snprintf(b, sizeof(b), "%.17g", val);
|
size = snprintf(b, sizeof(b), "%.*g", 15, val);
|
||||||
|
if(strtod(b, NULL) != val) {
|
||||||
|
size = snprintf(b, sizeof(b), "%.*g", 17, val);
|
||||||
|
}
|
||||||
c11_sbuf__write_cstr(self, b);
|
c11_sbuf__write_cstr(self, b);
|
||||||
bool all_is_digit = true;
|
bool all_is_digit = true;
|
||||||
for(int i = 1; i < size; i++) {
|
for(int i = 1; i < size; i++) {
|
||||||
if(!isdigit((unsigned char)b[i])) {
|
if(!isdigit(b[i])) {
|
||||||
all_is_digit = false;
|
all_is_digit = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user