Skip to content

Commit

Permalink
Add float16 (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn authored Oct 2, 2023
1 parent 561ee9b commit 3c8ee40
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions docs/guide/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ The remaining sequence methods are yet to be implemented.

The remaining mapping methods are yet to be implemented.

### Richcompare
### Rich Compare

CompareOp is a zig enum variant of CPython operator int. With an enum you can easily construct an exhaustive switch statement.

| Method | Signature |
| :---------------- | :------------------------------------------ |
| `__hash__` | `#!zig fn(*Self) !usize` |
| `__richcompare__` | `#!zig fn(*Self, object, CompareOp) !usize` |
| Method | Signature |
| :---------------- | :------------------------------------------------- |
| `__hash__` | `#!zig fn(*Self) !usize` |
| `__richcompare__` | `#!zig fn(*Self, other: object, CompareOp) !usize` |

Additionally you can implement comparison method as you would in python by providing individual operations as functions.

Expand Down
22 changes: 11 additions & 11 deletions docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ or returned from functions and automatically converted into Python objects.

### Zig Primitives

| Zig Type | Python Type |
|:---------------| :----------- |
| `void` | `None` |
| `bool` | `bool` |
| `i32`, `i64` | `int` |
| `u32`, `u64` | `int` |
| `f32`, `f64` | `float` |
| `struct` | `dict` |
| `tuple struct` | `tuple` |
| `[]const u8` | `str` |
| `*[_]u8` | `str` |
| Zig Type | Python Type |
|:----------------------| :----------- |
| `void` | `None` |
| `bool` | `bool` |
| `i32`, `i64` | `int` |
| `u32`, `u64` | `int` |
| `f16`, `f32`, `f64` | `float` |
| `struct` | `dict` |
| `tuple struct` | `tuple` |
| `[]const u8` | `str` |
| `*[_]u8` | `str` |

!!! tip ""

Expand Down
2 changes: 1 addition & 1 deletion pydust/src/types/float.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub const PyFloat = extern struct {

pub fn as(self: PyFloat, comptime T: type) !T {
return switch (T) {
f32, f64 => {
f16, f32, f64 => {
const double = ffi.PyFloat_AsDouble(self.obj.py);
if (ffi.PyErr_Occurred() != null) return PyError.PyRaised;
return @floatCast(double);
Expand Down

0 comments on commit 3c8ee40

Please sign in to comment.