Browse Source

linmath: Fix vector printing issues with big values on emscripten

rdb 1 year ago
parent
commit
c060b2f3fe
2 changed files with 5 additions and 3 deletions
  1. 2 1
      panda/src/linmath/dblnames.h
  2. 3 2
      panda/src/linmath/fltnames.h

+ 2 - 1
panda/src/linmath/dblnames.h

@@ -46,7 +46,8 @@
 #define FLOATTYPE_REPR(v, str) do { \
   double v_copy = (v); \
   char *into_str = (str); \
-  if ((double)(long long)v_copy == v_copy) { \
+  if (v_copy < 1e16 && v_copy > -1e16 && \
+      (double)(long long)v_copy == v_copy) { \
     snprintf(into_str, 32, "%lld", (long long)v_copy); \
   } else { \
     pdtoa(v_copy, into_str); \

+ 3 - 2
panda/src/linmath/fltnames.h

@@ -46,8 +46,9 @@
 #define FLOATTYPE_REPR(v, str) do { \
   float v_copy = (v); \
   char *into_str = (str); \
-  if ((float)(int)v_copy == v_copy) { \
-    snprintf(into_str, 32, "%d", (int)v_copy); \
+  if (v_copy < 1e16f && v_copy > -1e16f && \
+      (float)(long long)v_copy == v_copy) { \
+    snprintf(into_str, 32, "%lld", (long long)v_copy); \
   } else { \
     pftoa(v_copy, into_str); \
   } \