Skip to content

Commit 0deefed

Browse files
committed
WIP
1 parent 6714a3b commit 0deefed

File tree

11 files changed

+1257
-36
lines changed

11 files changed

+1257
-36
lines changed

ext/bcmath/bcmath.c

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

ext/bcmath/bcmath.stub.php

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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)