From 804204db7cf1e8a28defd359d17fa72949e13eff Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 31 Aug 2026 23:05:16 +0200 Subject: Implement with ptrCast to make it more transparent. --- src/float.zig | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/float.zig (limited to 'src/float.zig') diff --git a/src/float.zig b/src/float.zig new file mode 100644 index 0000000..ffe9903 --- /dev/null +++ b/src/float.zig @@ -0,0 +1,26 @@ +const c = @import("c"); + +const zpy = @import("root.zig"); + + +pub const Float = extern struct { + const Self = @This(); + + object: c.PyObject, + + pub fn from(value: f64) !*Self { + return @ptrCast(c.PyFloat_FromDouble(value) orelse return error.Exception); + } + + pub fn asDouble(self: *const Self) f64 { + return c.PyFloat_asDouble(self.object.ptr); + } + + pub fn deinit(self: *Self) void { + self.object.decref(); + } + + pub fn asObject(self: *Self) *zpy.Object { + return @ptrCast(self); + } +}; -- cgit v1.2.3-70-g09d2