From c8f633a9ca691ee6718992b370f6aecb777f78d3 Mon Sep 17 00:00:00 2001 From: fubark Date: Mon, 2 Oct 2023 07:35:10 -0400 Subject: [PATCH] Fix cyon float encode. --- src/builtins/builtins.zig | 2 +- src/cyon.zig | 2 +- test/core_test.cy | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/builtins/builtins.zig b/src/builtins/builtins.zig index 473af272d..44d7902c5 100644 --- a/src/builtins/builtins.zig +++ b/src/builtins/builtins.zig @@ -513,7 +513,7 @@ fn genDeclEntry(vm: *cy.UserVM, parser: *const cy.Parser, decl: cy.parser.Static } try vm.mapRawSet(entry, try vm.allocAstring("name"), try vm.allocAstring(name)); - try vm.mapRawSet(entry, try vm.allocAstring("pos"), Value.initF64(@floatFromInt(pos))); + try vm.mapRawSet(entry, try vm.allocAstring("pos"), Value.initInt(@intCast(pos))); return entry; } diff --git a/src/cyon.zig b/src/cyon.zig index 3d15b4f87..5b2c8925f 100644 --- a/src/cyon.zig +++ b/src/cyon.zig @@ -326,7 +326,7 @@ const Common = struct { fn encodeFloat(writer: anytype, f: f64) !void { if (cy.Value.floatCanBeInteger(f)) { - try writer.print("{d:.0}", .{f}); + try writer.print("{d:.0}.0", .{f}); } else { try writer.print("{d}", .{f}); } diff --git a/test/core_test.cy b/test/core_test.cy index 729a9e643..a5ba4ad97 100644 --- a/test/core_test.cy +++ b/test/core_test.cy @@ -170,6 +170,8 @@ t.eq(string(float), 'type: float') -- toCyon() var cyon = toCyon(123) t.eq(cyon, '123') +cyon = toCyon(123.0) +t.eq(cyon, '123.0') cyon = toCyon('foo') t.eq(cyon, "'foo'") cyon = toCyon(true)