mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
19563e33d2
commit
24f3656356
@ -233,6 +233,8 @@ PK_EXPORT py_f64 py_tofloat(py_Ref);
|
|||||||
/// If successful, return true and set the value to `out`.
|
/// If successful, return true and set the value to `out`.
|
||||||
/// Otherwise, return false and raise `TypeError`.
|
/// Otherwise, return false and raise `TypeError`.
|
||||||
PK_EXPORT bool py_castfloat(py_Ref, py_f64* out) PY_RAISE;
|
PK_EXPORT bool py_castfloat(py_Ref, py_f64* out) PY_RAISE;
|
||||||
|
/// 32-bit version of `py_castfloat`.
|
||||||
|
PK_EXPORT bool py_castfloat32(py_Ref, float* out) PY_RAISE;
|
||||||
/// Cast a `int` object in python to `int64_t`.
|
/// Cast a `int` object in python to `int64_t`.
|
||||||
PK_EXPORT bool py_castint(py_Ref, py_i64* out) PY_RAISE;
|
PK_EXPORT bool py_castint(py_Ref, py_i64* out) PY_RAISE;
|
||||||
/// Convert a `bool` object in python to `bool`.
|
/// Convert a `bool` object in python to `bool`.
|
||||||
|
@ -24,6 +24,14 @@ bool py_castfloat(py_Ref self, double* out) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool py_castfloat32(py_Ref self, float *out){
|
||||||
|
switch(self->type) {
|
||||||
|
case tp_int: *out = (float)self->_i64; return true;
|
||||||
|
case tp_float: *out = (float)self->_f64; return true;
|
||||||
|
default: return TypeError("expected 'int' or 'float', got '%t'", self->type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool py_castint(py_Ref self, int64_t* out) {
|
bool py_castint(py_Ref self, int64_t* out) {
|
||||||
if(self->type == tp_int) {
|
if(self->type == tp_int) {
|
||||||
*out = self->_i64;
|
*out = self->_i64;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user