@@ -81,34 +81,38 @@ public function multiply($other) {
8181 * @return math.BigNum
8282 */
8383 public function divide ($ other ) {
84- if ($ other instanceof self) {
85- if (null === ($ r = bcdiv ($ this ->num , $ other ->num , 0 ))) { // inlined
86- $ e = key (\xp::$ errors [__FILE__ ][__LINE__ - 1 ]);
87- \xp::gc (__FILE__ );
88- throw new IllegalArgumentException ($ e );
89- }
90- return new self ($ r );
91- } else if (is_int ($ other )) {
92- if (null === ($ r = bcdiv ($ this ->num , $ other , 0 ))) { // inlined
93- $ e = key (\xp::$ errors [__FILE__ ][__LINE__ - 1 ]);
94- \xp::gc (__FILE__ );
95- throw new IllegalArgumentException ($ e );
96- }
97- return new self ($ r );
98- } else if ($ other instanceof BigFloat) {
99- if (null === ($ r = bcdiv ($ this ->num , $ other ->num ))) { // inlined
100- $ e = key (\xp::$ errors [__FILE__ ][__LINE__ - 1 ]);
101- \xp::gc (__FILE__ );
102- throw new IllegalArgumentException ($ e );
103- }
104- return new BigFloat ($ r );
105- } else {
106- if (null === ($ r = bcdiv ($ this ->num , $ other ))) { // inlined
107- $ e = key (\xp::$ errors [__FILE__ ][__LINE__ - 1 ]);
108- \xp::gc (__FILE__ );
109- throw new IllegalArgumentException ($ e );
84+ try {
85+ if ($ other instanceof self) {
86+ if (null === ($ r = bcdiv ($ this ->num , $ other ->num , 0 ))) { // inlined
87+ $ e = key (\xp::$ errors [__FILE__ ][__LINE__ - 1 ]);
88+ \xp::gc (__FILE__ );
89+ throw new IllegalArgumentException ($ e );
90+ }
91+ return new self ($ r );
92+ } else if (is_int ($ other )) {
93+ if (null === ($ r = bcdiv ($ this ->num , $ other , 0 ))) { // inlined
94+ $ e = key (\xp::$ errors [__FILE__ ][__LINE__ - 1 ]);
95+ \xp::gc (__FILE__ );
96+ throw new IllegalArgumentException ($ e );
97+ }
98+ return new self ($ r );
99+ } else if ($ other instanceof BigFloat) {
100+ if (null === ($ r = bcdiv ($ this ->num , $ other ->num ))) { // inlined
101+ $ e = key (\xp::$ errors [__FILE__ ][__LINE__ - 1 ]);
102+ \xp::gc (__FILE__ );
103+ throw new IllegalArgumentException ($ e );
104+ }
105+ return new BigFloat ($ r );
106+ } else {
107+ if (null === ($ r = bcdiv ($ this ->num , $ other ))) { // inlined
108+ $ e = key (\xp::$ errors [__FILE__ ][__LINE__ - 1 ]);
109+ \xp::gc (__FILE__ );
110+ throw new IllegalArgumentException ($ e );
111+ }
112+ return new BigFloat ($ r );
110113 }
111- return new BigFloat ($ r );
114+ } catch (\Error $ e ) { // PHP 8.0
115+ throw new IllegalArgumentException ($ e ->getMessage ());
112116 }
113117 }
114118
@@ -149,12 +153,16 @@ public function multiply0($other) {
149153 * @return math.BigNum
150154 */
151155 public function divide0 ($ other ) {
152- if (null === ($ r = bcdiv ($ this ->num , $ other instanceof self ? $ other ->num : $ other , 0 ))) {
153- $ e = key (\xp::$ errors [__FILE__ ][__LINE__ - 1 ]);
154- \xp::gc (__FILE__ );
155- throw new IllegalArgumentException ($ e );
156+ try {
157+ if (null === ($ r = bcdiv ($ this ->num , $ other instanceof self ? $ other ->num : $ other , 0 ))) {
158+ $ e = key (\xp::$ errors [__FILE__ ][__LINE__ - 1 ]);
159+ \xp::gc (__FILE__ );
160+ throw new IllegalArgumentException ($ e );
161+ }
162+ return new self ($ r );
163+ } catch (\Error $ e ) { // PHP 8.0
164+ throw new IllegalArgumentException ($ e ->getMessage ());
156165 }
157- return new self ($ r );
158166 }
159167
160168 /**
@@ -189,12 +197,16 @@ public function power($other) {
189197 * @return math.BigNum
190198 */
191199 public function modulo ($ other ) {
192- if (null === ($ r = bcmod ($ this ->num , $ other instanceof self ? $ other ->num : $ other ))) {
193- $ e = key (\xp::$ errors [__FILE__ ][__LINE__ - 1 ]);
194- \xp::gc (__FILE__ );
195- throw new IllegalArgumentException ($ e );
200+ try {
201+ if (null === ($ r = bcmod ($ this ->num , $ other instanceof self ? $ other ->num : $ other ))) {
202+ $ e = key (\xp::$ errors [__FILE__ ][__LINE__ - 1 ]);
203+ \xp::gc (__FILE__ );
204+ throw new IllegalArgumentException ($ e );
205+ }
206+ return new $ this ($ r );
207+ } catch (\Error $ e ) { // PHP 8.0
208+ throw new IllegalArgumentException ($ e ->getMessage ());
196209 }
197- return new $ this ($ r );
198210 }
199211
200212 /**
0 commit comments