mirror of
https://github.com/pocketpy/pocketpy
synced 2026-08-11 16:47:10 +08:00
Compare commits
No commits in common. "7fd7e2db152c12e5ada1c3e8222d55ecf8b983cb" and "f2b6d90a7214e56d61813dcc96de2cc8ce36c5f5" have entirely different histories.
7fd7e2db15
...
f2b6d90a72
@ -384,7 +384,7 @@ static bool int__abs__(int argc, py_Ref argv) {
|
|||||||
static bool float__abs__(int argc, py_Ref argv) {
|
static bool float__abs__(int argc, py_Ref argv) {
|
||||||
PY_CHECK_ARGC(1);
|
PY_CHECK_ARGC(1);
|
||||||
py_f64 val = py_tofloat(&argv[0]);
|
py_f64 val = py_tofloat(&argv[0]);
|
||||||
py_newfloat(py_retval(), dmath_fabs(val));
|
py_newfloat(py_retval(), val < 0 ? -val : val);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -447,12 +447,6 @@ static bool str_zfill(int argc, py_Ref argv) {
|
|||||||
}
|
}
|
||||||
c11_sbuf buf;
|
c11_sbuf buf;
|
||||||
c11_sbuf__ctor(&buf);
|
c11_sbuf__ctor(&buf);
|
||||||
// a leading sign is kept in front; the padding goes after it
|
|
||||||
if(self.size > 0 && (self.data[0] == '+' || self.data[0] == '-')) {
|
|
||||||
c11_sbuf__write_char(&buf, self.data[0]);
|
|
||||||
self.data++;
|
|
||||||
self.size--;
|
|
||||||
}
|
|
||||||
for(int i = 0; i < delta; i++) {
|
for(int i = 0; i < delta; i++) {
|
||||||
c11_sbuf__write_char(&buf, '0');
|
c11_sbuf__write_char(&buf, '0');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -701,11 +701,8 @@ double dmath_copysign(double x, double y) {
|
|||||||
return ux.f;
|
return ux.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/kraj/musl/blob/kraj/master/src/math/fabs.c
|
|
||||||
double dmath_fabs(double x) {
|
double dmath_fabs(double x) {
|
||||||
union Float64Bits u = { .f = x };
|
return (x < 0) ? -x : x;
|
||||||
u.i &= -1ULL/2;
|
|
||||||
return u.f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double dmath_ceil(double x) {
|
double dmath_ceil(double x) {
|
||||||
|
|||||||
@ -97,9 +97,6 @@ assert 3.4e+3 == 3400.0
|
|||||||
assert abs(1.0) == 1.0
|
assert abs(1.0) == 1.0
|
||||||
assert abs(-1.0) == 1.0
|
assert abs(-1.0) == 1.0
|
||||||
assert abs(0.0) == 0.0
|
assert abs(0.0) == 0.0
|
||||||
# abs(-0.0) is 0.0, not -0.0. `==` cannot tell them apart, so check the sign.
|
|
||||||
assert str(abs(-0.0)) == '0.0'
|
|
||||||
assert str(abs(0.0)) == '0.0'
|
|
||||||
|
|
||||||
# import math
|
# import math
|
||||||
# assert math.isnan(0/0)
|
# assert math.isnan(0/0)
|
||||||
|
|||||||
@ -112,9 +112,6 @@ assert s2.join( seq ) == "runoob"
|
|||||||
|
|
||||||
assert 'x'.zfill(5) == '0000x'
|
assert 'x'.zfill(5) == '0000x'
|
||||||
assert '568'.zfill(1) == '568'
|
assert '568'.zfill(1) == '568'
|
||||||
assert '-5'.zfill(4) == '-005'
|
|
||||||
assert '+5'.zfill(4) == '+005'
|
|
||||||
assert '-'.zfill(3) == '-00'
|
|
||||||
|
|
||||||
num = 6
|
num = 6
|
||||||
assert str(num) == '6'
|
assert str(num) == '6'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user