@@ -11077,6 +11077,7 @@ void flecs_bitset_swap(
1107711077}
1107811078
1107911079#include <stdio.h>
11080+ #include <math.h>
1108011081
1108111082/**
1108211083 * stm32tpl -- STM32 C++ Template Peripheral Library
@@ -11105,14 +11106,34 @@ static
1110511106int ecs_strbuf_ftoa(
1110611107 ecs_strbuf_t *out,
1110711108 double f,
11108- int precision)
11109+ int precision,
11110+ char nan_delim)
1110911111{
1111011112 char buf[64];
1111111113 char * ptr = buf;
1111211114 char * p1;
1111311115 char c;
1111411116 int64_t intPart;
1111511117
11118+ if (isnan(f)) {
11119+ if (nan_delim) {
11120+ ecs_strbuf_appendch(out, nan_delim);
11121+ ecs_strbuf_appendstr(out, "nan");
11122+ return ecs_strbuf_appendch(out, nan_delim);
11123+ } else {
11124+ return ecs_strbuf_appendstr(out, "nan");
11125+ }
11126+ }
11127+ if (isinf(f)) {
11128+ if (nan_delim) {
11129+ ecs_strbuf_appendch(out, nan_delim);
11130+ ecs_strbuf_appendstr(out, "inf");
11131+ return ecs_strbuf_appendch(out, nan_delim);
11132+ } else {
11133+ return ecs_strbuf_appendstr(out, "inf");
11134+ }
11135+ }
11136+
1111611137 if (precision > MAX_PRECISION) {
1111711138 precision = MAX_PRECISION;
1111811139 }
@@ -11469,10 +11490,11 @@ bool ecs_strbuf_appendch(
1146911490
1147011491bool ecs_strbuf_appendflt(
1147111492 ecs_strbuf_t *b,
11472- double flt)
11493+ double flt,
11494+ char nan_delim)
1147311495{
1147411496 ecs_assert(b != NULL, ECS_INVALID_PARAMETER, NULL);
11475- return ecs_strbuf_ftoa(b, flt, 2);
11497+ return ecs_strbuf_ftoa(b, flt, 2, nan_delim );
1147611498}
1147711499
1147811500bool ecs_strbuf_appendstr_zerocpy(
@@ -23089,10 +23111,10 @@ int expr_ser_primitive(
2308923111 ecs_strbuf_append(str, "%lld", *(int64_t*)base);
2309023112 break;
2309123113 case EcsF32:
23092- ecs_strbuf_appendflt(str, (double)*(float*)base);
23114+ ecs_strbuf_appendflt(str, (double)*(float*)base, 0 );
2309323115 break;
2309423116 case EcsF64:
23095- ecs_strbuf_appendflt(str, *(double*)base);
23117+ ecs_strbuf_appendflt(str, *(double*)base, 0 );
2309623118 break;
2309723119 case EcsIPtr:
2309823120 ecs_strbuf_append(str, "%i", *(intptr_t*)base);
@@ -25328,7 +25350,7 @@ void json_number(
2532825350 ecs_strbuf_t *buf,
2532925351 double value)
2533025352{
25331- ecs_strbuf_appendflt(buf, value);
25353+ ecs_strbuf_appendflt(buf, value, '"' );
2533225354}
2533325355
2533425356void json_true(
@@ -25621,6 +25643,14 @@ int json_ser_type_op(
2562125643 /* Should not be parsed as single op */
2562225644 ecs_throw(ECS_INVALID_PARAMETER, NULL);
2562325645 break;
25646+ case EcsOpF32:
25647+ ecs_strbuf_appendflt(str,
25648+ (ecs_f64_t)*(ecs_f32_t*)ECS_OFFSET(ptr, op->offset), '"');
25649+ break;
25650+ case EcsOpF64:
25651+ ecs_strbuf_appendflt(str,
25652+ *(ecs_f64_t*)ECS_OFFSET(ptr, op->offset), '"');
25653+ break;
2562425654 case EcsOpEnum:
2562525655 if (json_ser_enum(world, op, ECS_OFFSET(ptr, op->offset), str)) {
2562625656 goto error;
0 commit comments