summaryrefslogtreecommitdiff
path: root/src/number.zig
blob: 253dda3383380d42ce5385c807cf0b0739a27ecb (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const c = @import("c");
const zpy = @import("root.zig");

pub const Number = extern struct {
    const Self = @This();

    data: c.PyObject,

    pub fn add(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_Add(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn sub(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_Subtract(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn mul(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_Multiply(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn matrixMultiply(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_MatrixMultiply(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn floorDiv(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_floorDivide(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn div(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_TrueDivide(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn remainder(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_Remainder(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn divmod(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_Divmod(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn power(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_Power(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn negative(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_Negative(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn positive(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_Positive(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn absolute(self: *Self) !*Self {
        return @ptrCast(c.PyNumber_Absolute(@ptrCast(self)) orelse return error.Exception);
    }

    pub fn invert(self: *Self) !*Self {
        return @ptrCast(c.PyNumber_Invert(@ptrCast(self)) orelse return error.Exception);
    }

    pub fn lshift(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_Lshift(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn rshift(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_Rshift(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn @"and"(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_And(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn xor(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_Xor(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn @"or"(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_Or(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn inPlaceAdd(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_InPlaceAdd(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn inPlaceSub(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_InPlaceSubtract(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn inPlaceMul(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_InPlaceMultiply(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn inPlaceMatrixMultiply(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_InPlaceMatrixMultiply(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn inPlaceFloorDiv(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_InPlacefloorDivide(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn inPlaceDiv(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_InPlaceTrueDivide(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn inPlaceRemainder(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_InPlaceRemainder(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn inPlaceDivmod(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_InPlaceDivmod(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn inPlacePower(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_InPlacePower(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn inPlaceLshift(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_InPlaceLshift(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn inPlaceRshift(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_InPlaceRshift(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn inPlaceAnd(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_InPlaceAnd(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn inPlaceXor(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_InPlaceXor(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn inPlaceOr(self: *Self, other: *Self) !*Self {
        return @ptrCast(c.PyNumber_InPlaceOr(@ptrCast(self), @ptrCast(other)) orelse return error.Exception);
    }

    pub fn toInt(self: *Self) !*zpy.Int {
        return @ptrCast(c.PyNumber_Long(@ptrCast(self)) orelse return error.Exception);
    }

    pub fn toFloat(self: *Self) !*zpy.Float {
        return @ptrCast(c.PyNumber_Float(@ptrCast(self)) orelse return error.Exception);
    }

    pub fn toBase(self: *Self, n: usize) !*zpy.Str {
        return @ptrCast(c.PyNumber_ToBase(@ptrCast(self), @intCast(n)) orelse return error.Exception);
    }

    pub fn as(self: *Self, T: type) T {
        return @intCast(c.PyNumber_AsSize_t(@ptrCast(self), null));
    }

    pub fn asObject(self: *Self) !*zpy.Object {
        return @ptrCast(self);
    }
};