Skip to content

Commit 96c2ada

Browse files
committed
wip
1 parent 6714a3b commit 96c2ada

File tree

11 files changed

+1194
-36
lines changed

11 files changed

+1194
-36
lines changed

ext/bcmath/bcmath.c

Lines changed: 845 additions & 6 deletions
Large diffs are not rendered by default.

ext/bcmath/bcmath.stub.php

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,80 @@
22

33
/** @generate-class-entries */
44

5-
/** @refcount 1 */
6-
function bcadd(string $num1, string $num2, ?int $scale = null): string {}
5+
namespace {
6+
/** @refcount 1 */
7+
function bcadd(string $num1, string $num2, ?int $scale = null): string {}
78

8-
/** @refcount 1 */
9-
function bcsub(string $num1, string $num2, ?int $scale = null): string {}
9+
/** @refcount 1 */
10+
function bcsub(string $num1, string $num2, ?int $scale = null): string {}
1011

11-
/** @refcount 1 */
12-
function bcmul(string $num1, string $num2, ?int $scale = null): string {}
12+
/** @refcount 1 */
13+
function bcmul(string $num1, string $num2, ?int $scale = null): string {}
1314

14-
/** @refcount 1 */
15-
function bcdiv(string $num1, string $num2, ?int $scale = null): string {}
15+
/** @refcount 1 */
16+
function bcdiv(string $num1, string $num2, ?int $scale = null): string {}
1617

17-
/** @refcount 1 */
18-
function bcmod(string $num1, string $num2, ?int $scale = null): string {}
18+
/** @refcount 1 */
19+
function bcmod(string $num1, string $num2, ?int $scale = null): string {}
1920

20-
/** @refcount 1 */
21-
function bcpowmod(string $num, string $exponent, string $modulus, ?int $scale = null): string {}
21+
/** @refcount 1 */
22+
function bcpowmod(string $num, string $exponent, string $modulus, ?int $scale = null): string {}
2223

23-
/** @refcount 1 */
24-
function bcpow(string $num, string $exponent, ?int $scale = null): string {}
24+
/** @refcount 1 */
25+
function bcpow(string $num, string $exponent, ?int $scale = null): string {}
2526

26-
/** @refcount 1 */
27-
function bcsqrt(string $num, ?int $scale = null): string {}
27+
/** @refcount 1 */
28+
function bcsqrt(string $num, ?int $scale = null): string {}
2829

29-
function bccomp(string $num1, string $num2, ?int $scale = null): int {}
30+
function bccomp(string $num1, string $num2, ?int $scale = null): int {}
3031

31-
function bcscale(?int $scale = null): int {}
32+
function bcscale(?int $scale = null): int {}
3233

33-
/** @refcount 1 */
34-
function bcfloor(string $num): string {}
34+
/** @refcount 1 */
35+
function bcfloor(string $num): string {}
3536

36-
/** @refcount 1 */
37-
function bcceil(string $num): string {}
37+
/** @refcount 1 */
38+
function bcceil(string $num): string {}
3839

39-
/** @refcount 1 */
40-
function bcround(string $num, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): string {}
40+
/** @refcount 1 */
41+
function bcround(string $num, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): string {}
42+
}
43+
44+
namespace BcMath {
45+
final readonly class Number implements \Stringable {
46+
public string $value;
47+
public int $scale;
48+
49+
public function __construct(string|int $num) {}
50+
51+
public function add(Number|string|int $num, ?int $scale = null): Number {}
52+
53+
public function sub(Number|string|int $num, ?int $scale = null): Number {}
54+
55+
public function mul(Number|string|int $num, ?int $scale = null): Number {}
56+
57+
public function div(Number|string|int $num, ?int $scale = null): Number {}
58+
59+
public function mod(Number|string|int $num, ?int $scale = null): Number {}
60+
61+
public function powmod(Number|string|int $exponent, Number|string|int $modulus, ?int $scale = null): Number {}
62+
63+
public function pow(Number|string|int $exponent, ?int $scale = null): Number {}
64+
65+
public function sqrt(?int $scale = null): Number {}
66+
67+
public function floor(): Number {}
68+
69+
public function ceil(): Number {}
70+
71+
public function round(int $precision = 0, int $mode = PHP_ROUND_HALF_UP): Number {}
72+
73+
public function comp(Number|string|int $num, ?int $scale = null): int {}
74+
75+
public function __toString(): string {}
76+
77+
public function __serialize(): array {}
78+
79+
public function __unserialize(array $data): void {}
80+
}
81+
}

ext/bcmath/bcmath_arginfo.h

Lines changed: 118 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/bcmath/config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ if test "$PHP_BCMATH" != "no"; then
1313
libbcmath/src/divmod.c
1414
libbcmath/src/doaddsub.c
1515
libbcmath/src/floor_or_ceil.c
16+
libbcmath/src/long2num.c
1617
libbcmath/src/init.c
1718
libbcmath/src/int2num.c
1819
libbcmath/src/nearzero.c

ext/bcmath/config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARG_ENABLE("bcmath", "bc style precision math functions", "yes");
55
if (PHP_BCMATH == "yes") {
66
EXTENSION("bcmath", "bcmath.c", null, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
77
ADD_SOURCES("ext/bcmath/libbcmath/src", "add.c div.c init.c neg.c \
8-
raisemod.c sub.c compare.c divmod.c int2num.c \
8+
raisemod.c sub.c compare.c divmod.c int2num.c long2num.c \
99
num2long.c recmul.c sqrt.c zero.c doaddsub.c \
1010
floor_or_ceil.c nearzero.c num2str.c raise.c rmzero.c str2num.c \
1111
round.c convert.c", "bcmath");

ext/bcmath/libbcmath/src/bcmath.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ static inline bc_num bc_copy_num(bc_num num)
9898

9999
void bc_init_num(bc_num *num);
100100

101-
bool bc_str2num(bc_num *num, const char *str, const char *end, size_t scale, bool auto_scale);
101+
bool bc_str2num(bc_num *num, const char *str, const char *end, size_t scale, size_t *full_scale, bool auto_scale);
102+
103+
void bc_long2num(bc_num *num, zend_long lval);
102104

103105
zend_string *bc_num2str_ex(bc_num num, size_t scale);
104106

@@ -122,6 +124,8 @@ bool bc_is_near_zero(bc_num num, size_t scale);
122124

123125
bool bc_is_neg(bc_num num);
124126

127+
void bc_rm_trailing_zeros(bc_num num);
128+
125129
bc_num bc_add(bc_num n1, bc_num n2, size_t scale_min);
126130

127131
#define bc_add_ex(n1, n2, result, scale_min) do { \
@@ -146,7 +150,7 @@ bc_num bc_multiply(bc_num n1, bc_num n2, size_t scale);
146150
*(result) = mul_ex; \
147151
} while (0)
148152

149-
bool bc_divide(bc_num n1, bc_num n2, bc_num *quot, int scale);
153+
bool bc_divide(bc_num n1, bc_num n2, bc_num *quot, size_t scale);
150154

151155
bool bc_modulo(bc_num num1, bc_num num2, bc_num *resul, size_t scale);
152156

ext/bcmath/libbcmath/src/div.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ static void bc_do_div(char *n1, size_t n1_readable_len, size_t n1_bottom_extensi
295295
efree(n1_vector);
296296
}
297297

298-
bool bc_divide(bc_num n1, bc_num n2, bc_num *quot, int scale)
298+
bool bc_divide(bc_num n1, bc_num n2, bc_num *quot, size_t scale)
299299
{
300300
/* divide by zero */
301301
if (bc_is_zero(n2)) {

0 commit comments

Comments
 (0)