summaryrefslogtreecommitdiff
path: root/src/float.zig
blob: ffe9903ef528cf509bb959f5e42fe11f75b2a167 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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);
    }
};