Commit 3a83875d

3a83875d6d13Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 2 files · ~2 modified

Description

fix: ao_render binary output and C parser precision

  • ao_render: replace printf("%c") with print chr for correct binary output (avoids CRuby UTF-8 encoding of high bytes). Convert Rand module to class for reliable instance variable handling.
  • spinel_parse.c: fix float precision (%.17g instead of %g) and escape % in identifier names (%25).

Pixel values still differ slightly between CRuby and Spinel due to float precision accumulation in Math.sqrt/cos/sin over ~260K rays. Both produce valid PPM images of identical size.

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
3a83875d6d13
Parent
56801a60cd3b

spinel_parse.cmodifiedView file

@@ -89,7 +89,7 @@
8989
9090 static void emit_float(int id, const char *field, double val) {
9191 char buf[64];
92- snprintf(buf, sizeof(buf), "%g", val);
92+ snprintf(buf, sizeof(buf), "%.17g", val);
9393 /* Ensure there's a decimal point (Ruby outputs 0.0, not 0) */
9494 if (!strchr(buf, '.') && !strchr(buf, 'e') && !strchr(buf, 'E'))
9595 strcat(buf, ".0");
@@ -148,7 +148,7 @@
148148 #define F(field, val) emit_float(id, field, val)
149149 #define R(field, child) emit_ref(id, field, (pm_node_t *)(child))
150150 #define A(field, list) emit_node_array(id, field, list)
151-#define NAME(field, cid) S(field, cstr(cid))
151+#define NAME(field, cid) do { char *_n = cstr(cid); char *_e = escape_str((const uint8_t *)_n, strlen(_n)); emit_str(id, field, _e); free(_e); free(_n); } while(0)
152152
153153 switch (t) {
154154 case PM_PROGRAM_NODE: {