Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions builtin-functions/kphp-full/_functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -784,14 +784,14 @@ define('PHP_ROUND_HALF_EVEN', 123423145);
define('PHP_ROUND_HALF_ODD', 123423146);

function bcscale ($scale ::: int) ::: void;
function bcdiv ($lhs ::: string, $rhs ::: string, $scale ::: int = PHP_INT_MIN) ::: string;
function bcmod ($lhs ::: string, $rhs ::: string, $scale ::: int = PHP_INT_MIN) ::: string;
function bcpow ($lhs ::: string, $rhs ::: string, $scale ::: int = PHP_INT_MIN) ::: string;
function bcadd ($lhs ::: string, $rhs ::: string, $scale ::: int = PHP_INT_MIN) ::: string;
function bcsub ($lhs ::: string, $rhs ::: string, $scale ::: int = PHP_INT_MIN) ::: string;
function bcmul ($lhs ::: string, $rhs ::: string, $scale ::: int = PHP_INT_MIN) ::: string;
function bccomp ($lhs ::: string, $rhs ::: string, $scale ::: int = PHP_INT_MIN) ::: int;
function bcsqrt($num ::: string, $scale ::: int = PHP_INT_MIN): string;
function bcdiv ($lhs ::: string, $rhs ::: string, $scale ::: ?int = null) ::: string;
function bcmod ($lhs ::: string, $rhs ::: string, $scale ::: ?int = null) ::: string;
function bcpow ($lhs ::: string, $rhs ::: string, $scale ::: ?int = null) ::: string;
function bcadd ($lhs ::: string, $rhs ::: string, $scale ::: ?int = null) ::: string;
function bcsub ($lhs ::: string, $rhs ::: string, $scale ::: ?int = null) ::: string;
function bcmul ($lhs ::: string, $rhs ::: string, $scale ::: ?int = null) ::: string;
function bccomp ($lhs ::: string, $rhs ::: string, $scale ::: ?int = null) ::: int;
function bcsqrt($num ::: string, $scale ::: ?int = null): string;

function mysqli_errno(\mysqli $dn) ::: int;
function mysqli_error(\mysqli $dn) ::: string;
Expand Down
18 changes: 9 additions & 9 deletions builtin-functions/kphp-light/stdlib/math-functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,23 @@ function min (...$a) ::: ^1[*];
*/
function max (...$a) ::: ^1[*];

function bcadd ($lhs ::: string, $rhs ::: string, $scale ::: int = PHP_INT_MIN) ::: string;
function bcscale ($scale ::: int) ::: void;

function bccomp ($lhs ::: string, $rhs ::: string, $scale ::: int = PHP_INT_MIN) ::: int;
function bcdiv ($lhs ::: string, $rhs ::: string, $scale ::: ?int = null) ::: string;

function bcdiv ($lhs ::: string, $rhs ::: string, $scale ::: int = PHP_INT_MIN) ::: string;
function bcmod ($lhs ::: string, $rhs ::: string, $scale ::: ?int = null) ::: string;

function bcmod ($lhs ::: string, $rhs ::: string, $scale ::: int = PHP_INT_MIN) ::: string;
function bcpow ($lhs ::: string, $rhs ::: string, $scale ::: ?int = null) ::: string;

function bcpow ($lhs ::: string, $rhs ::: string, $scale ::: int = PHP_INT_MIN) ::: string;
function bcadd ($lhs ::: string, $rhs ::: string, $scale ::: ?int = null) ::: string;

function bcmul ($lhs ::: string, $rhs ::: string, $scale ::: int = PHP_INT_MIN) ::: string;
function bcsub ($lhs ::: string, $rhs ::: string, $scale ::: ?int = null) ::: string;

function bcscale ($scale ::: int) ::: void;
function bcmul ($lhs ::: string, $rhs ::: string, $scale ::: ?int = null) ::: string;

function bcsqrt($num ::: string, $scale ::: int = PHP_INT_MIN): string;
function bccomp ($lhs ::: string, $rhs ::: string, $scale ::: ?int = null) ::: int;

function bcsub ($lhs ::: string, $rhs ::: string, $scale ::: int = PHP_INT_MIN) ::: string;
function bcsqrt($num ::: string, $scale ::: ?int = null): string;

function is_nan ($v ::: float) ::: bool;

Expand Down
67 changes: 25 additions & 42 deletions runtime-common/stdlib/math/bcmath-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,10 @@ void f$bcscale(int64_t scale) noexcept {
}
}

