Skip to content

Commit

Permalink
Fix issue with serializing large floating point values
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed May 15, 2023
1 parent a990162 commit 9ee83ca
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
5 changes: 5 additions & 0 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -13579,6 +13579,11 @@ int flecs_strbuf_ftoa(
p1[0] = '.';
do {
char t = (++p1)[0];
if (t == '.') {
exp ++;
p1 --;
break;
}
p1[0] = c;
c = t;
exp ++;
Expand Down
5 changes: 5 additions & 0 deletions src/datastructures/strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ int flecs_strbuf_ftoa(
p1[0] = '.';
do {
char t = (++p1)[0];
if (t == '.') {
exp ++;
p1 --;
break;
}
p1[0] = c;
c = t;
exp ++;
Expand Down
19 changes: 14 additions & 5 deletions test/meta/src/SerializeToJson.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,20 @@ void SerializeToJson_struct_double_large() {
}
});

T value = {60000};
char *expr = ecs_ptr_to_json(world, t, &value);
test_assert(expr != NULL);
test_str(expr, "{\"x\":\"6e4\"}");
ecs_os_free(expr);
{
T value = {60000};
char *expr = ecs_ptr_to_json(world, t, &value);
test_assert(expr != NULL);
test_str(expr, "{\"x\":\"6e4\"}");
ecs_os_free(expr);
}
{
T value = {1.9885e30};
char *expr = ecs_ptr_to_json(world, t, &value);
test_assert(expr != NULL);
test_str(expr, "{\"x\":\"1.98849999999e30\"}");
ecs_os_free(expr);
}

ecs_fini(world);
}
Expand Down

0 comments on commit 9ee83ca

Please sign in to comment.