@@ -490,12 +490,10 @@ void f$bcscale(int64_t scale) noexcept {
490490 }
491491}
492492
493- string f$bcdiv(const string& lhs_str, const string& rhs_str, int64_t scale ) noexcept {
493+ string f$bcdiv(const string& lhs_str, const string& rhs_str, Optional< int64_t > opt_scale ) noexcept {
494494 auto & math_lib_context{MathLibContext::get ()};
495495 const auto & math_lib_constants{MathLibConstants::get ()};
496- if (scale == std::numeric_limits<int64_t >::min ()) {
497- scale = math_lib_context.bc_scale ;
498- }
496+ int64_t scale{!opt_scale.has_value () ? math_lib_context.bc_scale : opt_scale.val ()};
499497 if (scale < 0 ) {
500498 php_warning (" Wrong parameter scale = %" PRIi64 " in function bcdiv" , scale);
501499 scale = 0 ;
@@ -533,12 +531,10 @@ static string scale_num(const string& num, int64_t scale) noexcept {
533531 return num;
534532}
535533
536- string f$bcmod(const string& lhs_str, const string& rhs_str, int64_t scale ) noexcept {
534+ string f$bcmod(const string& lhs_str, const string& rhs_str, Optional< int64_t > opt_scale ) noexcept {
537535 auto & math_lib_context{MathLibContext::get ()};
538536 const auto & math_lib_constants{MathLibConstants::get ()};
539- if (scale == std::numeric_limits<int64_t >::min ()) {
540- scale = math_lib_context.bc_scale ;
541- }
537+ int64_t scale{!opt_scale.has_value () ? math_lib_context.bc_scale : opt_scale.val ()};
542538 if (scale < 0 ) {
543539 php_warning (" Wrong parameter scale = %" PRIi64 " in function bcmod" , scale);
544540 scale = 0 ;
@@ -600,12 +596,10 @@ static std::pair<std::int64_t, bool> bc_num2int(const bcmath_impl_::BcNum& num)
600596 return {ingeger, true };
601597}
602598
603- string f$bcpow(const string& lhs_str, const string& rhs_str, int64_t scale ) noexcept {
599+ string f$bcpow(const string& lhs_str, const string& rhs_str, Optional< int64_t > opt_scale ) noexcept {
604600 auto & math_lib_context{MathLibContext::get ()};
605601 const auto & math_lib_constants{MathLibConstants::get ()};
606- if (scale == std::numeric_limits<int64_t >::min ()) {
607- scale = math_lib_context.bc_scale ;
608- }
602+ int64_t scale{!opt_scale.has_value () ? math_lib_context.bc_scale : opt_scale.val ()};
609603 if (scale < 0 ) {
610604 php_warning (" Wrong parameter scale = %" PRIi64 " in function bcpow" , scale);
611605 scale = 0 ;
@@ -681,18 +675,17 @@ string f$bcpow(const string& lhs_str, const string& rhs_str, int64_t scale) noex
681675 return f$bcadd (result, math_lib_constants.ZERO , scale);
682676}
683677
684- string f$bcadd(const string& lhs_str, const string& rhs_str, int64_t scale ) noexcept {
678+ string f$bcadd(const string& lhs_str, const string& rhs_str, Optional< int64_t > opt_scale ) noexcept {
685679 const auto & math_lib_constants{MathLibConstants::get ()};
686680 if (lhs_str.empty ()) {
687- return f$bcadd (math_lib_constants.ZERO , rhs_str, scale );
681+ return f$bcadd (math_lib_constants.ZERO , rhs_str, opt_scale );
688682 }
689683 if (rhs_str.empty ()) {
690- return f$bcadd (lhs_str, math_lib_constants.ZERO , scale );
684+ return f$bcadd (lhs_str, math_lib_constants.ZERO , opt_scale );
691685 }
692686
693- if (scale == std::numeric_limits<int64_t >::min ()) {
694- scale = MathLibContext::get ().bc_scale ;
695- }
687+ int64_t scale{!opt_scale.has_value () ? MathLibContext::get ().bc_scale : opt_scale.val ()};
688+
696689 if (scale < 0 ) {
697690 php_warning (" Wrong parameter scale = %" PRIi64 " in function bcadd" , scale);
698691 scale = 0 ;
@@ -713,18 +706,15 @@ string f$bcadd(const string& lhs_str, const string& rhs_str, int64_t scale) noex
713706 return bc_add (lhs, rhs, static_cast <int >(scale));
714707}
715708
716- string f$bcsub(const string& lhs_str, const string& rhs_str, int64_t scale ) noexcept {
709+ string f$bcsub(const string& lhs_str, const string& rhs_str, Optional< int64_t > opt_scale ) noexcept {
717710 const auto & math_lib_constants{MathLibConstants::get ()};
718711 if (lhs_str.empty ()) {
719- return f$bcsub (math_lib_constants.ZERO , rhs_str, scale );
712+ return f$bcsub (math_lib_constants.ZERO , rhs_str, opt_scale );
720713 }
721714 if (rhs_str.empty ()) {
722- return f$bcsub (lhs_str, math_lib_constants.ZERO , scale);
723- }
724-
725- if (scale == std::numeric_limits<int64_t >::min ()) {
726- scale = MathLibContext::get ().bc_scale ;
715+ return f$bcsub (lhs_str, math_lib_constants.ZERO , opt_scale);
727716 }
717+ int64_t scale{!opt_scale.has_value () ? MathLibContext::get ().bc_scale : opt_scale.val ()};
728718 if (scale < 0 ) {
729719 php_warning (" Wrong parameter scale = %" PRIi64 " in function bcsub" , scale);
730720 scale = 0 ;
@@ -747,18 +737,15 @@ string f$bcsub(const string& lhs_str, const string& rhs_str, int64_t scale) noex
747737 return bc_add (lhs, rhs, static_cast <int >(scale));
748738}
749739
750- string f$bcmul(const string& lhs_str, const string& rhs_str, int64_t scale ) noexcept {
740+ string f$bcmul(const string& lhs_str, const string& rhs_str, Optional< int64_t > opt_scale ) noexcept {
751741 const auto & math_lib_constants{MathLibConstants::get ()};
752742 if (lhs_str.empty ()) {
753- return f$bcmul (math_lib_constants.ZERO , rhs_str, scale );
743+ return f$bcmul (math_lib_constants.ZERO , rhs_str, opt_scale );
754744 }
755745 if (rhs_str.empty ()) {
756- return f$bcmul (lhs_str, math_lib_constants.ZERO , scale);
757- }
758-
759- if (scale == std::numeric_limits<int64_t >::min ()) {
760- scale = MathLibContext::get ().bc_scale ;
746+ return f$bcmul (lhs_str, math_lib_constants.ZERO , opt_scale);
761747 }
748+ int64_t scale{!opt_scale.has_value () ? MathLibContext::get ().bc_scale : opt_scale.val ()};
762749 if (scale < 0 ) {
763750 php_warning (" Wrong parameter scale = %" PRIi64 " in function bcmul" , scale);
764751 scale = 0 ;
@@ -779,18 +766,16 @@ string f$bcmul(const string& lhs_str, const string& rhs_str, int64_t scale) noex
779766 return bc_mul_positive (lhs, rhs, static_cast <int >(scale), lhs.n_sign * rhs.n_sign );
780767}
781768
782- int64_t f$bccomp(const string& lhs_str, const string& rhs_str, int64_t scale ) noexcept {
769+ int64_t f$bccomp(const string& lhs_str, const string& rhs_str, Optional< int64_t > opt_scale ) noexcept {
783770 const auto & math_lib_constants{MathLibConstants::get ()};
784771 if (lhs_str.empty ()) {
785- return f$bccomp (math_lib_constants.ZERO , rhs_str, scale );
772+ return f$bccomp (math_lib_constants.ZERO , rhs_str, opt_scale );
786773 }
787774 if (rhs_str.empty ()) {
788- return f$bccomp (lhs_str, math_lib_constants.ZERO , scale );
775+ return f$bccomp (lhs_str, math_lib_constants.ZERO , opt_scale );
789776 }
790777
791- if (scale == std::numeric_limits<int64_t >::min ()) {
792- scale = MathLibContext::get ().bc_scale ;
793- }
778+ int64_t scale{!opt_scale.has_value () ? MathLibContext::get ().bc_scale : opt_scale.val ()};
794779 if (scale < 0 ) {
795780 php_warning (" Wrong parameter scale = %" PRIi64 " in function bccomp" , scale);
796781 scale = 0 ;
@@ -907,10 +892,8 @@ static std::pair<string, bool> bc_sqrt(const bcmath_impl_::BcNum& num, int scale
907892 return {bc_div_positive (guess, math_lib_constants.BC_NUM_ONE , rscale, 1 ), true };
908893}
909894
910- string f$bcsqrt(const string& num_str, int64_t scale) noexcept {
911- if (scale == std::numeric_limits<int64_t >::min ()) {
912- scale = MathLibContext::get ().bc_scale ;
913- }
895+ string f$bcsqrt(const string& num_str, Optional<int64_t > opt_scale) noexcept {
896+ int64_t scale{!opt_scale.has_value () ? MathLibContext::get ().bc_scale : opt_scale.val ()};
914897 if (scale < 0 ) {
915898 php_warning (" Wrong parameter scale = %" PRIi64 " in function bcsqrt" , scale);
916899 scale = 0 ;
0 commit comments