Skip to content

Commit

Permalink
Fix cyon float encode.
Browse files Browse the repository at this point in the history
  • Loading branch information
fubark committed Oct 2, 2023
1 parent 8edac82 commit c8f633a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/builtins/builtins.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/cyon.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
Expand Down
2 changes: 2 additions & 0 deletions test/core_test.cy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c8f633a

Please sign in to comment.