mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
Update pocketpy.h
This commit is contained in:
parent
229a836444
commit
c5b263d5a8
@ -17,7 +17,9 @@ The initial version. Hello, world!
|
||||
+ Fix a bug about comment and indentation
|
||||
+ Fix a bug about compile error line number
|
||||
|
||||
## 0.4.8+4
|
||||
## 0.4.8+5
|
||||
|
||||
+ Downgrade to `sdk>=2.17.0`
|
||||
+ Fix some bugs about compile error
|
||||
+ Fix a bug for jsonify `nan` or `inf`
|
||||
+ Add `math.isnan` and `math.isinf`
|
@ -1,6 +1,6 @@
|
||||
name: pocketpy
|
||||
description: A lightweight Python interpreter for game engines.
|
||||
version: 0.4.8+4
|
||||
version: 0.4.8+5
|
||||
homepage: https://pocketpy.dev
|
||||
repository: https://github.com/blueloveth/pocketpy
|
||||
|
||||
|
@ -6481,7 +6481,11 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
||||
});
|
||||
|
||||
_vm->bindMethod("float", "__json__", [](VM* vm, const pkpy::ArgList& args) {
|
||||
return vm->PyStr(std::to_string((float)vm->PyFloat_AS_C(args[0])));
|
||||
_Float val = vm->PyFloat_AS_C(args[0]);
|
||||
if(std::isinf(val) || std::isnan(val)){
|
||||
vm->valueError("cannot jsonify 'nan' or 'inf'");
|
||||
}
|
||||
return vm->PyStr(std::to_string(val));
|
||||
});
|
||||
|
||||
/************ PyString ************/
|
||||
@ -6887,6 +6891,16 @@ void __addModuleMath(VM* vm){
|
||||
_Float b = vm->numToFloat(args[1]);
|
||||
return vm->PyBool(fabs(a - b) < 1e-9);
|
||||
});
|
||||
|
||||
vm->bindFunc(mod, "isnan", [](VM* vm, const pkpy::ArgList& args) {
|
||||
vm->__checkArgSize(args, 1);
|
||||
return vm->PyBool(std::isnan(vm->numToFloat(args[0])));
|
||||
});
|
||||
|
||||
vm->bindFunc(mod, "isinf", [](VM* vm, const pkpy::ArgList& args) {
|
||||
vm->__checkArgSize(args, 1);
|
||||
return vm->PyBool(std::isinf(vm->numToFloat(args[0])));
|
||||
});
|
||||
}
|
||||
|
||||
class _PkExported{
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit c645191b67d056996ee4d0d6a387758c16edf7e2
|
||||
Subproject commit b1d3e4f63e539272d5b77bfb44ed8f5778efef9e
|
@ -6481,7 +6481,11 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
||||
});
|
||||
|
||||
_vm->bindMethod("float", "__json__", [](VM* vm, const pkpy::ArgList& args) {
|
||||
return vm->PyStr(std::to_string((float)vm->PyFloat_AS_C(args[0])));
|
||||
_Float val = vm->PyFloat_AS_C(args[0]);
|
||||
if(std::isinf(val) || std::isnan(val)){
|
||||
vm->valueError("cannot jsonify 'nan' or 'inf'");
|
||||
}
|
||||
return vm->PyStr(std::to_string(val));
|
||||
});
|
||||
|
||||
/************ PyString ************/
|
||||
@ -6887,6 +6891,16 @@ void __addModuleMath(VM* vm){
|
||||
_Float b = vm->numToFloat(args[1]);
|
||||
return vm->PyBool(fabs(a - b) < 1e-9);
|
||||
});
|
||||
|
||||
vm->bindFunc(mod, "isnan", [](VM* vm, const pkpy::ArgList& args) {
|
||||
vm->__checkArgSize(args, 1);
|
||||
return vm->PyBool(std::isnan(vm->numToFloat(args[0])));
|
||||
});
|
||||
|
||||
vm->bindFunc(mod, "isinf", [](VM* vm, const pkpy::ArgList& args) {
|
||||
vm->__checkArgSize(args, 1);
|
||||
return vm->PyBool(std::isinf(vm->numToFloat(args[0])));
|
||||
});
|
||||
}
|
||||
|
||||
class _PkExported{
|
||||
|
@ -280,7 +280,11 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
||||
});
|
||||
|
||||
_vm->bindMethod("float", "__json__", [](VM* vm, const pkpy::ArgList& args) {
|
||||
return vm->PyStr(std::to_string((float)vm->PyFloat_AS_C(args[0])));
|
||||
_Float val = vm->PyFloat_AS_C(args[0]);
|
||||
if(std::isinf(val) || std::isnan(val)){
|
||||
vm->valueError("cannot jsonify 'nan' or 'inf'");
|
||||
}
|
||||
return vm->PyStr(std::to_string(val));
|
||||
});
|
||||
|
||||
/************ PyString ************/
|
||||
@ -688,6 +692,16 @@ void __addModuleMath(VM* vm){
|
||||
_Float b = vm->numToFloat(args[1]);
|
||||
return vm->PyBool(fabs(a - b) < 1e-9);
|
||||
});
|
||||
|
||||
vm->bindFunc(mod, "isnan", [](VM* vm, const pkpy::ArgList& args) {
|
||||
vm->__checkArgSize(args, 1);
|
||||
return vm->PyBool(std::isnan(vm->numToFloat(args[0])));
|
||||
});
|
||||
|
||||
vm->bindFunc(mod, "isinf", [](VM* vm, const pkpy::ArgList& args) {
|
||||
vm->__checkArgSize(args, 1);
|
||||
return vm->PyBool(std::isinf(vm->numToFloat(args[0])));
|
||||
});
|
||||
}
|
||||
|
||||
class _PkExported{
|
||||
|
@ -1,4 +1,4 @@
|
||||
from math import log, log10, log2, sin, cos, tan, e, pi, isclose
|
||||
from math import log, log10, log2, sin, cos, tan, e, pi, isclose, isnan, isinf
|
||||
|
||||
assert isclose(e, 2.718281828459045)
|
||||
assert isclose(pi, 3.141592653589793)
|
||||
@ -8,3 +8,9 @@ assert isclose(log2(10), 3.321928094887362)
|
||||
assert isclose(sin(0), 0.0)
|
||||
assert isclose(cos(0), 1.0)
|
||||
assert isclose(tan(0), 0.0)
|
||||
|
||||
a = -0.1
|
||||
a = a**a
|
||||
assert isnan(a)
|
||||
assert not isinf(a)
|
||||
assert isinf(float("inf"))
|
Loading…
x
Reference in New Issue
Block a user