string f$bcdiv(const string& lhs_str, const string& rhs_str, int64_t scale) noexcept {
string f$bcdiv(const string& lhs_str, const string& rhs_str, Optional<int64_t> opt_scale) noexcept {
auto& math_lib_context{MathLibContext::get()};
const auto& math_lib_constants{MathLibConstants::get()};
if (scale == std::numeric_limits<int64_t>::min()) {
scale = math_lib_context.bc_scale;
}
int64_t scale{!opt_scale.has_value() ? math_lib_context.bc_scale : opt_scale.val()};
if (scale < 0) {
php_warning("Wrong parameter scale = %" PRIi64 " in function bcdiv", scale);
scale = 0;
Expand Down Expand Up @@ -533,12 +531,10 @@ static string scale_num(const string& num, int64_t scale) noexcept {
return num;
}

string f$bcmod(const string& lhs_str, const string& rhs_str, int64_t scale) noexcept {
string f$bcmod(const string& lhs_str, const string& rhs_str, Optional<int64_t> opt_scale) noexcept {
auto& math_lib_context{MathLibContext::get()};
const auto& math_lib_constants{MathLibConstants::get()};
if (scale == std::numeric_limits<int64_t>::min()) {
scale = math_lib_context.bc_scale;
}
int64_t scale{!opt_scale.has_value() ? math_lib_context.bc_scale : opt_scale.val()};
if (scale < 0) {
php_warning("Wrong parameter scale = %" PRIi64 " in function bcmod", scale);
scale = 0;
Expand Down Expand Up @@ -600,12 +596,10 @@ static std::pair<std::int64_t, bool> bc_num2int(const bcmath_impl_::BcNum& num)
return {ingeger, true};
}

string f$bcpow(const string& lhs_str, const string& rhs_str, int64_t scale) noexcept {
string f$bcpow(const string& lhs_str, const string& rhs_str, Optional<int64_t> opt_scale) noexcept {
auto& math_lib_context{MathLibContext::get()};
const auto& math_lib_constants{MathLibConstants::get()};
if (scale == std::numeric_limits<int64_t>::min()) {
scale = math_lib_context.bc_scale;
}
int64_t scale{!opt_scale.has_value() ? math_lib_context.bc_scale : opt_scale.val()};
if (scale < 0) {
php_warning("Wrong parameter scale = %" PRIi64 " in function bcpow", scale);
scale = 0;
Expand Down Expand Up @@ -681,18 +675,17 @@ string f$bcpow(const string& lhs_str, const string& rhs_str, int64_t scale) noex
return f$bcadd(result, math_lib_constants.ZERO, scale);
}

string f$bcadd(const string& lhs_str, const string& rhs_str, int64_t scale) noexcept {
string f$bcadd(const string& lhs_str, const string& rhs_str, Optional<int64_t> opt_scale) noexcept {
const auto& math_lib_constants{MathLibConstants::get()};
if (lhs_str.empty()) {
return f$bcadd(math_lib_constants.ZERO, rhs_str, scale);
return f$bcadd(math_lib_constants.ZERO, rhs_str, opt_scale);
}
if (rhs_str.empty()) {
return f$bcadd(lhs_str, math_lib_constants.ZERO, scale);
return f$bcadd(lhs_str, math_lib_constants.ZERO, opt_scale);
}

if (scale == std::numeric_limits<int64_t>::min()) {
scale = MathLibContext::get().bc_scale;
}
int64_t scale{!opt_scale.has_value() ? MathLibContext::get().bc_scale : opt_scale.val()};

if (scale < 0) {
php_warning("Wrong parameter scale = %" PRIi64 " in function bcadd", scale);
scale = 0;
Expand All @@ -713,18 +706,15 @@ string f$bcadd(const string& lhs_str, const string& rhs_str, int64_t scale) noex
return bc_add(lhs, rhs, static_cast<int>(scale));
}

string f$bcsub(const string& lhs_str, const string& rhs_str, int64_t scale) noexcept {
string f$bcsub(const string& lhs_str, const string& rhs_str, Optional<int64_t> opt_scale) noexcept {
const auto& math_lib_constants{MathLibConstants::get()};
if (lhs_str.empty()) {
return f$bcsub(math_lib_constants.ZERO, rhs_str, scale);
return f$bcsub(math_lib_constants.ZERO, rhs_str, opt_scale);
}
if (rhs_str.empty()) {
return f$bcsub(lhs_str, math_lib_constants.ZERO, scale);
}

if (scale == std::numeric_limits<int64_t>::min()) {
scale = MathLibContext::get().bc_scale;
return f$bcsub(lhs_str, math_lib_constants.ZERO, opt_scale);
}
int64_t scale{!opt_scale.has_value() ? MathLibContext::get().bc_scale : opt_scale.val()};
if (scale < 0) {
php_warning("Wrong parameter scale = %" PRIi64 " in function bcsub", scale);
scale = 0;
Expand All @@ -747,18 +737,15 @@ string f$bcsub(const string& lhs_str, const string& rhs_str, int64_t scale) noex
return bc_add(lhs, rhs, static_cast<int>(scale));
}

string f$bcmul(const string& lhs_str, const string& rhs_str, int64_t scale) noexcept {
string f$bcmul(const string& lhs_str, const string& rhs_str, Optional<int64_t> opt_scale) noexcept {
const auto& math_lib_constants{MathLibConstants::get()};
if (lhs_str.empty()) {
return f$bcmul(math_lib_constants.ZERO, rhs_str, scale);
return f$bcmul(math_lib_constants.ZERO, rhs_str, opt_scale);
}
if (rhs_str.empty()) {
return f$bcmul(lhs_str, math_lib_constants.ZERO, scale);
}

if (scale == std::numeric_limits<int64_t>::min()) {
scale = MathLibContext::get().bc_scale;
return f$bcmul(lhs_str, math_lib_constants.ZERO, opt_scale);
}
int64_t scale{!opt_scale.has_value() ? MathLibContext::get().bc_scale : opt_scale.val()};
if (scale < 0) {
php_warning("Wrong parameter scale = %" PRIi64 " in function bcmul", scale);
scale = 0;
Expand All @@ -779,18 +766,16 @@ string f$bcmul(const string& lhs_str, const string& rhs_str, int64_t scale) noex
return bc_mul_positive(lhs, rhs, static_cast<int>(scale), lhs.n_sign * rhs.n_sign);
}

int64_t f$bccomp(const string& lhs_str, const string& rhs_str, int64_t scale) noexcept {
int64_t f$bccomp(const string& lhs_str, const string& rhs_str, Optional<int64_t> opt_scale) noexcept {
const auto& math_lib_constants{MathLibConstants::get()};
if (lhs_str.empty()) {
return f$bccomp(math_lib_constants.ZERO, rhs_str, scale);
return f$bccomp(math_lib_constants.ZERO, rhs_str, opt_scale);
}
if (rhs_str.empty()) {
return f$bccomp(lhs_str, math_lib_constants.ZERO, scale);
return f$bccomp(lhs_str, math_lib_constants.ZERO, opt_scale);
}

if (scale == std::numeric_limits<int64_t>::min()) {
scale = MathLibContext::get().bc_scale;
}
int64_t scale{!opt_scale.has_value() ? MathLibContext::get().bc_scale : opt_scale.val()};
if (scale < 0) {
php_warning("Wrong parameter scale = %" PRIi64 " in function bccomp", scale);
scale = 0;
Expand Down Expand Up @@ -907,10 +892,8 @@ static std::pair<string, bool> bc_sqrt(const bcmath_impl_::BcNum& num, int scale
return {bc_div_positive(guess, math_lib_constants.BC_NUM_ONE, rscale, 1), true};
}

string f$bcsqrt(const string& num_str, int64_t scale) noexcept {
if (scale == std::numeric_limits<int64_t>::min()) {
scale = MathLibContext::get().bc_scale;
}
string f$bcsqrt(const string& num_str, Optional<int64_t> opt_scale) noexcept {
int64_t scale{!opt_scale.has_value() ? MathLibContext::get().bc_scale : opt_scale.val()};
if (scale < 0) {
php_warning("Wrong parameter scale = %" PRIi64 " in function bcsqrt", scale);
scale = 0;
Expand Down
16 changes: 8 additions & 8 deletions runtime-common/stdlib/math/bcmath-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ std::pair<BcNum, bool> bc_parse_number(const string& num) noexcept;

void f$bcscale(int64_t scale) noexcept;

string f$bcdiv(const string& lhs_str, const string& rhs_str, int64_t scale = std::numeric_limits<int64_t>::min()) noexcept;
string f$bcdiv(const string& lhs_str, const string& rhs_str, Optional<int64_t> scale = Optional<int64_t>{}) noexcept;

string f$bcmod(const string& lhs_str, const string& rhs_str, int64_t scale = std::numeric_limits<int64_t>::min()) noexcept;
string f$bcmod(const string& lhs_str, const string& rhs_str, Optional<int64_t> scale = Optional<int64_t>{}) noexcept;

string f$bcpow(const string& lhs_str, const string& rhs_str, int64_t scale = std::numeric_limits<int64_t>::min()) noexcept;
string f$bcpow(const string& lhs_str, const string& rhs_str, Optional<int64_t> scale = Optional<int64_t>{}) noexcept;

string f$bcadd(const string& lhs_str, const string& rhs_str, int64_t scale = std::numeric_limits<int64_t>::min()) noexcept;
string f$bcadd(const string& lhs_str, const string& rhs_str, Optional<int64_t> scale = Optional<int64_t>{}) noexcept;

string f$bcsub(const string& lhs_str, const string& rhs_str, int64_t scale = std::numeric_limits<int64_t>::min()) noexcept;
string f$bcsub(const string& lhs_str, const string& rhs_str, Optional<int64_t> scale = Optional<int64_t>{}) noexcept;

string f$bcmul(const string& lhs_str, const string& rhs_str, int64_t scale = std::numeric_limits<int64_t>::min()) noexcept;
string f$bcmul(const string& lhs_str, const string& rhs_str, Optional<int64_t> scale = Optional<int64_t>{}) noexcept;

int64_t f$bccomp(const string& lhs_str, const string& rhs_str, int64_t scale = std::numeric_limits<int64_t>::min()) noexcept;
int64_t f$bccomp(const string& lhs_str, const string& rhs_str, Optional<int64_t> scale = Optional<int64_t>{}) noexcept;

string f$bcsqrt(const string& num_str, int64_t scale = std::numeric_limits<int64_t>::min()) noexcept;
string f$bcsqrt(const string& num_str, Optional<int64_t> scale = Optional<int64_t>{}) noexcept;
Loading