@@ -156,22 +156,24 @@ static void php_str2num(bc_num *num, char *str)
156
156
PHP_FUNCTION (bcadd )
157
157
{
158
158
zend_string * left , * right ;
159
- zend_long scale_param = 0 ;
159
+ zend_long scale_param ;
160
+ zend_bool scale_param_is_null = 1 ;
160
161
bc_num first , second , result ;
161
- int scale = BCG ( bc_precision ) ;
162
+ int scale ;
162
163
163
164
ZEND_PARSE_PARAMETERS_START (2 , 3 )
164
165
Z_PARAM_STR (left )
165
166
Z_PARAM_STR (right )
166
167
Z_PARAM_OPTIONAL
167
- Z_PARAM_LONG (scale_param )
168
+ Z_PARAM_LONG_OR_NULL (scale_param , scale_param_is_null )
168
169
ZEND_PARSE_PARAMETERS_END ();
169
170
170
- if (ZEND_NUM_ARGS () == 3 ) {
171
- if (scale_param < 0 || scale_param > INT_MAX ) {
172
- zend_argument_value_error (3 , "must be between 0 and %d" , INT_MAX );
173
- RETURN_THROWS ();
174
- }
171
+ if (scale_param_is_null ) {
172
+ scale = BCG (bc_precision );
173
+ } else if (scale_param < 0 || scale_param > INT_MAX ) {
174
+ zend_argument_value_error (3 , "must be between 0 and %d" , INT_MAX );
175
+ RETURN_THROWS ();
176
+ } else {
175
177
scale = (int ) scale_param ;
176
178
}
177
179
@@ -195,22 +197,24 @@ PHP_FUNCTION(bcadd)
195
197
PHP_FUNCTION (bcsub )
196
198
{
197
199
zend_string * left , * right ;
198
- zend_long scale_param = 0 ;
200
+ zend_long scale_param ;
201
+ zend_bool scale_param_is_null = 1 ;
199
202
bc_num first , second , result ;
200
- int scale = BCG ( bc_precision ) ;
203
+ int scale ;
201
204
202
205
ZEND_PARSE_PARAMETERS_START (2 , 3 )
203
206
Z_PARAM_STR (left )
204
207
Z_PARAM_STR (right )
205
208
Z_PARAM_OPTIONAL
206
- Z_PARAM_LONG (scale_param )
209
+ Z_PARAM_LONG_OR_NULL (scale_param , scale_param_is_null )
207
210
ZEND_PARSE_PARAMETERS_END ();
208
211
209
- if (ZEND_NUM_ARGS () == 3 ) {
210
- if (scale_param < 0 || scale_param > INT_MAX ) {
211
- zend_argument_value_error (3 , "must be between 0 and %d" , INT_MAX );
212
- RETURN_THROWS ();
213
- }
212
+ if (scale_param_is_null ) {
213
+ scale = BCG (bc_precision );
214
+ } else if (scale_param < 0 || scale_param > INT_MAX ) {
215
+ zend_argument_value_error (3 , "must be between 0 and %d" , INT_MAX );
216
+ RETURN_THROWS ();
217
+ } else {
214
218
scale = (int ) scale_param ;
215
219
}
216
220
@@ -234,22 +238,24 @@ PHP_FUNCTION(bcsub)
234
238
PHP_FUNCTION (bcmul )
235
239
{
236
240
zend_string * left , * right ;
237
- zend_long scale_param = 0 ;
241
+ zend_long scale_param ;
242
+ zend_bool scale_param_is_null = 1 ;
238
243
bc_num first , second , result ;
239
- int scale = BCG ( bc_precision ) ;
244
+ int scale ;
240
245
241
246
ZEND_PARSE_PARAMETERS_START (2 , 3 )
242
247
Z_PARAM_STR (left )
243
248
Z_PARAM_STR (right )
244
249
Z_PARAM_OPTIONAL
245
- Z_PARAM_LONG (scale_param )
250
+ Z_PARAM_LONG_OR_NULL (scale_param , scale_param_is_null )
246
251
ZEND_PARSE_PARAMETERS_END ();
247
252
248
- if (ZEND_NUM_ARGS () == 3 ) {
249
- if (scale_param < 0 || scale_param > INT_MAX ) {
250
- zend_argument_value_error (3 , "must be between 0 and %d" , INT_MAX );
251
- RETURN_THROWS ();
252
- }
253
+ if (scale_param_is_null ) {
254
+ scale = BCG (bc_precision );
255
+ } else if (scale_param < 0 || scale_param > INT_MAX ) {
256
+ zend_argument_value_error (3 , "must be between 0 and %d" , INT_MAX );
257
+ RETURN_THROWS ();
258
+ } else {
253
259
scale = (int ) scale_param ;
254
260
}
255
261
@@ -273,22 +279,24 @@ PHP_FUNCTION(bcmul)
273
279
PHP_FUNCTION (bcdiv )
274
280
{
275
281
zend_string * left , * right ;
276
- zend_long scale_param = 0 ;
282
+ zend_long scale_param ;
283
+ zend_bool scale_param_is_null = 1 ;
277
284
bc_num first , second , result ;
278
285
int scale = BCG (bc_precision );
279
286
280
287
ZEND_PARSE_PARAMETERS_START (2 , 3 )
281
288
Z_PARAM_STR (left )
282
289
Z_PARAM_STR (right )
283
290
Z_PARAM_OPTIONAL
284
- Z_PARAM_LONG (scale_param )
291
+ Z_PARAM_LONG_OR_NULL (scale_param , scale_param_is_null )
285
292
ZEND_PARSE_PARAMETERS_END ();
286
293
287
- if (ZEND_NUM_ARGS () == 3 ) {
288
- if (scale_param < 0 || scale_param > INT_MAX ) {
289
- zend_argument_value_error (3 , "must be between 0 and %d" , INT_MAX );
290
- RETURN_THROWS ();
291
- }
294
+ if (scale_param_is_null ) {
295
+ scale = BCG (bc_precision );
296
+ } else if (scale_param < 0 || scale_param > INT_MAX ) {
297
+ zend_argument_value_error (3 , "must be between 0 and %d" , INT_MAX );
298
+ RETURN_THROWS ();
299
+ } else {
292
300
scale = (int ) scale_param ;
293
301
}
294
302
@@ -319,22 +327,24 @@ PHP_FUNCTION(bcdiv)
319
327
PHP_FUNCTION (bcmod )
320
328
{
321
329
zend_string * left , * right ;
322
- zend_long scale_param = 0 ;
330
+ zend_long scale_param ;
331
+ zend_bool scale_param_is_null = 1 ;
323
332
bc_num first , second , result ;
324
333
int scale = BCG (bc_precision );
325
334
326
335
ZEND_PARSE_PARAMETERS_START (2 , 3 )
327
336
Z_PARAM_STR (left )
328
337
Z_PARAM_STR (right )
329
338
Z_PARAM_OPTIONAL
330
- Z_PARAM_LONG (scale_param )
339
+ Z_PARAM_LONG_OR_NULL (scale_param , scale_param_is_null )
331
340
ZEND_PARSE_PARAMETERS_END ();
332
341
333
- if (ZEND_NUM_ARGS () == 3 ) {
334
- if (scale_param < 0 || scale_param > INT_MAX ) {
335
- zend_argument_value_error (3 , "must be between 0 and %d" , INT_MAX );
336
- RETURN_THROWS ();
337
- }
342
+ if (scale_param_is_null ) {
343
+ scale = BCG (bc_precision );
344
+ } else if (scale_param < 0 || scale_param > INT_MAX ) {
345
+ zend_argument_value_error (3 , "must be between 0 and %d" , INT_MAX );
346
+ RETURN_THROWS ();
347
+ } else {
338
348
scale = (int ) scale_param ;
339
349
}
340
350
@@ -356,7 +366,6 @@ PHP_FUNCTION(bcmod)
356
366
bc_free_num (& first );
357
367
bc_free_num (& second );
358
368
bc_free_num (& result );
359
- return ;
360
369
}
361
370
/* }}} */
362
371
@@ -365,7 +374,8 @@ PHP_FUNCTION(bcmod)
365
374
PHP_FUNCTION (bcpowmod )
366
375
{
367
376
zend_string * left , * right , * modulus ;
368
- zend_long scale_param = 0 ;
377
+ zend_long scale_param ;
378
+ zend_bool scale_param_is_null = 1 ;
369
379
bc_num first , second , mod , result ;
370
380
int scale = BCG (bc_precision );
371
381
@@ -374,14 +384,15 @@ PHP_FUNCTION(bcpowmod)
374
384
Z_PARAM_STR (right )
375
385
Z_PARAM_STR (modulus )
376
386
Z_PARAM_OPTIONAL
377
- Z_PARAM_LONG (scale_param )
387
+ Z_PARAM_LONG_OR_NULL (scale_param , scale_param_is_null )
378
388
ZEND_PARSE_PARAMETERS_END ();
379
389
380
- if (ZEND_NUM_ARGS () == 4 ) {
381
- if (scale_param < 0 || scale_param > INT_MAX ) {
382
- zend_argument_value_error (4 , "must be between 0 and %d" , INT_MAX );
383
- RETURN_THROWS ();
384
- }
390
+ if (scale_param_is_null ) {
391
+ scale = BCG (bc_precision );
392
+ } else if (scale_param < 0 || scale_param > INT_MAX ) {
393
+ zend_argument_value_error (4 , "must be between 0 and %d" , INT_MAX );
394
+ RETURN_THROWS ();
395
+ } else {
385
396
scale = (int ) scale_param ;
386
397
}
387
398
@@ -403,7 +414,6 @@ PHP_FUNCTION(bcpowmod)
403
414
bc_free_num (& second );
404
415
bc_free_num (& mod );
405
416
bc_free_num (& result );
406
- return ;
407
417
}
408
418
/* }}} */
409
419
@@ -412,22 +422,24 @@ PHP_FUNCTION(bcpowmod)
412
422
PHP_FUNCTION (bcpow )
413
423
{
414
424
zend_string * left , * right ;
415
- zend_long scale_param = 0 ;
425
+ zend_long scale_param ;
426
+ zend_bool scale_param_is_null = 1 ;
416
427
bc_num first , second , result ;
417
428
int scale = BCG (bc_precision );
418
429
419
430
ZEND_PARSE_PARAMETERS_START (2 , 3 )
420
431
Z_PARAM_STR (left )
421
432
Z_PARAM_STR (right )
422
433
Z_PARAM_OPTIONAL
423
- Z_PARAM_LONG (scale_param )
434
+ Z_PARAM_LONG_OR_NULL (scale_param , scale_param_is_null )
424
435
ZEND_PARSE_PARAMETERS_END ();
425
436
426
- if (ZEND_NUM_ARGS () == 3 ) {
427
- if (scale_param < 0 || scale_param > INT_MAX ) {
428
- zend_argument_value_error (3 , "must be between 0 and %d" , INT_MAX );
429
- RETURN_THROWS ();
430
- }
437
+ if (scale_param_is_null ) {
438
+ scale = BCG (bc_precision );
439
+ } else if (scale_param < 0 || scale_param > INT_MAX ) {
440
+ zend_argument_value_error (3 , "must be between 0 and %d" , INT_MAX );
441
+ RETURN_THROWS ();
442
+ } else {
431
443
scale = (int ) scale_param ;
432
444
}
433
445
@@ -442,7 +454,6 @@ PHP_FUNCTION(bcpow)
442
454
bc_free_num (& first );
443
455
bc_free_num (& second );
444
456
bc_free_num (& result );
445
- return ;
446
457
}
447
458
/* }}} */
448
459
@@ -451,21 +462,23 @@ PHP_FUNCTION(bcpow)
451
462
PHP_FUNCTION (bcsqrt )
452
463
{
453
464
zend_string * left ;
454
- zend_long scale_param = 0 ;
465
+ zend_long scale_param ;
466
+ zend_bool scale_param_is_null = 1 ;
455
467
bc_num result ;
456
468
int scale = BCG (bc_precision );
457
469
458
470
ZEND_PARSE_PARAMETERS_START (1 , 2 )
459
471
Z_PARAM_STR (left )
460
472
Z_PARAM_OPTIONAL
461
- Z_PARAM_LONG (scale_param )
473
+ Z_PARAM_LONG_OR_NULL (scale_param , scale_param_is_null )
462
474
ZEND_PARSE_PARAMETERS_END ();
463
475
464
- if (ZEND_NUM_ARGS () == 2 ) {
465
- if (scale_param < 0 || scale_param > INT_MAX ) {
466
- zend_argument_value_error (2 , "must be between 0 and %d" , INT_MAX );
467
- RETURN_THROWS ();
468
- }
476
+ if (scale_param_is_null ) {
477
+ scale = BCG (bc_precision );
478
+ } else if (scale_param < 0 || scale_param > INT_MAX ) {
479
+ zend_argument_value_error (2 , "must be between 0 and %d" , INT_MAX );
480
+ RETURN_THROWS ();
481
+ } else {
469
482
scale = (int ) scale_param ;
470
483
}
471
484
@@ -488,22 +501,24 @@ PHP_FUNCTION(bcsqrt)
488
501
PHP_FUNCTION (bccomp )
489
502
{
490
503
zend_string * left , * right ;
491
- zend_long scale_param = 0 ;
504
+ zend_long scale_param ;
505
+ zend_bool scale_param_is_null = 1 ;
492
506
bc_num first , second ;
493
507
int scale = BCG (bc_precision );
494
508
495
509
ZEND_PARSE_PARAMETERS_START (2 , 3 )
496
510
Z_PARAM_STR (left )
497
511
Z_PARAM_STR (right )
498
512
Z_PARAM_OPTIONAL
499
- Z_PARAM_LONG (scale_param )
513
+ Z_PARAM_LONG_OR_NULL (scale_param , scale_param_is_null )
500
514
ZEND_PARSE_PARAMETERS_END ();
501
515
502
- if (ZEND_NUM_ARGS () == 3 ) {
503
- if (scale_param < 0 || scale_param > INT_MAX ) {
504
- zend_argument_value_error (3 , "must be between 0 and %d" , INT_MAX );
505
- RETURN_THROWS ();
506
- }
516
+ if (scale_param_is_null ) {
517
+ scale = BCG (bc_precision );
518
+ } else if (scale_param < 0 || scale_param > INT_MAX ) {
519
+ zend_argument_value_error (3 , "must be between 0 and %d" , INT_MAX );
520
+ RETURN_THROWS ();
521
+ } else {
507
522
scale = (int ) scale_param ;
508
523
}
509
524
@@ -529,19 +544,21 @@ PHP_FUNCTION(bccomp)
529
544
PHP_FUNCTION (bcscale )
530
545
{
531
546
zend_long old_scale , new_scale ;
547
+ zend_bool new_scale_is_null = 1 ;
532
548
533
549
ZEND_PARSE_PARAMETERS_START (0 , 1 )
534
550
Z_PARAM_OPTIONAL
535
- Z_PARAM_LONG (new_scale )
551
+ Z_PARAM_LONG_OR_NULL (new_scale , new_scale_is_null )
536
552
ZEND_PARSE_PARAMETERS_END ();
537
553
538
554
old_scale = BCG (bc_precision );
539
555
540
- if (ZEND_NUM_ARGS () == 1 ) {
556
+ if (! new_scale_is_null ) {
541
557
if (new_scale < 0 || new_scale > INT_MAX ) {
542
558
zend_argument_value_error (1 , "must be between 0 and %d" , INT_MAX );
543
559
RETURN_THROWS ();
544
560
}
561
+
545
562
BCG (bc_precision ) = (int ) new_scale ;
546
563
}
547
564
0 commit comments