mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-23 04:50:17 +00:00
This commit is contained in:
parent
035886b655
commit
4af7d5c873
@ -170,7 +170,14 @@ void add_module_math(VM* vm){
|
|||||||
});
|
});
|
||||||
|
|
||||||
vm->bind_func<1>(mod, "exp", PK_LAMBDA(VAR(std::exp(CAST_F(args[0])))));
|
vm->bind_func<1>(mod, "exp", PK_LAMBDA(VAR(std::exp(CAST_F(args[0])))));
|
||||||
vm->bind_func<1>(mod, "log", PK_LAMBDA(VAR(std::log(CAST_F(args[0])))));
|
// vm->bind_func<1>(mod, "log", PK_LAMBDA(VAR(std::log(CAST_F(args[0])))));
|
||||||
|
|
||||||
|
vm->bind(mod, "log(x, base=2.718281828459045)", [](VM* vm, ArgsView args){
|
||||||
|
f64 x = CAST_F(args[0]);
|
||||||
|
f64 base = CAST_F(args[1]);
|
||||||
|
return VAR(std::log(x) / std::log(base));
|
||||||
|
});
|
||||||
|
|
||||||
vm->bind_func<1>(mod, "log2", PK_LAMBDA(VAR(std::log2(CAST_F(args[0])))));
|
vm->bind_func<1>(mod, "log2", PK_LAMBDA(VAR(std::log2(CAST_F(args[0])))));
|
||||||
vm->bind_func<1>(mod, "log10", PK_LAMBDA(VAR(std::log10(CAST_F(args[0])))));
|
vm->bind_func<1>(mod, "log10", PK_LAMBDA(VAR(std::log10(CAST_F(args[0])))));
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from cmath import isclose, sqrt, nan, inf, nanj, infj
|
from cmath import isclose, sqrt, nan, inf, nanj, infj, log
|
||||||
import math
|
import math
|
||||||
|
|
||||||
assert 1+2j == complex(1, 2) == 2j+1
|
assert 1+2j == complex(1, 2) == 2j+1
|
||||||
@ -36,3 +36,6 @@ assert repr(nanj) == '(0.0+nanj)', nanj
|
|||||||
assert repr(-nanj) == '(0.0+nanj)', -nanj
|
assert repr(-nanj) == '(0.0+nanj)', -nanj
|
||||||
assert repr(infj) == '(0.0+infj)', infj
|
assert repr(infj) == '(0.0+infj)', infj
|
||||||
assert repr(-infj) == '(0.0-infj)', -infj
|
assert repr(-infj) == '(0.0-infj)', -infj
|
||||||
|
|
||||||
|
assert math.log(1) == 0.0
|
||||||
|
assert isclose(log(10+5j), 2.4141568686511508+0.4636476090008061j)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user