diff --git a/core/io/image.cpp b/core/io/image.cpp index 857a9ec6e24..86038fb271c 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -38,8 +38,6 @@ #include "core/templates/hash_map.h" #include "core/variant/dictionary.h" -#include - const char *Image::format_names[Image::FORMAT_MAX] = { "Lum8", "LumAlpha8", @@ -4418,12 +4416,12 @@ Dictionary Image::compute_image_metrics(const Ref p_compared_image, bool image_metric_mean = CLAMP(sum / total_values, 0.0f, 255.0f); image_metric_mean_squared = CLAMP(sum2 / total_values, 0.0f, 255.0f * 255.0f); - image_metric_root_mean_squared = sqrt(image_metric_mean_squared); + image_metric_root_mean_squared = std::sqrt(image_metric_mean_squared); if (!image_metric_root_mean_squared) { image_metric_peak_snr = 1e+10f; } else { - image_metric_peak_snr = CLAMP(log10(255.0f / image_metric_root_mean_squared) * 20.0f, 0.0f, 500.0f); + image_metric_peak_snr = CLAMP(std::log10(255.0f / image_metric_root_mean_squared) * 20.0f, 0.0f, 500.0f); } result["max"] = image_metric_max; result["mean"] = image_metric_mean; diff --git a/core/io/json.cpp b/core/io/json.cpp index fcb6182fc50..0945b8fea77 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -78,7 +78,7 @@ String JSON::_stringify(const Variant &p_var, const String &p_indent, int p_cur_ return String("0.0"); } - double magnitude = log10(Math::abs(num)); + double magnitude = std::log10(Math::abs(num)); int total_digits = p_full_precision ? 17 : 14; int precision = MAX(1, total_digits - (int)Math::floor(magnitude)); diff --git a/core/io/plist.cpp b/core/io/plist.cpp index b02ca8a7458..a1c1bc7835c 100644 --- a/core/io/plist.cpp +++ b/core/io/plist.cpp @@ -525,11 +525,11 @@ Ref PList::read_bplist_obj(Ref p_file, uint64_t p_offset_ } break; case 0x10: { node->data_type = PL_NODE_TYPE_INTEGER; - node->data_int = static_cast(read_bplist_var_size_int(p_file, pow(2, marker_size))); + node->data_int = static_cast(read_bplist_var_size_int(p_file, std::pow(2, marker_size))); } break; case 0x20: { node->data_type = PL_NODE_TYPE_REAL; - node->data_int = static_cast(read_bplist_var_size_int(p_file, pow(2, marker_size))); + node->data_int = static_cast(read_bplist_var_size_int(p_file, std::pow(2, marker_size))); } break; case 0x30: { node->data_type = PL_NODE_TYPE_DATE; @@ -539,7 +539,7 @@ Ref PList::read_bplist_obj(Ref p_file, uint64_t p_offset_ case 0x40: { if (marker_size == 0x0F) { uint8_t ext = p_file->get_8() & 0xF; - marker_size = read_bplist_var_size_int(p_file, pow(2, ext)); + marker_size = read_bplist_var_size_int(p_file, std::pow(2, ext)); } node->data_type = PL_NODE_TYPE_DATA; PackedByteArray buf; @@ -550,7 +550,7 @@ Ref PList::read_bplist_obj(Ref p_file, uint64_t p_offset_ case 0x50: { if (marker_size == 0x0F) { uint8_t ext = p_file->get_8() & 0xF; - marker_size = read_bplist_var_size_int(p_file, pow(2, ext)); + marker_size = read_bplist_var_size_int(p_file, std::pow(2, ext)); } node->data_type = PL_NODE_TYPE_STRING; node->data_string.resize(marker_size + 1); @@ -559,7 +559,7 @@ Ref PList::read_bplist_obj(Ref p_file, uint64_t p_offset_ case 0x60: { if (marker_size == 0x0F) { uint8_t ext = p_file->get_8() & 0xF; - marker_size = read_bplist_var_size_int(p_file, pow(2, ext)); + marker_size = read_bplist_var_size_int(p_file, std::pow(2, ext)); } Char16String cs16; cs16.resize(marker_size + 1); @@ -577,7 +577,7 @@ Ref PList::read_bplist_obj(Ref p_file, uint64_t p_offset_ case 0xC0: { if (marker_size == 0x0F) { uint8_t ext = p_file->get_8() & 0xF; - marker_size = read_bplist_var_size_int(p_file, pow(2, ext)); + marker_size = read_bplist_var_size_int(p_file, std::pow(2, ext)); } uint64_t pos = p_file->get_position(); @@ -594,7 +594,7 @@ Ref PList::read_bplist_obj(Ref p_file, uint64_t p_offset_ case 0xD0: { if (marker_size == 0x0F) { uint8_t ext = p_file->get_8() & 0xF; - marker_size = read_bplist_var_size_int(p_file, pow(2, ext)); + marker_size = read_bplist_var_size_int(p_file, std::pow(2, ext)); } uint64_t pos = p_file->get_position(); diff --git a/core/math/basis.cpp b/core/math/basis.cpp index c14f32bf9c7..f1d5832537c 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -262,7 +262,7 @@ void Basis::scale_orthogonal(const Vector3 &p_scale) { Basis Basis::scaled_orthogonal(const Vector3 &p_scale) const { Basis m = *this; Vector3 s = Vector3(-1, -1, -1) + p_scale; - bool sign = signbit(s.x + s.y + s.z); + bool sign = std::signbit(s.x + s.y + s.z); Basis b = m.orthonormalized(); s = b.xform_inv(s); Vector3 dots; @@ -271,7 +271,7 @@ Basis Basis::scaled_orthogonal(const Vector3 &p_scale) const { dots[j] += s[i] * Math::abs(m.get_column(i).normalized().dot(b.get_column(j))); } } - if (sign != signbit(dots.x + dots.y + dots.z)) { + if (sign != std::signbit(dots.x + dots.y + dots.z)) { dots = -dots; } m.scale_local(Vector3(1, 1, 1) + dots); @@ -477,7 +477,7 @@ Vector3 Basis::get_euler(EulerOrder p_order) const { if (rows[1][0] == 0 && rows[0][1] == 0 && rows[1][2] == 0 && rows[2][1] == 0 && rows[1][1] == 1) { // return the simplest form (human friendlier in editor and scripts) euler.x = 0; - euler.y = atan2(rows[0][2], rows[0][0]); + euler.y = std::atan2(rows[0][2], rows[0][0]); euler.z = 0; } else { euler.x = Math::atan2(-rows[1][2], rows[2][2]); @@ -542,22 +542,22 @@ Vector3 Basis::get_euler(EulerOrder p_order) const { // is this a pure X rotation? if (rows[1][0] == 0 && rows[0][1] == 0 && rows[0][2] == 0 && rows[2][0] == 0 && rows[0][0] == 1) { // return the simplest form (human friendlier in editor and scripts) - euler.x = atan2(-m12, rows[1][1]); + euler.x = std::atan2(-m12, rows[1][1]); euler.y = 0; euler.z = 0; } else { - euler.x = asin(-m12); - euler.y = atan2(rows[0][2], rows[2][2]); - euler.z = atan2(rows[1][0], rows[1][1]); + euler.x = std::asin(-m12); + euler.y = std::atan2(rows[0][2], rows[2][2]); + euler.z = std::atan2(rows[1][0], rows[1][1]); } } else { // m12 == -1 euler.x = Math::PI * 0.5f; - euler.y = atan2(rows[0][1], rows[0][0]); + euler.y = std::atan2(rows[0][1], rows[0][0]); euler.z = 0; } } else { // m12 == 1 euler.x = -Math::PI * 0.5f; - euler.y = -atan2(rows[0][1], rows[0][0]); + euler.y = -std::atan2(rows[0][1], rows[0][0]); euler.z = 0; } diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 56027765124..971ecd5aeac 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -34,37 +34,37 @@ #include "core/math/math_defs.h" #include "core/typedefs.h" -#include -#include +#include +#include namespace Math { _ALWAYS_INLINE_ double sin(double p_x) { - return ::sin(p_x); + return std::sin(p_x); } _ALWAYS_INLINE_ float sin(float p_x) { - return ::sinf(p_x); + return std::sin(p_x); } _ALWAYS_INLINE_ double cos(double p_x) { - return ::cos(p_x); + return std::cos(p_x); } _ALWAYS_INLINE_ float cos(float p_x) { - return ::cosf(p_x); + return std::cos(p_x); } _ALWAYS_INLINE_ double tan(double p_x) { - return ::tan(p_x); + return std::tan(p_x); } _ALWAYS_INLINE_ float tan(float p_x) { - return ::tanf(p_x); + return std::tan(p_x); } _ALWAYS_INLINE_ double sinh(double p_x) { - return ::sinh(p_x); + return std::sinh(p_x); } _ALWAYS_INLINE_ float sinh(float p_x) { - return ::sinhf(p_x); + return std::sinh(p_x); } _ALWAYS_INLINE_ double sinc(double p_x) { @@ -82,212 +82,156 @@ _ALWAYS_INLINE_ float sincn(float p_x) { } _ALWAYS_INLINE_ double cosh(double p_x) { - return ::cosh(p_x); + return std::cosh(p_x); } _ALWAYS_INLINE_ float cosh(float p_x) { - return ::coshf(p_x); + return std::cosh(p_x); } _ALWAYS_INLINE_ double tanh(double p_x) { - return ::tanh(p_x); + return std::tanh(p_x); } _ALWAYS_INLINE_ float tanh(float p_x) { - return ::tanhf(p_x); + return std::tanh(p_x); } // Always does clamping so always safe to use. _ALWAYS_INLINE_ double asin(double p_x) { - return p_x < -1 ? (-PI / 2) : (p_x > 1 ? (PI / 2) : ::asin(p_x)); + return p_x < -1 ? (-PI / 2) : (p_x > 1 ? (PI / 2) : std::asin(p_x)); } _ALWAYS_INLINE_ float asin(float p_x) { - return p_x < -1 ? (-(float)PI / 2) : (p_x > 1 ? ((float)PI / 2) : ::asinf(p_x)); + return p_x < -1 ? (-(float)PI / 2) : (p_x > 1 ? ((float)PI / 2) : std::asin(p_x)); } // Always does clamping so always safe to use. _ALWAYS_INLINE_ double acos(double p_x) { - return p_x < -1 ? PI : (p_x > 1 ? 0 : ::acos(p_x)); + return p_x < -1 ? PI : (p_x > 1 ? 0 : std::acos(p_x)); } _ALWAYS_INLINE_ float acos(float p_x) { - return p_x < -1 ? (float)PI : (p_x > 1 ? 0 : ::acosf(p_x)); + return p_x < -1 ? (float)PI : (p_x > 1 ? 0 : std::acos(p_x)); } _ALWAYS_INLINE_ double atan(double p_x) { - return ::atan(p_x); + return std::atan(p_x); } _ALWAYS_INLINE_ float atan(float p_x) { - return ::atanf(p_x); + return std::atan(p_x); } _ALWAYS_INLINE_ double atan2(double p_y, double p_x) { - return ::atan2(p_y, p_x); + return std::atan2(p_y, p_x); } _ALWAYS_INLINE_ float atan2(float p_y, float p_x) { - return ::atan2f(p_y, p_x); + return std::atan2(p_y, p_x); } _ALWAYS_INLINE_ double asinh(double p_x) { - return ::asinh(p_x); + return std::asinh(p_x); } _ALWAYS_INLINE_ float asinh(float p_x) { - return ::asinhf(p_x); + return std::asinh(p_x); } // Always does clamping so always safe to use. _ALWAYS_INLINE_ double acosh(double p_x) { - return p_x < 1 ? 0 : ::acosh(p_x); + return p_x < 1 ? 0 : std::acosh(p_x); } _ALWAYS_INLINE_ float acosh(float p_x) { - return p_x < 1 ? 0 : ::acoshf(p_x); + return p_x < 1 ? 0 : std::acosh(p_x); } // Always does clamping so always safe to use. _ALWAYS_INLINE_ double atanh(double p_x) { - return p_x <= -1 ? -INF : (p_x >= 1 ? INF : ::atanh(p_x)); + return p_x <= -1 ? -INF : (p_x >= 1 ? INF : std::atanh(p_x)); } _ALWAYS_INLINE_ float atanh(float p_x) { - return p_x <= -1 ? (float)-INF : (p_x >= 1 ? (float)INF : ::atanhf(p_x)); + return p_x <= -1 ? (float)-INF : (p_x >= 1 ? (float)INF : std::atanh(p_x)); } _ALWAYS_INLINE_ double sqrt(double p_x) { - return ::sqrt(p_x); + return std::sqrt(p_x); } _ALWAYS_INLINE_ float sqrt(float p_x) { - return ::sqrtf(p_x); + return std::sqrt(p_x); } _ALWAYS_INLINE_ double fmod(double p_x, double p_y) { - return ::fmod(p_x, p_y); + return std::fmod(p_x, p_y); } _ALWAYS_INLINE_ float fmod(float p_x, float p_y) { - return ::fmodf(p_x, p_y); + return std::fmod(p_x, p_y); } _ALWAYS_INLINE_ double modf(double p_x, double *r_y) { - return ::modf(p_x, r_y); + return std::modf(p_x, r_y); } _ALWAYS_INLINE_ float modf(float p_x, float *r_y) { - return ::modff(p_x, r_y); + return std::modf(p_x, r_y); } _ALWAYS_INLINE_ double floor(double p_x) { - return ::floor(p_x); + return std::floor(p_x); } _ALWAYS_INLINE_ float floor(float p_x) { - return ::floorf(p_x); + return std::floor(p_x); } _ALWAYS_INLINE_ double ceil(double p_x) { - return ::ceil(p_x); + return std::ceil(p_x); } _ALWAYS_INLINE_ float ceil(float p_x) { - return ::ceilf(p_x); + return std::ceil(p_x); } _ALWAYS_INLINE_ double pow(double p_x, double p_y) { - return ::pow(p_x, p_y); + return std::pow(p_x, p_y); } _ALWAYS_INLINE_ float pow(float p_x, float p_y) { - return ::powf(p_x, p_y); + return std::pow(p_x, p_y); } _ALWAYS_INLINE_ double log(double p_x) { - return ::log(p_x); + return std::log(p_x); } _ALWAYS_INLINE_ float log(float p_x) { - return ::logf(p_x); + return std::log(p_x); } _ALWAYS_INLINE_ double log1p(double p_x) { - return ::log1p(p_x); + return std::log1p(p_x); } _ALWAYS_INLINE_ float log1p(float p_x) { - return ::log1pf(p_x); + return std::log1p(p_x); } _ALWAYS_INLINE_ double log2(double p_x) { - return ::log2(p_x); + return std::log2(p_x); } _ALWAYS_INLINE_ float log2(float p_x) { - return ::log2f(p_x); + return std::log2(p_x); } _ALWAYS_INLINE_ double exp(double p_x) { - return ::exp(p_x); + return std::exp(p_x); } _ALWAYS_INLINE_ float exp(float p_x) { - return ::expf(p_x); + return std::exp(p_x); } _ALWAYS_INLINE_ bool is_nan(double p_val) { -#ifdef _MSC_VER - return _isnan(p_val); -#elif defined(__GNUC__) && __GNUC__ < 6 - union { - uint64_t u; - double f; - } ieee754; - ieee754.f = p_val; - // (unsigned)(0x7ff0000000000001 >> 32) : 0x7ff00000 - return ((((unsigned)(ieee754.u >> 32) & 0x7fffffff) + ((unsigned)ieee754.u != 0)) > 0x7ff00000); -#else - return isnan(p_val); -#endif + return std::isnan(p_val); } _ALWAYS_INLINE_ bool is_nan(float p_val) { -#ifdef _MSC_VER - return _isnan(p_val); -#elif defined(__GNUC__) && __GNUC__ < 6 - union { - uint32_t u; - float f; - } ieee754; - ieee754.f = p_val; - // ----------------------------------- - // (single-precision floating-point) - // NaN : s111 1111 1xxx xxxx xxxx xxxx xxxx xxxx - // : (> 0x7f800000) - // where, - // s : sign - // x : non-zero number - // ----------------------------------- - return ((ieee754.u & 0x7fffffff) > 0x7f800000); -#else - return isnan(p_val); -#endif + return std::isnan(p_val); } _ALWAYS_INLINE_ bool is_inf(double p_val) { -#ifdef _MSC_VER - return !_finite(p_val); -// use an inline implementation of isinf as a workaround for problematic libstdc++ versions from gcc 5.x era -#elif defined(__GNUC__) && __GNUC__ < 6 - union { - uint64_t u; - double f; - } ieee754; - ieee754.f = p_val; - return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 && - ((unsigned)ieee754.u == 0); -#else - return isinf(p_val); -#endif + return std::isinf(p_val); } _ALWAYS_INLINE_ bool is_inf(float p_val) { -#ifdef _MSC_VER - return !_finite(p_val); -// use an inline implementation of isinf as a workaround for problematic libstdc++ versions from gcc 5.x era -#elif defined(__GNUC__) && __GNUC__ < 6 - union { - uint32_t u; - float f; - } ieee754; - ieee754.f = p_val; - return (ieee754.u & 0x7fffffff) == 0x7f800000; -#else - return isinf(p_val); -#endif + return std::isinf(p_val); } // These methods assume (p_num + p_den) doesn't overflow. @@ -307,24 +251,17 @@ _ALWAYS_INLINE_ uint64_t division_round_up(uint64_t p_num, uint64_t p_den) { } _ALWAYS_INLINE_ bool is_finite(double p_val) { - return isfinite(p_val); + return std::isfinite(p_val); } _ALWAYS_INLINE_ bool is_finite(float p_val) { - return isfinite(p_val); -} - -_ALWAYS_INLINE_ double absd(double p_value) { - return ::fabs(p_value); -} -_ALWAYS_INLINE_ float absf(float p_value) { - return ::fabsf(p_value); + return std::isfinite(p_val); } _ALWAYS_INLINE_ double abs(double p_value) { - return absd(p_value); + return std::abs(p_value); } _ALWAYS_INLINE_ float abs(float p_value) { - return absf(p_value); + return std::abs(p_value); } _ALWAYS_INLINE_ int8_t abs(int8_t p_value) { return p_value > 0 ? p_value : -p_value; @@ -333,10 +270,10 @@ _ALWAYS_INLINE_ int16_t abs(int16_t p_value) { return p_value > 0 ? p_value : -p_value; } _ALWAYS_INLINE_ int32_t abs(int32_t p_value) { - return ::abs(p_value); + return std::abs(p_value); } _ALWAYS_INLINE_ int64_t abs(int64_t p_value) { - return ::llabs(p_value); + return std::abs(p_value); } _ALWAYS_INLINE_ double fposmod(double p_x, double p_y) { @@ -686,10 +623,10 @@ _ALWAYS_INLINE_ float db_to_linear(float p_db) { } _ALWAYS_INLINE_ double round(double p_val) { - return ::round(p_val); + return std::round(p_val); } _ALWAYS_INLINE_ float round(float p_val) { - return ::roundf(p_val); + return std::round(p_val); } _ALWAYS_INLINE_ double wrapf(double p_value, double p_min, double p_max) { @@ -760,8 +697,7 @@ int random(int p_from, int p_to); // This function should be as fast as possible and rounding mode should not matter. _ALWAYS_INLINE_ int fast_ftoi(float p_value) { - // Assuming every supported compiler has `lrint()`. - return lrintf(p_value); + return std::rint(p_value); } _ALWAYS_INLINE_ uint32_t halfbits_to_floatbits(uint16_t p_half) { diff --git a/core/math/projection.cpp b/core/math/projection.cpp index a71e44d903d..e0b8dcf815d 100644 --- a/core/math/projection.cpp +++ b/core/math/projection.cpp @@ -282,7 +282,7 @@ void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t real_t left, right, modeltranslation, ymax, xmax, frustumshift; - ymax = p_z_near * tan(Math::deg_to_rad(p_fovy_degrees / 2.0)); + ymax = p_z_near * std::tan(Math::deg_to_rad(p_fovy_degrees / 2.0)); xmax = ymax * p_aspect; frustumshift = (p_intraocular_dist / 2.0) * p_z_near / p_convergence_dist; diff --git a/core/math/quaternion.cpp b/core/math/quaternion.cpp index 6c0b491aa10..536682de8d8 100644 --- a/core/math/quaternion.cpp +++ b/core/math/quaternion.cpp @@ -148,7 +148,7 @@ Quaternion Quaternion::slerpni(const Quaternion &p_to, real_t p_weight) const { real_t dot = from.dot(p_to); - if (Math::absf(dot) > 0.9999f) { + if (Math::abs(dot) > 0.9999f) { return from; } @@ -180,11 +180,11 @@ Quaternion Quaternion::spherical_cubic_interpolate(const Quaternion &p_b, const post_q = Basis(post_q).get_rotation_quaternion(); // Flip quaternions to shortest path if necessary. - bool flip1 = signbit(from_q.dot(pre_q)); + bool flip1 = std::signbit(from_q.dot(pre_q)); pre_q = flip1 ? -pre_q : pre_q; - bool flip2 = signbit(from_q.dot(to_q)); + bool flip2 = std::signbit(from_q.dot(to_q)); to_q = flip2 ? -to_q : to_q; - bool flip3 = flip2 ? to_q.dot(post_q) <= 0 : signbit(to_q.dot(post_q)); + bool flip3 = flip2 ? to_q.dot(post_q) <= 0 : std::signbit(to_q.dot(post_q)); post_q = flip3 ? -post_q : post_q; // Calc by Expmap in from_q space. @@ -231,11 +231,11 @@ Quaternion Quaternion::spherical_cubic_interpolate_in_time(const Quaternion &p_b post_q = Basis(post_q).get_rotation_quaternion(); // Flip quaternions to shortest path if necessary. - bool flip1 = signbit(from_q.dot(pre_q)); + bool flip1 = std::signbit(from_q.dot(pre_q)); pre_q = flip1 ? -pre_q : pre_q; - bool flip2 = signbit(from_q.dot(to_q)); + bool flip2 = std::signbit(from_q.dot(to_q)); to_q = flip2 ? -to_q : to_q; - bool flip3 = flip2 ? to_q.dot(post_q) <= 0 : signbit(to_q.dot(post_q)); + bool flip3 = flip2 ? to_q.dot(post_q) <= 0 : std::signbit(to_q.dot(post_q)); post_q = flip3 ? -post_q : post_q; // Calc by Expmap in from_q space. diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h index f39cd7ab144..bfcd3eeeccb 100644 --- a/core/math/random_pcg.h +++ b/core/math/random_pcg.h @@ -30,12 +30,10 @@ #pragma once -#include "core/math/math_defs.h" +#include "core/math/math_funcs.h" #include "thirdparty/misc/pcg.h" -#include - #if defined(__GNUC__) #define CLZ32(x) __builtin_clz(x) #elif defined(_MSC_VER) @@ -46,16 +44,6 @@ static int __bsr_clz32(uint32_t x) { return 31 - index; } #define CLZ32(x) __bsr_clz32(x) -#else -#endif - -#if defined(__GNUC__) -#define LDEXP(s, e) __builtin_ldexp(s, e) -#define LDEXPF(s, e) __builtin_ldexpf(s, e) -#else -#include -#define LDEXP(s, e) ldexp(s, e) -#define LDEXPF(s, e) ldexp(s, e) #endif template @@ -110,7 +98,7 @@ public: return 0; } uint64_t significand = (((uint64_t)rand()) << 32) | rand() | 0x8000000000000001U; - return LDEXP((double)significand, -64 - CLZ32(proto_exp_offset)); + return std::ldexp((double)significand, -64 - CLZ32(proto_exp_offset)); #else #pragma message("RandomPCG::randd - intrinsic clz is not available, falling back to bit truncation") return (double)(((((uint64_t)rand()) << 32) | rand()) & 0x1FFFFFFFFFFFFFU) / (double)0x1FFFFFFFFFFFFFU; @@ -122,7 +110,7 @@ public: if (unlikely(proto_exp_offset == 0)) { return 0; } - return LDEXPF((float)(rand() | 0x80000001), -32 - CLZ32(proto_exp_offset)); + return std::ldexp((float)(rand() | 0x80000001), -32 - CLZ32(proto_exp_offset)); #else #pragma message("RandomPCG::randf - intrinsic clz is not available, falling back to bit truncation") return (float)(rand() & 0xFFFFFF) / (float)0xFFFFFF; @@ -134,14 +122,14 @@ public: if (temp < CMP_EPSILON) { temp += CMP_EPSILON; // To prevent generating of INF value in log function, resulting to return NaN value from this function. } - return p_mean + p_deviation * (cos(Math::TAU * randd()) * sqrt(-2.0 * log(temp))); // Box-Muller transform. + return p_mean + p_deviation * (std::cos(Math::TAU * randd()) * std::sqrt(-2.0 * std::log(temp))); // Box-Muller transform. } _FORCE_INLINE_ float randfn(float p_mean, float p_deviation) { float temp = randf(); if (temp < CMP_EPSILON) { temp += CMP_EPSILON; // To prevent generating of INF value in log function, resulting to return NaN value from this function. } - return p_mean + p_deviation * (cos((float)Math::TAU * randf()) * sqrt(-2.0 * log(temp))); // Box-Muller transform. + return p_mean + p_deviation * (std::cos((float)Math::TAU * randf()) * std::sqrt(-2.0 * std::log(temp))); // Box-Muller transform. } double random(double p_from, double p_to); diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index cad7d9a8343..d71fef49f44 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -1445,7 +1445,7 @@ String String::num(double p_num, int p_decimals) { } if (Math::is_inf(p_num)) { - if (signbit(p_num)) { + if (std::signbit(p_num)) { return "-inf"; } else { return "inf"; @@ -1458,7 +1458,7 @@ String String::num(double p_num, int p_decimals) { if (abs_num > 10) { // We want to align the digits to the above reasonable default, so we only // need to subtract log10 for numbers with a positive power of ten. - p_decimals -= (int)floor(log10(abs_num)); + p_decimals -= (int)std::floor(std::log10(abs_num)); } } if (p_decimals > MAX_DECIMALS) { @@ -1624,7 +1624,7 @@ String String::num_real(double p_num, bool p_trailing) { // to subtract log10 for numbers with a positive power of ten magnitude. const double abs_num = Math::abs(p_num); if (abs_num > 10) { - decimals -= (int)floor(log10(abs_num)); + decimals -= (int)std::floor(std::log10(abs_num)); } return num(p_num, decimals); @@ -1647,7 +1647,7 @@ String String::num_real(float p_num, bool p_trailing) { // to subtract log10 for numbers with a positive power of ten magnitude. const float abs_num = Math::abs(p_num); if (abs_num > 10) { - decimals -= (int)floor(log10(abs_num)); + decimals -= (int)std::floor(std::log10(abs_num)); } return num(p_num, decimals); } @@ -5621,7 +5621,7 @@ String String::sprintf(const Array &values, bool *error) const { } double value = values[value_index]; - bool is_negative = signbit(value); + bool is_negative = std::signbit(value); String str = String::num(Math::abs(value), min_decimals); const bool is_finite = Math::is_finite(value); diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 399172587f2..eb6fab2c7fc 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -758,7 +758,7 @@ struct _VariantCall { String s; if (p_instance->size() > 0) { const uint8_t *r = p_instance->ptr(); - s.append_utf16((const char16_t *)r, floor((double)p_instance->size() / (double)sizeof(char16_t))); + s.append_utf16((const char16_t *)r, std::floor((double)p_instance->size() / (double)sizeof(char16_t))); } return s; } @@ -767,7 +767,7 @@ struct _VariantCall { String s; if (p_instance->size() > 0) { const uint8_t *r = p_instance->ptr(); - s.append_utf32(Span((const char32_t *)r, floor((double)p_instance->size() / (double)sizeof(char32_t)))); + s.append_utf32(Span((const char32_t *)r, std::floor((double)p_instance->size() / (double)sizeof(char32_t)))); } return s; } @@ -777,9 +777,9 @@ struct _VariantCall { if (p_instance->size() > 0) { const uint8_t *r = p_instance->ptr(); #ifdef WINDOWS_ENABLED - s.append_utf16((const char16_t *)r, floor((double)p_instance->size() / (double)sizeof(char16_t))); + s.append_utf16((const char16_t *)r, std::floor((double)p_instance->size() / (double)sizeof(char16_t))); #else - s.append_utf32(Span((const char32_t *)r, floor((double)p_instance->size() / (double)sizeof(char32_t)))); + s.append_utf32(Span((const char32_t *)r, std::floor((double)p_instance->size() / (double)sizeof(char32_t)))); #endif } return s; diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp index 5b9fc4c8f38..7f6b9f9689a 100644 --- a/core/variant/variant_parser.cpp +++ b/core/variant/variant_parser.cpp @@ -1937,9 +1937,9 @@ Error VariantParser::parse(Stream *p_stream, Variant &r_ret, String &r_err_str, static String rtos_fix(double p_value, bool p_compat) { if (p_value == 0.0) { return "0"; //avoid negative zero (-0) being written, which may annoy git, svn, etc. for changes when they don't exist. - } else if (isnan(p_value)) { + } else if (std::isnan(p_value)) { return "nan"; - } else if (isinf(p_value)) { + } else if (std::isinf(p_value)) { if (p_value > 0) { return "inf"; } else if (p_compat) { diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index 7ed71a5e3cb..80f95aca24c 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -248,7 +248,7 @@ Variant VariantUtilityFunctions::abs(const Variant &x, Callable::CallError &r_er return Math::abs(VariantInternalAccessor::get(&x)); } break; case Variant::FLOAT: { - return Math::absd(VariantInternalAccessor::get(&x)); + return Math::abs(VariantInternalAccessor::get(&x)); } break; case Variant::VECTOR2: { return VariantInternalAccessor::get(&x).abs(); @@ -278,7 +278,7 @@ Variant VariantUtilityFunctions::abs(const Variant &x, Callable::CallError &r_er } double VariantUtilityFunctions::absf(double x) { - return Math::absd(x); + return Math::abs(x); } int64_t VariantUtilityFunctions::absi(int64_t x) { diff --git a/drivers/gles3/effects/cubemap_filter.cpp b/drivers/gles3/effects/cubemap_filter.cpp index a21a02fcbfe..cc4e370757c 100644 --- a/drivers/gles3/effects/cubemap_filter.cpp +++ b/drivers/gles3/effects/cubemap_filter.cpp @@ -92,13 +92,13 @@ CubemapFilter::~CubemapFilter() { Vector3 importance_sample_GGX(Vector2 xi, float roughness4) { // Compute distribution direction float phi = 2.0 * Math::PI * xi.x; - float cos_theta = sqrt((1.0 - xi.y) / (1.0 + (roughness4 - 1.0) * xi.y)); - float sin_theta = sqrt(1.0 - cos_theta * cos_theta); + float cos_theta = std::sqrt((1.0 - xi.y) / (1.0 + (roughness4 - 1.0) * xi.y)); + float sin_theta = std::sqrt(1.0 - cos_theta * cos_theta); // Convert to spherical direction Vector3 half_vector; - half_vector.x = sin_theta * cos(phi); - half_vector.y = sin_theta * sin(phi); + half_vector.x = sin_theta * std::cos(phi); + half_vector.y = sin_theta * std::sin(phi); half_vector.z = cos_theta; return half_vector; @@ -182,7 +182,7 @@ void CubemapFilter::filter_radiance(GLuint p_source_cubemap, GLuint p_dest_cubem float solid_angle_sample = 1.0 / (float(sample_count) * pdf + 0.0001); - float mip_level = MAX(0.5 * log2(solid_angle_sample / solid_angle_texel) + float(MAX(1, p_layer - 3)), 1.0); + float mip_level = MAX(0.5 * std::log2(solid_angle_sample / solid_angle_texel) + float(MAX(1, p_layer - 3)), 1.0); sample_directions[index * 4 + 3] = mip_level; weight += light_vec.z; diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index a71e55e2239..2771bbc6d4a 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -1432,7 +1432,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref &p_event) { float track_h = animation->bezier_track_interpolate(i, time); float track_height = _bezier_h_to_pixel(track_h); - if (abs(mb->get_position().y - track_height) < 10) { + if (std::abs(mb->get_position().y - track_height) < 10) { set_animation_and_track(animation, i, read_only); break; } @@ -1448,7 +1448,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref &p_event) { if (moving_selection_attempt && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { if (!read_only) { - if (moving_selection && (abs(moving_selection_offset.x) > CMP_EPSILON || abs(moving_selection_offset.y) > CMP_EPSILON)) { + if (moving_selection && (std::abs(moving_selection_offset.x) > CMP_EPSILON || std::abs(moving_selection_offset.y) > CMP_EPSILON)) { // Commit it. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(TTR("Move Bezier Points")); @@ -1723,7 +1723,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref &p_event) { float snapped_time = editor->snap_time(moving_selection_pivot + time_delta); float time_offset = 0.0; - if (abs(moving_selection_offset.x) > CMP_EPSILON || (snapped_time > moving_selection_pivot && time_delta > CMP_EPSILON) || (snapped_time < moving_selection_pivot && time_delta < -CMP_EPSILON)) { + if (std::abs(moving_selection_offset.x) > CMP_EPSILON || (snapped_time > moving_selection_pivot && time_delta > CMP_EPSILON) || (snapped_time < moving_selection_pivot && time_delta < -CMP_EPSILON)) { time_offset = snapped_time - moving_selection_pivot; } diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 1fe82aa2d0a..5d048a04fbb 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -3187,7 +3187,7 @@ void AnimationTrackEdit::gui_input(const Ref &p_event) { if (!mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { moving_selection_attempt = false; if (moving_selection && moving_selection_effective) { - if (abs(editor->get_moving_selection_offset()) > CMP_EPSILON) { + if (std::abs(editor->get_moving_selection_offset()) > CMP_EPSILON) { emit_signal(SNAME("move_selection_commit")); } } else if (select_single_attempt != -1) { @@ -3268,7 +3268,7 @@ void AnimationTrackEdit::gui_input(const Ref &p_event) { float snapped_time = editor->snap_time(moving_selection_pivot + delta); float offset = 0.0; - if (abs(editor->get_moving_selection_offset()) > CMP_EPSILON || (snapped_time > moving_selection_pivot && delta > CMP_EPSILON) || (snapped_time < moving_selection_pivot && delta < -CMP_EPSILON)) { + if (std::abs(editor->get_moving_selection_offset()) > CMP_EPSILON || (snapped_time > moving_selection_pivot && delta > CMP_EPSILON) || (snapped_time < moving_selection_pivot && delta < -CMP_EPSILON)) { offset = snapped_time - moving_selection_pivot; moving_selection_effective = true; } @@ -6930,8 +6930,8 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) { if (is_using_angle) { real_t a = from_v; real_t b = to_v; - real_t to_diff = fmod(b - a, Math::TAU); - to_v = a + fmod(2.0 * to_diff, Math::TAU) - to_diff; + real_t to_diff = std::fmod(b - a, Math::TAU); + to_v = a + std::fmod(2.0 * to_diff, Math::TAU) - to_diff; } Variant delta_v = Animation::subtract_variant(to_v, from_v); double duration = to_t - from_t; diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index ee197199bec..bc011fe7052 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -940,7 +940,7 @@ void CodeTextEditor::_text_editor_gui_input(const Ref &p_event) { #ifndef ANDROID_ENABLED Ref magnify_gesture = p_event; if (magnify_gesture.is_valid()) { - _zoom_to(zoom_factor * powf(magnify_gesture->get_factor(), 0.25f)); + _zoom_to(zoom_factor * std::pow(magnify_gesture->get_factor(), 0.25f)); accept_event(); return; } diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 68c54de2b83..02d84145079 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -1550,7 +1550,7 @@ void EditorPropertyEasing::_drag_easing(const Ref &p_ev) { float val = get_edited_property_value(); bool sg = val < 0; - val = Math::absf(val); + val = Math::abs(val); val = Math::log(val) / Math::log((float)2.0); // Logarithmic space. diff --git a/editor/gui/editor_spin_slider.cpp b/editor/gui/editor_spin_slider.cpp index ec513d514f4..fddbadfa2d7 100644 --- a/editor/gui/editor_spin_slider.cpp +++ b/editor/gui/editor_spin_slider.cpp @@ -246,7 +246,7 @@ void EditorSpinSlider::_value_input_gui_input(const Ref &p_event) { if (step < 1) { double divisor = 1.0 / step; - if (trunc(divisor) == divisor) { + if (std::trunc(divisor) == divisor) { step = 1.0; } } diff --git a/editor/import/3d/editor_import_collada.cpp b/editor/import/3d/editor_import_collada.cpp index 27e1df77a83..1a1b202b075 100644 --- a/editor/import/3d/editor_import_collada.cpp +++ b/editor/import/3d/editor_import_collada.cpp @@ -1020,7 +1020,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p Vector tangents = d[Mesh::ARRAY_TANGENT]; for (int vert = 0; vert < normals.size(); vert++) { Vector3 tan = Vector3(tangents[vert * 4 + 0], tangents[vert * 4 + 1], tangents[vert * 4 + 2]); - if (abs(tan.dot(normals[vert])) > 0.0001) { + if (std::abs(tan.dot(normals[vert])) > 0.0001) { // Tangent is not perpendicular to the normal, so we can't use compression. mesh_flags &= ~RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES; } diff --git a/editor/import/3d/post_import_plugin_skeleton_rest_fixer.cpp b/editor/import/3d/post_import_plugin_skeleton_rest_fixer.cpp index ebfe706876e..652c00a7475 100644 --- a/editor/import/3d/post_import_plugin_skeleton_rest_fixer.cpp +++ b/editor/import/3d/post_import_plugin_skeleton_rest_fixer.cpp @@ -372,7 +372,7 @@ void PostImportPluginSkeletonRestFixer::internal_process(InternalImportCategory if (Math::abs(Math::rad_to_deg(src_dir.angle_to(prof_dir))) > float(p_options["retarget/rest_fixer/fix_silhouette/threshold"])) { // Get rotation difference. Vector3 up_vec; // Need to rotate other than roll axis. - switch (Vector3(abs(src_dir.x), abs(src_dir.y), abs(src_dir.z)).min_axis_index()) { + switch (Vector3(std::abs(src_dir.x), std::abs(src_dir.y), std::abs(src_dir.z)).min_axis_index()) { case Vector3::AXIS_X: { up_vec = Vector3(1, 0, 0); } break; @@ -465,7 +465,7 @@ void PostImportPluginSkeletonRestFixer::internal_process(InternalImportCategory if (bool(p_options["retarget/rest_fixer/normalize_position_tracks"])) { int src_bone_idx = src_skeleton->find_bone(profile->get_scale_base_bone()); if (src_bone_idx >= 0) { - real_t motion_scale = abs(src_skeleton->get_bone_global_rest(src_bone_idx).origin.y); + real_t motion_scale = std::abs(src_skeleton->get_bone_global_rest(src_bone_idx).origin.y); if (motion_scale > 0) { src_skeleton->set_motion_scale(motion_scale); } diff --git a/editor/import/3d/resource_importer_obj.cpp b/editor/import/3d/resource_importer_obj.cpp index 13b54949f30..d9b1c873095 100644 --- a/editor/import/3d/resource_importer_obj.cpp +++ b/editor/import/3d/resource_importer_obj.cpp @@ -432,7 +432,7 @@ static Error _parse_obj(const String &p_path, List> &r_meshes, ERR_FAIL_COND_V(tangents.is_empty(), ERR_FILE_CORRUPT); for (int vert = 0; vert < norms.size(); vert++) { Vector3 tan = Vector3(tangents[vert * 4 + 0], tangents[vert * 4 + 1], tangents[vert * 4 + 2]); - if (abs(tan.dot(norms[vert])) > 0.0001) { + if (std::abs(tan.dot(norms[vert])) > 0.0001) { // Tangent is not perpendicular to the normal, so we can't use compression. mesh_flags &= ~RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES; } diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index cd333949ca5..809d50c2b94 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -342,7 +342,7 @@ void CanvasItemEditor::_snap_other_nodes( if (ci && !exception) { Transform2D ci_transform = ci->get_screen_transform(); - if (fmod(ci_transform.get_rotation() - p_transform_to_snap.get_rotation(), (real_t)360.0) == 0.0) { + if (std::fmod(ci_transform.get_rotation() - p_transform_to_snap.get_rotation(), (real_t)360.0) == 0.0) { if (ci->_edit_use_rect()) { Point2 begin = ci_transform.xform(ci->_edit_get_rect().get_position()); Point2 end = ci_transform.xform(ci->_edit_get_rect().get_position() + ci->_edit_get_rect().get_size()); @@ -447,7 +447,7 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, unsig get_tree()->get_edited_scene_root()); } - if (((is_snap_active && snap_guides && (p_modes & SNAP_GUIDES)) || (p_forced_modes & SNAP_GUIDES)) && fmod(rotation, (real_t)360.0) == 0.0) { + if (((is_snap_active && snap_guides && (p_modes & SNAP_GUIDES)) || (p_forced_modes & SNAP_GUIDES)) && std::fmod(rotation, (real_t)360.0) == 0.0) { // Guides. if (Node *scene = EditorNode::get_singleton()->get_edited_scene()) { Array vguides = scene->get_meta("_edit_vertical_guides_", Array()); @@ -462,7 +462,7 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, unsig } } - if (((grid_snap_active && (p_modes & SNAP_GRID)) || (p_forced_modes & SNAP_GRID)) && fmod(rotation, (real_t)360.0) == 0.0) { + if (((grid_snap_active && (p_modes & SNAP_GRID)) || (p_forced_modes & SNAP_GRID)) && std::fmod(rotation, (real_t)360.0) == 0.0) { // Grid Point2 offset = grid_offset; if (snap_relative) { @@ -3136,8 +3136,8 @@ void CanvasItemEditor::_draw_grid() { if (snap_relative && selection.size() > 0) { const Vector2 topleft = _get_encompassing_rect_from_list(selection).position; - real_grid_offset.x = fmod(topleft.x, grid_step.x * (real_t)Math::pow(2.0, grid_step_multiplier)); - real_grid_offset.y = fmod(topleft.y, grid_step.y * (real_t)Math::pow(2.0, grid_step_multiplier)); + real_grid_offset.x = std::fmod(topleft.x, grid_step.x * (real_t)Math::pow(2.0, grid_step_multiplier)); + real_grid_offset.y = std::fmod(topleft.y, grid_step.y * (real_t)Math::pow(2.0, grid_step_multiplier)); } else { real_grid_offset = grid_offset; } @@ -3282,8 +3282,8 @@ void CanvasItemEditor::_draw_ruler_tool() { viewport->draw_string(font, text_pos, TS->format_number(vformat("%.1f px", length_vector.length())), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color); if (draw_secondary_lines) { - const int horizontal_angle = round(180 * horizontal_angle_rad / Math::PI); - const int vertical_angle = round(180 * vertical_angle_rad / Math::PI); + const int horizontal_angle = std::round(180 * horizontal_angle_rad / Math::PI); + const int vertical_angle = std::round(180 * vertical_angle_rad / Math::PI); Point2 text_pos2 = text_pos; text_pos2.x = begin.x < text_pos.x ? MIN(text_pos.x - text_width, begin.x - text_width / 2) : MAX(text_pos.x + text_width, begin.x - text_width / 2); @@ -3331,16 +3331,16 @@ void CanvasItemEditor::_draw_ruler_tool() { Point2 text_pos2 = text_pos; text_pos2.x = begin.x < text_pos.x ? MIN(text_pos.x - text_width, begin.x - text_width / 2) : MAX(text_pos.x + text_width, begin.x - text_width / 2); - viewport->draw_string_outline(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), roundf(length_vector.y / grid_step.y))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); - viewport->draw_string(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), roundf(length_vector.y / grid_step.y))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); + viewport->draw_string_outline(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), std::round(length_vector.y / grid_step.y))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); + viewport->draw_string(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), std::round(length_vector.y / grid_step.y))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); text_pos2 = text_pos; text_pos2.y = end.y < text_pos.y ? MIN(text_pos.y - text_height * 2, end.y + text_height / 2) : MAX(text_pos.y + text_height * 2, end.y + text_height / 2); - viewport->draw_string_outline(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), roundf(length_vector.x / grid_step.x))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); - viewport->draw_string(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), roundf(length_vector.x / grid_step.x))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); + viewport->draw_string_outline(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), std::round(length_vector.x / grid_step.x))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); + viewport->draw_string(font, text_pos2, TS->format_number(vformat("%d " + TTR("units"), std::round(length_vector.x / grid_step.x))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_secondary_color); } else { - viewport->draw_string_outline(font, text_pos, TS->format_number(vformat("%d " + TTR("units"), roundf((length_vector / grid_step).length()))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); - viewport->draw_string(font, text_pos, TS->format_number(vformat("%d " + TTR("units"), roundf((length_vector / grid_step).length()))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color); + viewport->draw_string_outline(font, text_pos, TS->format_number(vformat("%d " + TTR("units"), std::round((length_vector / grid_step).length()))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, outline_size, outline_color); + viewport->draw_string(font, text_pos, TS->format_number(vformat("%d " + TTR("units"), std::round((length_vector / grid_step).length()))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color); } } } else { diff --git a/editor/plugins/editor_resource_tooltip_plugins.cpp b/editor/plugins/editor_resource_tooltip_plugins.cpp index d8da6002d58..f8fc7aea8c2 100644 --- a/editor/plugins/editor_resource_tooltip_plugins.cpp +++ b/editor/plugins/editor_resource_tooltip_plugins.cpp @@ -138,7 +138,7 @@ Control *EditorAudioStreamTooltipPlugin::make_tooltip_for_path(const String &p_r double length = p_metadata.get("length", 0.0); if (length >= 60.0) { - vb->add_child(memnew(Label(vformat(TTR("Length: %0dm %0ds"), int(length / 60.0), int(fmod(length, 60)))))); + vb->add_child(memnew(Label(vformat(TTR("Length: %0dm %0ds"), int(length / 60.0), int(std::fmod(length, 60)))))); } else if (length >= 1.0) { vb->add_child(memnew(Label(vformat(TTR("Length: %0.1fs"), length)))); } else { diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp index 1b756163f74..62330ce8d62 100644 --- a/editor/plugins/particles_editor_plugin.cpp +++ b/editor/plugins/particles_editor_plugin.cpp @@ -72,7 +72,7 @@ void ParticlesEditorPlugin::_notification(int p_what) { bool ParticlesEditorPlugin::need_show_lifetime_dialog(SpinBox *p_seconds) { // Add one second to the default generation lifetime, since the progress is updated every second. - p_seconds->set_value(MAX(1.0, trunc(edited_node->get("lifetime").operator double()) + 1.0)); + p_seconds->set_value(MAX(1.0, std::trunc(edited_node->get("lifetime").operator double()) + 1.0)); if (p_seconds->get_value() >= 11.0 + CMP_EPSILON) { // Only pop up the time dialog if the particle's lifetime is long enough to warrant shortening it. diff --git a/editor/plugins/path_3d_editor_plugin.cpp b/editor/plugins/path_3d_editor_plugin.cpp index 721fe063973..c600a5061e6 100644 --- a/editor/plugins/path_3d_editor_plugin.cpp +++ b/editor/plugins/path_3d_editor_plugin.cpp @@ -473,7 +473,7 @@ void Path3DGizmo::redraw() { const int n = 36; for (int i = 0; i <= n; i++) { const float a = Math::TAU * i / n; - const Vector3 edge = sin(a) * side + cos(a) * up; + const Vector3 edge = std::sin(a) * side + std::cos(a) * up; disk.append(pos + edge * disk_size); } add_vertices(disk, debug_material, Mesh::PRIMITIVE_LINE_STRIP); diff --git a/main/main_timer_sync.cpp b/main/main_timer_sync.cpp index 569930d4277..08b861b8820 100644 --- a/main/main_timer_sync.cpp +++ b/main/main_timer_sync.cpp @@ -335,7 +335,7 @@ MainFrameTime MainTimerSync::advance_core(double p_physics_step, int p_physics_t // simple determination of number of physics iteration time_accum += ret.process_step; - ret.physics_steps = floor(time_accum * p_physics_ticks_per_second); + ret.physics_steps = std::floor(time_accum * p_physics_ticks_per_second); int min_typical_steps = typical_physics_steps[0]; int max_typical_steps = min_typical_steps + 1; @@ -368,7 +368,7 @@ MainFrameTime MainTimerSync::advance_core(double p_physics_step, int p_physics_t // try to keep it consistent with previous iterations if (ret.physics_steps < min_typical_steps) { - const int max_possible_steps = floor((time_accum)*p_physics_ticks_per_second + get_physics_jitter_fix()); + const int max_possible_steps = std::floor((time_accum)*p_physics_ticks_per_second + get_physics_jitter_fix()); if (max_possible_steps < min_typical_steps) { ret.physics_steps = max_possible_steps; update_typical = true; @@ -376,7 +376,7 @@ MainFrameTime MainTimerSync::advance_core(double p_physics_step, int p_physics_t ret.physics_steps = min_typical_steps; } } else if (ret.physics_steps > max_typical_steps) { - const int min_possible_steps = floor((time_accum)*p_physics_ticks_per_second - get_physics_jitter_fix()); + const int min_possible_steps = std::floor((time_accum)*p_physics_ticks_per_second - get_physics_jitter_fix()); if (min_possible_steps > max_typical_steps) { ret.physics_steps = min_possible_steps; update_typical = true; @@ -462,7 +462,7 @@ MainFrameTime MainTimerSync::advance_checked(double p_physics_step, int p_physic #endif if (time_accum > p_physics_step) { - const int extra_physics_steps = floor(time_accum * p_physics_ticks_per_second); + const int extra_physics_steps = std::floor(time_accum * p_physics_ticks_per_second); time_accum -= extra_physics_steps * p_physics_step; ret.physics_steps += extra_physics_steps; } diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index f737f93929e..928beafd455 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -3609,7 +3609,7 @@ Error GLTFDocument::_parse_meshes(Ref p_state) { } else { for (int vert = 0; vert < normals.size(); vert++) { Vector3 tan = Vector3(tangents[vert * 4 + 0], tangents[vert * 4 + 1], tangents[vert * 4 + 2]); - if (abs(tan.dot(normals[vert])) > 0.0001) { + if (std::abs(tan.dot(normals[vert])) > 0.0001) { // Tangent is not perpendicular to the normal, so we can't use compression. flags &= ~RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES; } diff --git a/modules/godot_physics_2d/godot_body_2d.cpp b/modules/godot_physics_2d/godot_body_2d.cpp index 378cf1618a6..65a5e1eebcf 100644 --- a/modules/godot_physics_2d/godot_body_2d.cpp +++ b/modules/godot_physics_2d/godot_body_2d.cpp @@ -563,7 +563,7 @@ void GodotBody2D::integrate_forces(real_t p_step) { linear_velocity = constant_linear_velocity + motion / p_step; real_t rot = new_transform.get_rotation() - get_transform().get_rotation(); - angular_velocity = constant_angular_velocity + remainder(rot, 2.0 * Math::PI) / p_step; + angular_velocity = constant_angular_velocity + std::remainder(rot, 2.0 * Math::PI) / p_step; do_motion = true; diff --git a/modules/godot_physics_3d/godot_shape_3d.cpp b/modules/godot_physics_3d/godot_shape_3d.cpp index c5bbff8d68f..10970ee4e9e 100644 --- a/modules/godot_physics_3d/godot_shape_3d.cpp +++ b/modules/godot_physics_3d/godot_shape_3d.cpp @@ -743,7 +743,7 @@ bool GodotCylinderShape3D::intersect_point(const Vector3 &p_point) const { } Vector3 GodotCylinderShape3D::get_closest_point_to(const Vector3 &p_point) const { - if (Math::absf(p_point.y) > height * 0.5) { + if (Math::abs(p_point.y) > height * 0.5) { // Project point to top disk. real_t dir = p_point.y > 0.0 ? 1.0 : -1.0; Vector3 circle_pos(0.0, dir * height * 0.5, 0.0); diff --git a/modules/godot_physics_3d/godot_soft_body_3d.cpp b/modules/godot_physics_3d/godot_soft_body_3d.cpp index 13c786cf9af..a117095648d 100644 --- a/modules/godot_physics_3d/godot_soft_body_3d.cpp +++ b/modules/godot_physics_3d/godot_soft_body_3d.cpp @@ -963,7 +963,7 @@ Vector3 GodotSoftBody3D::_compute_area_windforce(const GodotArea3D *p_area, cons const Vector3 &ws = p_area->get_wind_source(); real_t projection_on_tri_normal = vec3_dot(p_face->normal, wd); real_t projection_toward_centroid = vec3_dot(p_face->centroid - ws, wd); - real_t attenuation_over_distance = pow(projection_toward_centroid, -waf); + real_t attenuation_over_distance = std::pow(projection_toward_centroid, -waf); real_t nodal_force_magnitude = wfm * 0.33333333333 * p_face->ra * projection_on_tri_normal * attenuation_over_distance; return nodal_force_magnitude * p_face->normal; } diff --git a/modules/hdr/image_loader_hdr.cpp b/modules/hdr/image_loader_hdr.cpp index 91b3e0b436b..1b69fe5302d 100644 --- a/modules/hdr/image_loader_hdr.cpp +++ b/modules/hdr/image_loader_hdr.cpp @@ -129,7 +129,7 @@ Error ImageLoaderHDR::load_image(Ref p_image, Ref f, BitField int e = ptr[3] - 128; if (force_linear || (e < -15 || e > 15)) { - float exp = pow(2.0f, e); + float exp = std::pow(2.0f, e); Color c(ptr[0] * exp / 255.0, ptr[1] * exp / 255.0, ptr[2] * exp / 255.0); if (force_linear) { diff --git a/modules/jolt_physics/spaces/jolt_physics_direct_space_state_3d.cpp b/modules/jolt_physics/spaces/jolt_physics_direct_space_state_3d.cpp index 306949568ff..e0fb463e895 100644 --- a/modules/jolt_physics/spaces/jolt_physics_direct_space_state_3d.cpp +++ b/modules/jolt_physics/spaces/jolt_physics_direct_space_state_3d.cpp @@ -111,7 +111,7 @@ bool JoltPhysicsDirectSpaceState3D::_cast_motion_impl(const JPH::Shape &p_jolt_s }; // Figure out the number of steps we need in our binary search in order to achieve millimeter precision, within reason. - const int step_count = CLAMP(int(logf(1000.0f * motion_length) / (float)Math::LN2), 4, 16); + const int step_count = CLAMP(int(std::log(1000.0f * motion_length) / (float)Math::LN2), 4, 16); bool collided = false; diff --git a/modules/mobile_vr/mobile_vr_interface.cpp b/modules/mobile_vr/mobile_vr_interface.cpp index 8134a17fd3a..5a9ea8dae29 100644 --- a/modules/mobile_vr/mobile_vr_interface.cpp +++ b/modules/mobile_vr/mobile_vr_interface.cpp @@ -205,7 +205,7 @@ void MobileVRInterface::set_position_from_sensors() { Vector3 axis = grav_adj.cross(down); axis.normalize(); - Basis drift_compensation(axis, acos(dot) * delta_time * 10); + Basis drift_compensation(axis, std::acos(dot) * delta_time * 10); orientation = drift_compensation * orientation; }; }; diff --git a/modules/mobile_vr/mobile_vr_interface.h b/modules/mobile_vr/mobile_vr_interface.h index 36e6c0e8b0b..f09be9117a0 100644 --- a/modules/mobile_vr/mobile_vr_interface.h +++ b/modules/mobile_vr/mobile_vr_interface.h @@ -94,8 +94,8 @@ private: ///@TODO a few support functions for trackers, most are math related and should likely be moved elsewhere float floor_decimals(const float p_value, const float p_decimals) { - float power_of_10 = pow(10.0f, p_decimals); - return floor(p_value * power_of_10) / power_of_10; + float power_of_10 = std::pow(10.0f, p_decimals); + return std::floor(p_value * power_of_10) / power_of_10; } Vector3 floor_decimals(const Vector3 &p_vector, const float p_decimals) { diff --git a/modules/noise/noise.cpp b/modules/noise/noise.cpp index 12e9aca3ea9..c8d6d78a43b 100644 --- a/modules/noise/noise.cpp +++ b/modules/noise/noise.cpp @@ -30,8 +30,6 @@ #include "noise.h" -#include - Vector> Noise::_get_seamless_image(int p_width, int p_height, int p_depth, bool p_invert, bool p_in_3d_space, real_t p_blend_skirt, bool p_normalize) const { ERR_FAIL_COND_V(p_width <= 0 || p_height <= 0 || p_depth <= 0, Vector>()); diff --git a/modules/openxr/extensions/openxr_hand_tracking_extension.cpp b/modules/openxr/extensions/openxr_hand_tracking_extension.cpp index 7552a44baa3..775d49f4d34 100644 --- a/modules/openxr/extensions/openxr_hand_tracking_extension.cpp +++ b/modules/openxr/extensions/openxr_hand_tracking_extension.cpp @@ -245,7 +245,7 @@ void OpenXRHandTrackingExtension::on_process() { // For some reason an inactive controller isn't coming back as inactive but has coordinates either as NAN or very large const XrPosef &palm = hand_trackers[i].joint_locations[XR_HAND_JOINT_PALM_EXT].pose; - if (!hand_trackers[i].locations.isActive || isnan(palm.position.x) || palm.position.x < -1000000.00 || palm.position.x > 1000000.00) { + if (!hand_trackers[i].locations.isActive || std::isnan(palm.position.x) || palm.position.x < -1000000.00 || palm.position.x > 1000000.00) { hand_trackers[i].locations.isActive = false; // workaround, make sure its inactive } diff --git a/modules/openxr/openxr_util.cpp b/modules/openxr/openxr_util.cpp index 1d442333378..59f29206c0e 100644 --- a/modules/openxr/openxr_util.cpp +++ b/modules/openxr/openxr_util.cpp @@ -30,9 +30,9 @@ #include "openxr_util.h" -#include +#include "core/math/math_funcs.h" -#include +#include #define XR_ENUM_CASE_STR(name, val) \ case name: \ @@ -155,11 +155,11 @@ void OpenXRUtil::XrMatrix4x4f_CreateProjection(XrMatrix4x4f *result, GraphicsAPI // Creates a projection matrix based on the specified FOV. void OpenXRUtil::XrMatrix4x4f_CreateProjectionFov(XrMatrix4x4f *result, GraphicsAPI graphicsApi, const XrFovf fov, const float nearZ, const float farZ) { - const float tanLeft = tanf(fov.angleLeft); - const float tanRight = tanf(fov.angleRight); + const float tanLeft = std::tan(fov.angleLeft); + const float tanRight = std::tan(fov.angleRight); - const float tanDown = tanf(fov.angleDown); - const float tanUp = tanf(fov.angleUp); + const float tanDown = std::tan(fov.angleDown); + const float tanUp = std::tan(fov.angleUp); XrMatrix4x4f_CreateProjection(result, graphicsApi, tanLeft, tanRight, tanUp, tanDown, nearZ, farZ); } diff --git a/modules/svg/image_loader_svg.cpp b/modules/svg/image_loader_svg.cpp index 39292f842b0..d0e2b1728c6 100644 --- a/modules/svg/image_loader_svg.cpp +++ b/modules/svg/image_loader_svg.cpp @@ -89,8 +89,8 @@ Error ImageLoaderSVG::create_image_from_utf8_buffer(Ref p_image, const ui float fw, fh; picture->size(&fw, &fh); - uint32_t width = MAX(1, round(fw * p_scale)); - uint32_t height = MAX(1, round(fh * p_scale)); + uint32_t width = MAX(1, std::round(fw * p_scale)); + uint32_t height = MAX(1, std::round(fh * p_scale)); const uint32_t max_dimension = 16384; if (width > max_dimension || height > max_dimension) { diff --git a/modules/text_server_adv/thorvg_svg_in_ot.cpp b/modules/text_server_adv/thorvg_svg_in_ot.cpp index e88cb682015..51fa264ff7e 100644 --- a/modules/text_server_adv/thorvg_svg_in_ot.cpp +++ b/modules/text_server_adv/thorvg_svg_in_ot.cpp @@ -60,7 +60,6 @@ using namespace godot; #include #include -#include #include FT_Error tvg_svg_in_ot_init(FT_Pointer *p_state) { diff --git a/modules/text_server_fb/thorvg_svg_in_ot.cpp b/modules/text_server_fb/thorvg_svg_in_ot.cpp index e88cb682015..51fa264ff7e 100644 --- a/modules/text_server_fb/thorvg_svg_in_ot.cpp +++ b/modules/text_server_fb/thorvg_svg_in_ot.cpp @@ -60,7 +60,6 @@ using namespace godot; #include #include -#include #include FT_Error tvg_svg_in_ot_init(FT_Pointer *p_state) { diff --git a/modules/webxr/webxr_interface_js.cpp b/modules/webxr/webxr_interface_js.cpp index 2c92ba9d6d5..cf11dcc9ded 100644 --- a/modules/webxr/webxr_interface_js.cpp +++ b/modules/webxr/webxr_interface_js.cpp @@ -728,7 +728,7 @@ void WebXRInterfaceJS::_update_input_source(int p_input_source_id) { Vector2 delta = position - touches[touch_index].position; // If position has changed by at least 1 pixel, generate a drag event. - if (abs(delta.x) >= 1.0 || abs(delta.y) >= 1.0) { + if (std::abs(delta.x) >= 1.0 || std::abs(delta.y) >= 1.0) { Ref event; event.instantiate(); event->set_index(touch_index); diff --git a/platform/linuxbsd/joypad_linux.cpp b/platform/linuxbsd/joypad_linux.cpp index f76e54d74e1..d109f230c15 100644 --- a/platform/linuxbsd/joypad_linux.cpp +++ b/platform/linuxbsd/joypad_linux.cpp @@ -443,9 +443,9 @@ void JoypadLinux::joypad_vibration_start(Joypad &p_joypad, float p_weak_magnitud struct ff_effect effect; effect.type = FF_RUMBLE; effect.id = -1; - effect.u.rumble.weak_magnitude = floor(p_weak_magnitude * (float)0xffff); - effect.u.rumble.strong_magnitude = floor(p_strong_magnitude * (float)0xffff); - effect.replay.length = floor(p_duration * 1000); + effect.u.rumble.weak_magnitude = std::floor(p_weak_magnitude * (float)0xffff); + effect.u.rumble.strong_magnitude = std::floor(p_strong_magnitude * (float)0xffff); + effect.replay.length = std::floor(p_duration * 1000); effect.replay.delay = 0; if (ioctl(p_joypad.fd, EVIOCSFF, &effect) < 0) { diff --git a/platform/linuxbsd/tts_linux.cpp b/platform/linuxbsd/tts_linux.cpp index 2ef89747ecf..1b0a83b3891 100644 --- a/platform/linuxbsd/tts_linux.cpp +++ b/platform/linuxbsd/tts_linux.cpp @@ -166,9 +166,9 @@ void TTS_Linux::_speech_event(int p_msg_id, int p_type) { spd_set_voice_pitch(synth, (message.pitch - 1) * 100); float rate = 0; if (message.rate > 1.f) { - rate = log10(MIN(message.rate, 2.5f)) / log10(2.5f) * 100; + rate = std::log10(MIN(message.rate, 2.5f)) / std::log10(2.5f) * 100; } else if (message.rate < 1.f) { - rate = log10(MAX(message.rate, 0.5f)) / log10(0.5f) * -100; + rate = std::log10(MAX(message.rate, 0.5f)) / std::log10(0.5f) * -100; } spd_set_voice_rate(synth, rate); spd_set_data_mode(synth, SPD_DATA_SSML); diff --git a/platform/linuxbsd/wayland/wayland_thread.cpp b/platform/linuxbsd/wayland/wayland_thread.cpp index caf240d35ac..4f5a08e96b6 100644 --- a/platform/linuxbsd/wayland/wayland_thread.cpp +++ b/platform/linuxbsd/wayland/wayland_thread.cpp @@ -1830,7 +1830,7 @@ void WaylandThread::_wl_pointer_on_frame(void *data, struct wl_pointer *wl_point if (test_button == MouseButton::WHEEL_RIGHT || test_button == MouseButton::WHEEL_LEFT) { // If this is a discrete scroll, specify how many "clicks" it did for this // pointer frame. - mb->set_factor(fabs(pd.discrete_scroll_vector_120.x / (float)120)); + mb->set_factor(std::abs(pd.discrete_scroll_vector_120.x / (float)120)); } mb->set_button_mask(pd.pressed_button_mask); @@ -3228,8 +3228,8 @@ void WaylandThread::window_state_update_size(WindowState *p_ws, int p_width, int // must be scaled with away from zero half-rounding. Vector2i WaylandThread::scale_vector2i(const Vector2i &p_vector, double p_amount) { // This snippet is tiny, I know, but this is done a lot. - int x = round(p_vector.x * p_amount); - int y = round(p_vector.y * p_amount); + int x = std::round(p_vector.x * p_amount); + int y = std::round(p_vector.y * p_amount); return Vector2i(x, y); } @@ -4198,8 +4198,8 @@ void WaylandThread::pointer_set_hint(const Point2i &p_hint) { // discussing about this. I'm not really sure about the maths behind this but, // oh well, we're setting a cursor hint. ¯\_(ツ)_/¯ // See: https://oftc.irclog.whitequark.org/wayland/2023-08-23#1692756914-1692816818 - hint_x = round(p_hint.x / window_state_get_scale_factor(ws)); - hint_y = round(p_hint.y / window_state_get_scale_factor(ws)); + hint_x = std::round(p_hint.x / window_state_get_scale_factor(ws)); + hint_y = std::round(p_hint.y / window_state_get_scale_factor(ws)); } if (ss) { @@ -4394,7 +4394,7 @@ void WaylandThread::cursor_shape_set_custom_image(DisplayServer::CursorShape p_c // Fill the cursor buffer with the image data. for (unsigned int index = 0; index < (unsigned int)(image_size.width * image_size.height); index++) { - int row_index = floor(index / image_size.width); + int row_index = std::floor(index / image_size.width); int column_index = (index % int(image_size.width)); cursor.buffer_data[index] = p_image->get_pixel(column_index, row_index).to_argb32(); diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index 985209bd082..67250c3d147 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -3443,7 +3443,7 @@ void DisplayServerX11::cursor_set_custom_image(const Ref &p_cursor, Cu cursor_image->pixels = (XcursorPixel *)memalloc(size); for (XcursorPixel index = 0; index < image_size; index++) { - int row_index = floor(index / texture_size.width); + int row_index = std::floor(index / texture_size.width); int column_index = index % int(texture_size.width); *(cursor_image->pixels + index) = image->get_pixel(column_index, row_index).to_argb32(); diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index 3ec84872e66..cd99d9b21b5 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -1753,7 +1753,7 @@ int DisplayServerMacOS::screen_get_dpi(int p_screen) const { float den2 = (displayPhysicalSize.width / 25.4f) * (displayPhysicalSize.width / 25.4f) + (displayPhysicalSize.height / 25.4f) * (displayPhysicalSize.height / 25.4f); if (den2 > 0.0f) { - return ceil(sqrt(displayPixelSize.width * displayPixelSize.width + displayPixelSize.height * displayPixelSize.height) / sqrt(den2) * scale); + return std::ceil(std::sqrt(displayPixelSize.width * displayPixelSize.width + displayPixelSize.height * displayPixelSize.height) / std::sqrt(den2) * scale); } } @@ -1768,7 +1768,7 @@ float DisplayServerMacOS::screen_get_scale(int p_screen) const { NSArray *screenArray = [NSScreen screens]; if ((NSUInteger)p_screen < [screenArray count]) { if ([[screenArray objectAtIndex:p_screen] respondsToSelector:@selector(backingScaleFactor)]) { - return fmax(1.0, [[screenArray objectAtIndex:p_screen] backingScaleFactor]); + return std::fmax(1.0, [[screenArray objectAtIndex:p_screen] backingScaleFactor]); } } } @@ -3230,7 +3230,7 @@ void DisplayServerMacOS::cursor_set_custom_image(const Ref &p_cursor, int len = int(texture_size.width * texture_size.height); for (int i = 0; i < len; i++) { - int row_index = floor(i / texture_size.width); + int row_index = std::floor(i / texture_size.width); int column_index = i % int(texture_size.width); uint32_t color = image->get_pixel(column_index, row_index).to_argb32(); @@ -3863,7 +3863,7 @@ DisplayServerMacOS::DisplayServerMacOS(const String &p_rendering_driver, WindowM int screen_count = get_screen_count(); for (int i = 0; i < screen_count; i++) { - display_max_scale = fmax(display_max_scale, screen_get_scale(i)); + display_max_scale = std::fmax(display_max_scale, screen_get_scale(i)); } // Register to be notified on keyboard layout changes. diff --git a/platform/macos/godot_content_view.mm b/platform/macos/godot_content_view.mm index cf9655785d5..48a782fe2ab 100644 --- a/platform/macos/godot_content_view.mm +++ b/platform/macos/godot_content_view.mm @@ -871,11 +871,11 @@ if ([event phase] != NSEventPhaseNone || [event momentumPhase] != NSEventPhaseNone) { [self processPanEvent:event dx:delta_x dy:delta_y]; } else { - if (fabs(delta_x)) { - [self processScrollEvent:event button:(0 > delta_x ? MouseButton::WHEEL_RIGHT : MouseButton::WHEEL_LEFT) factor:fabs(delta_x * 0.3)]; + if (std::abs(delta_x)) { + [self processScrollEvent:event button:(0 > delta_x ? MouseButton::WHEEL_RIGHT : MouseButton::WHEEL_LEFT) factor:std::abs(delta_x * 0.3)]; } - if (fabs(delta_y)) { - [self processScrollEvent:event button:(0 < delta_y ? MouseButton::WHEEL_UP : MouseButton::WHEEL_DOWN) factor:fabs(delta_y * 0.3)]; + if (std::abs(delta_y)) { + [self processScrollEvent:event button:(0 < delta_y ? MouseButton::WHEEL_UP : MouseButton::WHEEL_DOWN) factor:std::abs(delta_y * 0.3)]; } } } diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index b071235735f..9b0b92f98e1 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -1056,31 +1056,31 @@ Ref DisplayServerWindows::clipboard_get_image() const { if (dc) { HDC hdc = CreateCompatibleDC(dc); if (hdc) { - HBITMAP hbm = CreateCompatibleBitmap(dc, info->biWidth, abs(info->biHeight)); + HBITMAP hbm = CreateCompatibleBitmap(dc, info->biWidth, std::abs(info->biHeight)); if (hbm) { SelectObject(hdc, hbm); - SetDIBitsToDevice(hdc, 0, 0, info->biWidth, abs(info->biHeight), 0, 0, 0, abs(info->biHeight), dib_bits, ptr, DIB_RGB_COLORS); + SetDIBitsToDevice(hdc, 0, 0, info->biWidth, std::abs(info->biHeight), 0, 0, 0, std::abs(info->biHeight), dib_bits, ptr, DIB_RGB_COLORS); BITMAPINFO bmp_info = {}; bmp_info.bmiHeader.biSize = sizeof(bmp_info.bmiHeader); bmp_info.bmiHeader.biWidth = info->biWidth; - bmp_info.bmiHeader.biHeight = -abs(info->biHeight); + bmp_info.bmiHeader.biHeight = -std::abs(info->biHeight); bmp_info.bmiHeader.biPlanes = 1; bmp_info.bmiHeader.biBitCount = 32; bmp_info.bmiHeader.biCompression = BI_RGB; Vector img_data; - img_data.resize(info->biWidth * abs(info->biHeight) * 4); - GetDIBits(hdc, hbm, 0, abs(info->biHeight), img_data.ptrw(), &bmp_info, DIB_RGB_COLORS); + img_data.resize(info->biWidth * std::abs(info->biHeight) * 4); + GetDIBits(hdc, hbm, 0, std::abs(info->biHeight), img_data.ptrw(), &bmp_info, DIB_RGB_COLORS); uint8_t *wr = (uint8_t *)img_data.ptrw(); - for (int i = 0; i < info->biWidth * abs(info->biHeight); i++) { + for (int i = 0; i < info->biWidth * std::abs(info->biHeight); i++) { SWAP(wr[i * 4 + 0], wr[i * 4 + 2]); // Swap B and R. if (info->biBitCount != 32) { wr[i * 4 + 3] = 255; // Set A to solid if it's not in the source image. } } - image = Image::create_from_data(info->biWidth, abs(info->biHeight), false, Image::Format::FORMAT_RGBA8, img_data); + image = Image::create_from_data(info->biWidth, std::abs(info->biHeight), false, Image::Format::FORMAT_RGBA8, img_data); DeleteObject(hbm); } @@ -3003,7 +3003,7 @@ void DisplayServerWindows::cursor_set_custom_image(const Ref &p_cursor bool fully_transparent = true; for (UINT index = 0; index < image_size; index++) { - int row_index = floor(index / texture_size.width); + int row_index = std::floor(index / texture_size.width); int column_index = index % int(texture_size.width); const Color &c = image->get_pixel(column_index, row_index); @@ -5574,7 +5574,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } else { mb->set_button_index(MouseButton::WHEEL_DOWN); } - mb->set_factor(fabs((double)motion / (double)WHEEL_DELTA)); + mb->set_factor(std::fabs((double)motion / (double)WHEEL_DELTA)); } break; case WM_MOUSEHWHEEL: { mb->set_pressed(true); @@ -5588,7 +5588,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } else { mb->set_button_index(MouseButton::WHEEL_RIGHT); } - mb->set_factor(fabs((double)motion / (double)WHEEL_DELTA)); + mb->set_factor(std::fabs((double)motion / (double)WHEEL_DELTA)); } break; case WM_XBUTTONDOWN: { mb->set_pressed(true); diff --git a/platform/windows/native_menu_windows.cpp b/platform/windows/native_menu_windows.cpp index 84d9302403e..f79862449cd 100644 --- a/platform/windows/native_menu_windows.cpp +++ b/platform/windows/native_menu_windows.cpp @@ -58,7 +58,7 @@ HBITMAP NativeMenuWindows::_make_bitmap(const Ref &p_img) const { HDC dc = GetDC(nullptr); HBITMAP bitmap = CreateDIBSection(dc, reinterpret_cast(&bi), DIB_RGB_COLORS, reinterpret_cast(&buffer), nullptr, 0); for (UINT index = 0; index < image_size; index++) { - int row_index = floor(index / texture_size.width); + int row_index = std::floor(index / texture_size.width); int column_index = (index % int(texture_size.width)); const Color &c = p_img->get_pixel(column_index, row_index); *(buffer + index) = c.to_argb32(); diff --git a/platform/windows/tts_windows.cpp b/platform/windows/tts_windows.cpp index e9ef50d7367..c04cb7dd444 100644 --- a/platform/windows/tts_windows.cpp +++ b/platform/windows/tts_windows.cpp @@ -104,7 +104,7 @@ void TTS_Windows::process_events() { ut.id = message.id; synth->SetVolume(message.volume); - synth->SetRate(10.f * log10(message.rate) / log10(3.f)); + synth->SetRate(10.f * std::log10(message.rate) / std::log10(3.f)); synth->Speak((LPCWSTR)ut.string.get_data(), flags, &stream_number); ids[(uint32_t)stream_number] = ut; diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp index bdcb2b83d0b..07750883672 100644 --- a/scene/2d/animated_sprite_2d.cpp +++ b/scene/2d/animated_sprite_2d.cpp @@ -204,7 +204,7 @@ void AnimatedSprite2D::_notification(int p_what) { int fc = frames->get_frame_count(animation); int last_frame = fc - 1; - if (!signbit(speed)) { + if (!std::signbit(speed)) { // Forwards. if (frame_progress >= 1.0) { if (frame >= last_frame) { @@ -336,7 +336,7 @@ Ref AnimatedSprite2D::get_sprite_frames() const { } void AnimatedSprite2D::set_frame(int p_frame) { - set_frame_and_progress(p_frame, signbit(get_playing_speed()) ? 1.0 : 0.0); + set_frame_and_progress(p_frame, std::signbit(get_playing_speed()) ? 1.0 : 0.0); } int AnimatedSprite2D::get_frame() const { @@ -498,7 +498,7 @@ void AnimatedSprite2D::play(const StringName &p_name, float p_custom_scale, bool emit_signal(SceneStringName(animation_changed)); } else { int end_frame = MAX(0, frames->get_frame_count(animation) - 1); - bool is_backward = signbit(speed_scale * custom_speed_scale); + bool is_backward = std::signbit(speed_scale * custom_speed_scale); if (p_from_end && is_backward && frame == 0 && frame_progress <= 0.0) { set_frame_and_progress(end_frame, 1.0); @@ -570,7 +570,7 @@ void AnimatedSprite2D::set_animation(const StringName &p_name) { ERR_FAIL_MSG(vformat("There is no animation with name '%s'.", p_name)); } - if (signbit(get_playing_speed())) { + if (std::signbit(get_playing_speed())) { set_frame_and_progress(frame_count - 1, 1.0); } else { set_frame_and_progress(0, 0.0); diff --git a/scene/2d/gpu_particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp index 73ccf953d24..e8250e2f8fd 100644 --- a/scene/2d/gpu_particles_2d.cpp +++ b/scene/2d/gpu_particles_2d.cpp @@ -833,7 +833,7 @@ void GPUParticles2D::_draw_emission_gizmo() { draw_circle(Vector2(), pm->get_emission_ring_radius(), emission_ring_color, false); } else { Vector2 a = Vector2(pm->get_emission_ring_height() / -2.0, pm->get_emission_ring_radius() / -1.0); - Vector2 b = Vector2(-a.x, MIN(a.y + tan((90.0 - pm->get_emission_ring_cone_angle()) * 0.01745329) * pm->get_emission_ring_height(), 0.0)); + Vector2 b = Vector2(-a.x, MIN(a.y + std::tan((90.0 - pm->get_emission_ring_cone_angle()) * 0.01745329) * pm->get_emission_ring_height(), 0.0)); Vector2 c = Vector2(b.x, -b.y); Vector2 d = Vector2(a.x, -a.y); if (ring_axis.is_equal_approx(Vector3(1.0, 0.0, 0.0))) { diff --git a/scene/2d/line_builder.cpp b/scene/2d/line_builder.cpp index d4a5b224b5d..52755971e06 100644 --- a/scene/2d/line_builder.cpp +++ b/scene/2d/line_builder.cpp @@ -367,7 +367,7 @@ void LineBuilder::build() { float dot_product = vbegin.dot(vend); // Note that we're comparing against -0.f for clarity but 0.f would // match as well, therefore we need the explicit signbit check too. - if (cross_product == -0.f && signbit(cross_product)) { + if (cross_product == -0.f && std::signbit(cross_product)) { cross_product = 0.f; } float angle_delta = Math::atan2(cross_product, dot_product); diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp index 24f261deb6b..b0379608fd9 100644 --- a/scene/2d/parallax_layer.cpp +++ b/scene/2d/parallax_layer.cpp @@ -118,12 +118,12 @@ void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, real_t p_s if (mirroring.x) { real_t den = mirroring.x * p_scale; - new_ofs.x -= den * ceil(new_ofs.x / den); + new_ofs.x -= den * std::ceil(new_ofs.x / den); } if (mirroring.y) { real_t den = mirroring.y * p_scale; - new_ofs.y -= den * ceil(new_ofs.y / den); + new_ofs.y -= den * std::ceil(new_ofs.y / den); } set_position(new_ofs); diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp index 31fbfd26532..3b986e5845f 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -330,7 +330,7 @@ void PathFollow2D::_bind_methods() { } void PathFollow2D::set_progress(real_t p_progress) { - ERR_FAIL_COND(!isfinite(p_progress)); + ERR_FAIL_COND(!std::isfinite(p_progress)); progress = p_progress; if (path) { if (path->get_curve().is_valid()) { diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 5ab8b552323..210b3219864 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -83,13 +83,13 @@ public: const Speaker *r = speakers.ptr(); real_t sum_squared_gains = 0.0; for (unsigned int speaker_num = 0; speaker_num < (unsigned int)speakers.size(); speaker_num++) { - real_t initial_gain = 0.5 * powf(1.0 + r[speaker_num].direction.dot(source_direction), tightness) / r[speaker_num].effective_number_of_speakers; + real_t initial_gain = 0.5 * std::pow(1.0 + r[speaker_num].direction.dot(source_direction), tightness) / r[speaker_num].effective_number_of_speakers; r[speaker_num].squared_gain = initial_gain * initial_gain; sum_squared_gains += r[speaker_num].squared_gain; } for (unsigned int speaker_num = 0; speaker_num < MIN(volume_count, (unsigned int)speakers.size()); speaker_num++) { - volumes[speaker_num] = sqrtf(r[speaker_num].squared_gain / sum_squared_gains); + volumes[speaker_num] = std::sqrt(r[speaker_num].squared_gain / sum_squared_gains); } } }; diff --git a/scene/3d/look_at_modifier_3d.cpp b/scene/3d/look_at_modifier_3d.cpp index 2ed065514dc..ea17f5a76a4 100644 --- a/scene/3d/look_at_modifier_3d.cpp +++ b/scene/3d/look_at_modifier_3d.cpp @@ -549,7 +549,7 @@ void LookAtModifier3D::_process_modification(double p_delta) { (prev_forward_vector != Vector3(0, 0, 0) && forward_vector == Vector3(0, 0, 0)) || (prev_forward_vector == Vector3(0, 0, 0) && forward_vector != Vector3(0, 0, 0))) { init_transition(); - } else if (is_flippable && signbit(prev_forward_vector[secondary_rotation_axis]) != signbit(forward_vector[secondary_rotation_axis])) { + } else if (is_flippable && std::signbit(prev_forward_vector[secondary_rotation_axis]) != std::signbit(forward_vector[secondary_rotation_axis])) { // Flipping by angle_limitation can be detected by sign of secondary rotation axes during forward_vector is rotated more than 90 degree from forward_axis (means dot production is negative). Vector3 prev_forward_vector_nrm = forward_vector.normalized(); Vector3 rest_forward_vector = get_vector_from_bone_axis(forward_axis); @@ -596,7 +596,7 @@ bool LookAtModifier3D::is_intersecting_axis(const Vector3 &p_prev, const Vector3 return false; } - return signbit(p_prev[p_flipping_axis]) != signbit(p_current[p_flipping_axis]); + return std::signbit(p_prev[p_flipping_axis]) != std::signbit(p_current[p_flipping_axis]); } Vector3 LookAtModifier3D::get_basis_vector_from_bone_axis(const Basis &p_basis, BoneAxis p_axis) { @@ -647,7 +647,7 @@ Vector2 LookAtModifier3D::get_projection_vector(const Vector3 &p_vector, Vector3 } float LookAtModifier3D::remap_damped(float p_from, float p_to, float p_damp_threshold, float p_value) const { - float sign = signbit(p_value) ? -1.0f : 1.0f; + float sign = std::signbit(p_value) ? -1.0f : 1.0f; float abs_value = Math::abs(p_value); if (Math::is_equal_approx(p_damp_threshold, 1.0f) || Math::is_zero_approx(p_to)) { @@ -707,7 +707,7 @@ Transform3D LookAtModifier3D::look_at_with_axes(const Transform3D &p_rest) { limit_angle = primary_limit_angle * 0.5f; damp_threshold = primary_damp_threshold; } else { - if (signbit(calculated_angle)) { + if (std::signbit(calculated_angle)) { limit_angle = primary_negative_limit_angle; damp_threshold = primary_negative_damp_threshold; } else { @@ -740,7 +740,7 @@ Transform3D LookAtModifier3D::look_at_with_axes(const Transform3D &p_rest) { limit_angle = secondary_limit_angle * 0.5f; damp_threshold = secondary_damp_threshold; } else { - if (signbit(calculated_angle)) { + if (std::signbit(calculated_angle)) { limit_angle = secondary_negative_limit_angle; damp_threshold = secondary_negative_damp_threshold; } else { diff --git a/scene/3d/mesh_instance_3d.cpp b/scene/3d/mesh_instance_3d.cpp index 8e68e8fca77..41977b78d86 100644 --- a/scene/3d/mesh_instance_3d.cpp +++ b/scene/3d/mesh_instance_3d.cpp @@ -591,7 +591,7 @@ Ref MeshInstance3D::bake_mesh_from_current_blend_shape_mix(Ref CMP_EPSILON) ? Vector3(-dir.y, dir.x, 0).normalized() : Vector3(0, -dir.z, dir.y).normalized(); + Vector3 normal = (std::abs(dir.x) + std::abs(dir.y) > CMP_EPSILON) ? Vector3(-dir.y, dir.x, 0).normalized() : Vector3(0, -dir.z, dir.y).normalized(); normal *= debug_shape_thickness / scale_factor; int vertices_strip_order[14] = { 4, 5, 0, 1, 2, 5, 6, 4, 7, 0, 3, 2, 7, 6 }; for (int v = 0; v < 14; v++) { diff --git a/scene/3d/spring_bone_simulator_3d.cpp b/scene/3d/spring_bone_simulator_3d.cpp index cf2e672289e..605fcc1cfe0 100644 --- a/scene/3d/spring_bone_simulator_3d.cpp +++ b/scene/3d/spring_bone_simulator_3d.cpp @@ -1298,7 +1298,7 @@ void SpringBoneSimulator3D::_validate_rotation_axis(Skeleton3D *p_skeleton, int } } fwd.normalize(); - if (Math::is_equal_approx(Math::absf(rot.dot(fwd)), 1.0f)) { + if (Math::is_equal_approx(Math::abs(rot.dot(fwd)), 1)) { WARN_PRINT_ED("Setting: " + itos(p_index) + " Joint: " + itos(p_joint) + ": Rotation axis and forward vectors are colinear. This is not advised as it may cause unwanted rotation."); } } diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index 4f2f24118ab..b7a969fd209 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -1112,7 +1112,7 @@ void AnimatedSprite3D::_notification(int p_what) { int fc = frames->get_frame_count(animation); int last_frame = fc - 1; - if (!signbit(speed)) { + if (!std::signbit(speed)) { // Forwards. if (frame_progress >= 1.0) { if (frame >= last_frame) { @@ -1210,7 +1210,7 @@ Ref AnimatedSprite3D::get_sprite_frames() const { } void AnimatedSprite3D::set_frame(int p_frame) { - set_frame_and_progress(p_frame, signbit(get_playing_speed()) ? 1.0 : 0.0); + set_frame_and_progress(p_frame, std::signbit(get_playing_speed()) ? 1.0 : 0.0); } int AnimatedSprite3D::get_frame() const { @@ -1347,7 +1347,7 @@ void AnimatedSprite3D::play(const StringName &p_name, float p_custom_scale, bool emit_signal(SceneStringName(animation_changed)); } else { int end_frame = MAX(0, frames->get_frame_count(animation) - 1); - bool is_backward = signbit(speed_scale * custom_speed_scale); + bool is_backward = std::signbit(speed_scale * custom_speed_scale); if (p_from_end && is_backward && frame == 0 && frame_progress <= 0.0) { set_frame_and_progress(end_frame, 1.0); @@ -1419,7 +1419,7 @@ void AnimatedSprite3D::set_animation(const StringName &p_name) { ERR_FAIL_MSG(vformat("There is no animation with name '%s'.", p_name)); } - if (signbit(get_playing_speed())) { + if (std::signbit(get_playing_speed())) { set_frame_and_progress(frame_count - 1, 1.0); } else { set_frame_and_progress(0, 0.0); diff --git a/scene/animation/animation_blend_space_1d.cpp b/scene/animation/animation_blend_space_1d.cpp index acbc892d478..5d69b87e495 100644 --- a/scene/animation/animation_blend_space_1d.cpp +++ b/scene/animation/animation_blend_space_1d.cpp @@ -366,7 +366,7 @@ AnimationNode::NodeTimeInfo AnimationNodeBlendSpace1D::_process(const AnimationM double new_closest_dist = 1e20; for (int i = 0; i < blend_points_used; i++) { - double d = abs(blend_points[i].position - blend_pos); + double d = std::abs(blend_points[i].position - blend_pos); if (d < new_closest_dist) { new_closest = i; new_closest_dist = d; diff --git a/scene/animation/animation_mixer.cpp b/scene/animation/animation_mixer.cpp index c4d6718d4e9..60a857698c6 100644 --- a/scene/animation/animation_mixer.cpp +++ b/scene/animation/animation_mixer.cpp @@ -1178,8 +1178,8 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) { real_t weight = ai.playback_info.weight; const real_t *track_weights_ptr = ai.playback_info.track_weights.ptr(); int track_weights_count = ai.playback_info.track_weights.size(); - bool backward = signbit(delta); // This flag is used by the root motion calculates or detecting the end of audio stream. - bool seeked_backward = signbit(p_delta); + bool backward = std::signbit(delta); // This flag is used by the root motion calculates or detecting the end of audio stream. + bool seeked_backward = std::signbit(p_delta); #ifndef _3D_DISABLED bool calc_root = !seeked || is_external_seeking; #endif // _3D_DISABLED diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 680fd5c3369..c9af9ba3c96 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -160,7 +160,7 @@ void AnimationPlayer::_notification(int p_what) { void AnimationPlayer::_process_playback_data(PlaybackData &cd, double p_delta, float p_blend, bool p_seeked, bool p_internal_seeked, bool p_started, bool p_is_current) { double speed = speed_scale * cd.speed_scale; - bool backwards = signbit(speed); // Negative zero means playing backwards too. + bool backwards = std::signbit(speed); // Negative zero means playing backwards too. double delta = p_started ? 0 : p_delta * speed; double next_pos = cd.pos + delta; @@ -284,7 +284,7 @@ void AnimationPlayer::_blend_playback_data(double p_delta, bool p_started) { List::Element *> to_erase; for (List::Element *E = c.blend.front(); E; E = E->next()) { Blend &b = E->get(); - b.blend_left = MAX(0, b.blend_left - Math::absf(speed_scale * p_delta) / b.blend_time); + b.blend_left = MAX(0, b.blend_left - Math::abs(speed_scale * p_delta) / b.blend_time); if (Animation::is_less_or_equal_approx(b.blend_left, 0)) { to_erase.push_back(E); b.blend_left = CMP_EPSILON; // May want to play last frame. @@ -546,7 +546,7 @@ void AnimationPlayer::_capture(const StringName &p_name, bool p_from_end, double if (anim.is_null() || !anim->is_capture_included()) { return; } - if (signbit(p_duration)) { + if (std::signbit(p_duration)) { double max_dur = 0; double current_pos = playback.current.pos; if (playback.assigned != name) { @@ -588,7 +588,7 @@ void AnimationPlayer::set_current_animation(const String &p_animation) { play(p_animation); } else if (playback.assigned != p_animation) { float speed = playback.current.speed_scale; - play(p_animation, -1.0, speed, signbit(speed)); + play(p_animation, -1.0, speed, std::signbit(speed)); } else { // Same animation, do not replay from start. } @@ -601,7 +601,7 @@ String AnimationPlayer::get_current_animation() const { void AnimationPlayer::set_assigned_animation(const String &p_animation) { if (is_playing()) { float speed = playback.current.speed_scale; - play(p_animation, -1.0, speed, signbit(speed)); + play(p_animation, -1.0, speed, std::signbit(speed)); } else { ERR_FAIL_COND_MSG(!animation_set.has(p_animation), vformat("Animation not found: %s.", p_animation)); playback.current.pos = 0; diff --git a/scene/animation/easing_equations.h b/scene/animation/easing_equations.h index c1bfaf04988..a758910ab62 100644 --- a/scene/animation/easing_equations.h +++ b/scene/animation/easing_equations.h @@ -30,6 +30,8 @@ #pragma once +#include "core/math/math_funcs.h" + /* * Derived from Robert Penner's easing equations: http://robertpenner.com/easing/ * @@ -62,15 +64,15 @@ static real_t in(real_t t, real_t b, real_t c, real_t d) { namespace Sine { static real_t in(real_t t, real_t b, real_t c, real_t d) { - return -c * cos(t / d * (Math::PI / 2)) + c + b; + return -c * std::cos(t / d * (Math::PI / 2)) + c + b; } static real_t out(real_t t, real_t b, real_t c, real_t d) { - return c * sin(t / d * (Math::PI / 2)) + b; + return c * std::sin(t / d * (Math::PI / 2)) + b; } static real_t in_out(real_t t, real_t b, real_t c, real_t d) { - return -c / 2 * (cos(Math::PI * t / d) - 1) + b; + return -c / 2 * (std::cos(Math::PI * t / d) - 1) + b; } static real_t out_in(real_t t, real_t b, real_t c, real_t d) { @@ -84,20 +86,20 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) { namespace Quint { static real_t in(real_t t, real_t b, real_t c, real_t d) { - return c * pow(t / d, 5) + b; + return c * std::pow(t / d, 5) + b; } static real_t out(real_t t, real_t b, real_t c, real_t d) { - return c * (pow(t / d - 1, 5) + 1) + b; + return c * (std::pow(t / d - 1, 5) + 1) + b; } static real_t in_out(real_t t, real_t b, real_t c, real_t d) { t = t / d * 2; if (t < 1) { - return c / 2 * pow(t, 5) + b; + return c / 2 * std::pow(t, 5) + b; } - return c / 2 * (pow(t - 2, 5) + 2) + b; + return c / 2 * (std::pow(t - 2, 5) + 2) + b; } static real_t out_in(real_t t, real_t b, real_t c, real_t d) { @@ -111,20 +113,20 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) { namespace Quart { static real_t in(real_t t, real_t b, real_t c, real_t d) { - return c * pow(t / d, 4) + b; + return c * std::pow(t / d, 4) + b; } static real_t out(real_t t, real_t b, real_t c, real_t d) { - return -c * (pow(t / d - 1, 4) - 1) + b; + return -c * (std::pow(t / d - 1, 4) - 1) + b; } static real_t in_out(real_t t, real_t b, real_t c, real_t d) { t = t / d * 2; if (t < 1) { - return c / 2 * pow(t, 4) + b; + return c / 2 * std::pow(t, 4) + b; } - return -c / 2 * (pow(t - 2, 4) - 2) + b; + return -c / 2 * (std::pow(t - 2, 4) - 2) + b; } static real_t out_in(real_t t, real_t b, real_t c, real_t d) { @@ -138,7 +140,7 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) { namespace Quad { static real_t in(real_t t, real_t b, real_t c, real_t d) { - return c * pow(t / d, 2) + b; + return c * std::pow(t / d, 2) + b; } static real_t out(real_t t, real_t b, real_t c, real_t d) { @@ -150,7 +152,7 @@ static real_t in_out(real_t t, real_t b, real_t c, real_t d) { t = t / d * 2; if (t < 1) { - return c / 2 * pow(t, 2) + b; + return c / 2 * std::pow(t, 2) + b; } return -c / 2 * ((t - 1) * (t - 3) - 1) + b; } @@ -169,14 +171,14 @@ static real_t in(real_t t, real_t b, real_t c, real_t d) { if (t == 0) { return b; } - return c * pow(2, 10 * (t / d - 1)) + b - c * 0.001; + return c * std::pow(2, 10 * (t / d - 1)) + b - c * 0.001; } static real_t out(real_t t, real_t b, real_t c, real_t d) { if (t == d) { return b + c; } - return c * 1.001 * (-pow(2, -10 * t / d) + 1) + b; + return c * 1.001 * (-std::pow(2, -10 * t / d) + 1) + b; } static real_t in_out(real_t t, real_t b, real_t c, real_t d) { @@ -191,9 +193,9 @@ static real_t in_out(real_t t, real_t b, real_t c, real_t d) { t = t / d * 2; if (t < 1) { - return c / 2 * pow(2, 10 * (t - 1)) + b - c * 0.0005; + return c / 2 * std::pow(2, 10 * (t - 1)) + b - c * 0.0005; } - return c / 2 * 1.0005 * (-pow(2, -10 * (t - 1)) + 2) + b; + return c / 2 * 1.0005 * (-std::pow(2, -10 * (t - 1)) + 2) + b; } static real_t out_in(real_t t, real_t b, real_t c, real_t d) { @@ -218,10 +220,10 @@ static real_t in(real_t t, real_t b, real_t c, real_t d) { t -= 1; float p = d * 0.3f; - float a = c * pow(2, 10 * t); + float a = c * std::pow(2, 10 * t); float s = p / 4; - return -(a * sin((t * d - s) * (2 * Math::PI) / p)) + b; + return -(a * std::sin((t * d - s) * (2 * Math::PI) / p)) + b; } static real_t out(real_t t, real_t b, real_t c, real_t d) { @@ -237,7 +239,7 @@ static real_t out(real_t t, real_t b, real_t c, real_t d) { float p = d * 0.3f; float s = p / 4; - return (c * pow(2, -10 * t) * sin((t * d - s) * (2 * Math::PI) / p) + c + b); + return (c * std::pow(2, -10 * t) * std::sin((t * d - s) * (2 * Math::PI) / p) + c + b); } static real_t in_out(real_t t, real_t b, real_t c, real_t d) { @@ -255,13 +257,13 @@ static real_t in_out(real_t t, real_t b, real_t c, real_t d) { if (t < 1) { t -= 1; - a *= pow(2, 10 * t); - return -0.5f * (a * sin((t * d - s) * (2 * Math::PI) / p)) + b; + a *= std::pow(2, 10 * t); + return -0.5f * (a * std::sin((t * d - s) * (2 * Math::PI) / p)) + b; } t -= 1; - a *= pow(2, -10 * t); - return a * sin((t * d - s) * (2 * Math::PI) / p) * 0.5f + c + b; + a *= std::pow(2, -10 * t); + return a * std::sin((t * d - s) * (2 * Math::PI) / p) * 0.5f + c + b; } static real_t out_in(real_t t, real_t b, real_t c, real_t d) { @@ -306,22 +308,22 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) { namespace Circ { static real_t in(real_t t, real_t b, real_t c, real_t d) { t /= d; - return -c * (sqrt(1 - t * t) - 1) + b; + return -c * (std::sqrt(1 - t * t) - 1) + b; } static real_t out(real_t t, real_t b, real_t c, real_t d) { t = t / d - 1; - return c * sqrt(1 - t * t) + b; + return c * std::sqrt(1 - t * t) + b; } static real_t in_out(real_t t, real_t b, real_t c, real_t d) { t /= d / 2; if (t < 1) { - return -c / 2 * (sqrt(1 - t * t) - 1) + b; + return -c / 2 * (std::sqrt(1 - t * t) - 1) + b; } t -= 2; - return c / 2 * (sqrt(1 - t * t) + 1) + b; + return c / 2 * (std::sqrt(1 - t * t) + 1) + b; } static real_t out_in(real_t t, real_t b, real_t c, real_t d) { @@ -416,7 +418,7 @@ namespace Spring { static real_t out(real_t t, real_t b, real_t c, real_t d) { t /= d; real_t s = 1.0 - t; - t = (sin(t * Math::PI * (0.2 + 2.5 * t * t * t)) * pow(s, 2.2) + t) * (1.0 + (1.2 * s)); + t = (std::sin(t * Math::PI * (0.2 + 2.5 * t * t * t)) * std::pow(s, 2.2) + t) * (1.0 + (1.2 * s)); return c * t + b; } diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index c2aaf8e6728..fd04fb8b6d6 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -3731,7 +3731,7 @@ void CodeEdit::_text_changed() { } int lc = get_line_count(); - int new_line_number_digits = log10l(lc) + 1; + int new_line_number_digits = std::log10(lc) + 1; if (line_number_digits != new_line_number_digits) { _clear_line_number_text_cache(); } diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index ff52236c0bf..c501c31a372 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -150,7 +150,7 @@ bool Control::_edit_use_rotation() const { void Control::_edit_set_pivot(const Point2 &p_pivot) { Vector2 delta_pivot = p_pivot - get_pivot_offset(); - Vector2 move = Vector2((cos(data.rotation) - 1.0) * delta_pivot.x - sin(data.rotation) * delta_pivot.y, sin(data.rotation) * delta_pivot.x + (cos(data.rotation) - 1.0) * delta_pivot.y); + Vector2 move = Vector2((std::cos(data.rotation) - 1.0) * delta_pivot.x - std::sin(data.rotation) * delta_pivot.y, std::sin(data.rotation) * delta_pivot.x + (std::cos(data.rotation) - 1.0) * delta_pivot.y); set_position(get_position() + move); set_pivot_offset(p_pivot); } @@ -790,7 +790,7 @@ void Control::set_anchor_and_offset(Side p_side, real_t p_anchor, real_t p_pos, void Control::set_begin(const Point2 &p_point) { ERR_MAIN_THREAD_GUARD; - ERR_FAIL_COND(!isfinite(p_point.x) || !isfinite(p_point.y)); + ERR_FAIL_COND(!std::isfinite(p_point.x) || !std::isfinite(p_point.y)); if (data.offset[0] == p_point.x && data.offset[1] == p_point.y) { return; } @@ -1471,7 +1471,7 @@ void Control::_set_size(const Size2 &p_size) { void Control::set_size(const Size2 &p_size, bool p_keep_offsets) { ERR_MAIN_THREAD_GUARD; - ERR_FAIL_COND(!isfinite(p_size.x) || !isfinite(p_size.y)); + ERR_FAIL_COND(!std::isfinite(p_size.x) || !std::isfinite(p_size.y)); Size2 new_size = p_size; Size2 min = get_combined_minimum_size(); if (new_size.x < min.x) { @@ -1683,7 +1683,7 @@ void Control::set_custom_minimum_size(const Size2 &p_custom) { return; } - if (!isfinite(p_custom.x) || !isfinite(p_custom.y)) { + if (!std::isfinite(p_custom.x) || !std::isfinite(p_custom.y)) { // Prevent infinite loop. return; } diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index e14556cf50c..100d8cd2587 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -2430,8 +2430,8 @@ float GraphEdit::get_zoom() const { } void GraphEdit::set_zoom_step(float p_zoom_step) { - p_zoom_step = abs(p_zoom_step); - ERR_FAIL_COND(!isfinite(p_zoom_step)); + p_zoom_step = std::abs(p_zoom_step); + ERR_FAIL_COND(!std::isfinite(p_zoom_step)); if (zoom_step == p_zoom_step) { return; } diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp index 0fdca084895..75de126b9f1 100644 --- a/scene/gui/grid_container.cpp +++ b/scene/gui/grid_container.cpp @@ -74,7 +74,7 @@ void GridContainer::_notification(int p_what) { } int max_col = MIN(valid_controls_index, columns); - int max_row = ceil((float)valid_controls_index / (float)columns); + int max_row = std::ceil((float)valid_controls_index / (float)columns); // Consider all empty columns expanded. for (int i = valid_controls_index; i < columns; i++) { diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 29c52f7a11c..5cb0cf3a5d8 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -1435,7 +1435,7 @@ void LineEdit::_notification(int p_what) { Vector2 oofs = ofs; for (int i = 0; i < gl_size; i++) { for (int j = 0; j < glyphs[i].repeat; j++) { - if (ceil(oofs.x) >= x_ofs && (oofs.x + glyphs[i].advance) <= ofs_max) { + if (std::ceil(oofs.x) >= x_ofs && (oofs.x + glyphs[i].advance) <= ofs_max) { if (glyphs[i].font_rid != RID()) { TS->font_draw_glyph_outline(glyphs[i].font_rid, ci, glyphs[i].font_size, outline_size, oofs + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, font_outline_color); } @@ -1450,7 +1450,7 @@ void LineEdit::_notification(int p_what) { for (int i = 0; i < gl_size; i++) { bool selected = selection.enabled && glyphs[i].start >= selection.begin && glyphs[i].end <= selection.end; for (int j = 0; j < glyphs[i].repeat; j++) { - if (ceil(ofs.x) >= x_ofs && (ofs.x + glyphs[i].advance) <= ofs_max) { + if (std::ceil(ofs.x) >= x_ofs && (ofs.x + glyphs[i].advance) <= ofs_max) { if (glyphs[i].font_rid != RID()) { TS->font_draw_glyph(glyphs[i].font_rid, ci, glyphs[i].font_size, ofs + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, selected ? font_selected_color : font_color); } else if (((glyphs[i].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) && ((glyphs[i].flags & TextServer::GRAPHEME_IS_EMBEDDED_OBJECT) != TextServer::GRAPHEME_IS_EMBEDDED_OBJECT)) { @@ -1789,7 +1789,7 @@ void LineEdit::set_caret_at_pixel_pos(int p_x) { } } - int ofs = ceil(TS->shaped_text_hit_test_position(text_rid, p_x - x_ofs - scroll_offset)); + int ofs = std::ceil(TS->shaped_text_hit_test_position(text_rid, p_x - x_ofs - scroll_offset)); if (!caret_mid_grapheme_enabled) { ofs = TS->shaped_text_closest_character_pos(text_rid, ofs); } diff --git a/scene/gui/progress_bar.cpp b/scene/gui/progress_bar.cpp index 0e2e18ce179..a24e3ddad9c 100644 --- a/scene/gui/progress_bar.cpp +++ b/scene/gui/progress_bar.cpp @@ -114,13 +114,13 @@ void ProgressBar::_notification(int p_what) { case FILL_BEGIN_TO_END: case FILL_END_TO_BEGIN: { int mp = theme_cache.fill_style->get_minimum_size().width; - int p = round(r * (get_size().width - mp)); + int p = std::round(r * (get_size().width - mp)); // We want FILL_BEGIN_TO_END to map to right to left when UI layout is RTL, // and left to right otherwise. And likewise for FILL_END_TO_BEGIN. bool right_to_left = mode == (is_layout_rtl() ? FILL_BEGIN_TO_END : FILL_END_TO_BEGIN); if (p > 0) { if (right_to_left) { - int p_remaining = round((1.0 - r) * (get_size().width - mp)); + int p_remaining = std::round((1.0 - r) * (get_size().width - mp)); draw_style_box(theme_cache.fill_style, Rect2(Point2(p_remaining, 0), Size2(p + theme_cache.fill_style->get_minimum_size().width, get_size().height))); } else { draw_style_box(theme_cache.fill_style, Rect2(Point2(0, 0), Size2(p + theme_cache.fill_style->get_minimum_size().width, get_size().height))); @@ -130,13 +130,13 @@ void ProgressBar::_notification(int p_what) { case FILL_TOP_TO_BOTTOM: case FILL_BOTTOM_TO_TOP: { int mp = theme_cache.fill_style->get_minimum_size().height; - int p = round(r * (get_size().height - mp)); + int p = std::round(r * (get_size().height - mp)); if (p > 0) { if (mode == FILL_TOP_TO_BOTTOM) { draw_style_box(theme_cache.fill_style, Rect2(Point2(0, 0), Size2(get_size().width, p + theme_cache.fill_style->get_minimum_size().height))); } else { - int p_remaining = round((1.0 - r) * (get_size().height - mp)); + int p_remaining = std::round((1.0 - r) * (get_size().height - mp)); draw_style_box(theme_cache.fill_style, Rect2(Point2(0, p_remaining), Size2(get_size().width, p + theme_cache.fill_style->get_minimum_size().height))); } } diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index fc096c05b2c..9593f31bc4e 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -258,7 +258,7 @@ void Range::set_as_ratio(double p_value) { } else { double percent = (get_max() - get_min()) * p_value; if (get_step() > 0) { - double steps = round(percent / get_step()); + double steps = std::round(percent / get_step()); v = steps * get_step() + get_min(); } else { v = percent + get_min(); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 584daacf2ce..2448db6b7fb 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -630,8 +630,8 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref t_char_count += cell_ch; remaining_characters -= cell_ch; - table->columns[column].min_width = MAX(table->columns[column].min_width, frame->lines[i].indent + ceil(frame->lines[i].text_buf->get_size().x)); - table->columns[column].max_width = MAX(table->columns[column].max_width, frame->lines[i].indent + ceil(frame->lines[i].text_buf->get_non_wrapped_size().x)); + table->columns[column].min_width = MAX(table->columns[column].min_width, frame->lines[i].indent + std::ceil(frame->lines[i].text_buf->get_size().x)); + table->columns[column].max_width = MAX(table->columns[column].max_width, frame->lines[i].indent + std::ceil(frame->lines[i].text_buf->get_non_wrapped_size().x)); } idx++; } @@ -755,8 +755,8 @@ void RichTextLabel::_set_table_size(ItemTable *p_table, int p_available_width) { MutexLock sub_lock(frame->lines[i].text_buf->get_mutex()); frame->lines[i].text_buf->set_width(p_table->columns[column].width); - p_table->columns[column].width = MAX(p_table->columns[column].width, ceil(frame->lines[i].text_buf->get_size().x)); - p_table->columns[column].width_with_padding = MAX(p_table->columns[column].width_with_padding, ceil(frame->lines[i].text_buf->get_size().x + frame->padding.position.x + frame->padding.size.x)); + p_table->columns[column].width = MAX(p_table->columns[column].width, std::ceil(frame->lines[i].text_buf->get_size().x)); + p_table->columns[column].width_with_padding = MAX(p_table->columns[column].width_with_padding, std::ceil(frame->lines[i].text_buf->get_size().x + frame->padding.position.x + frame->padding.size.x)); frame->lines[i].offset.y = prev_h; @@ -2404,9 +2404,9 @@ void RichTextLabel::_notification(int p_what) { bool right_to_left = is_layout_rtl(); double r = loaded.load(); int mp = theme_cache.progress_fg_style->get_minimum_size().width; - int p = round(r * (p_size.width - mp)); + int p = std::round(r * (p_size.width - mp)); if (right_to_left) { - int p_remaining = round((1.0 - r) * (p_size.width - mp)); + int p_remaining = std::round((1.0 - r) * (p_size.width - mp)); draw_style_box(theme_cache.progress_fg_style, Rect2(p_pos + Point2(p_remaining, 0), Size2(p + theme_cache.progress_fg_style->get_minimum_size().width, p_size.height))); } else { draw_style_box(theme_cache.progress_fg_style, Rect2(p_pos, Size2(p + theme_cache.progress_fg_style->get_minimum_size().width, p_size.height))); diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index d8a8ea01f42..ec2c46147ba 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -334,7 +334,7 @@ void ScrollBar::_notification(int p_what) { if (scrolling) { if (get_value() != target_scroll) { double target = target_scroll - get_value(); - double dist = abs(target); + double dist = std::abs(target); double vel = ((target / dist) * 500) * get_process_delta_time(); if (Math::abs(vel) >= dist) { diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 32ab5b71dd9..6afdb085330 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -808,7 +808,7 @@ void TextEdit::_notification(int p_what) { case NOTIFICATION_INTERNAL_PROCESS: { if (scrolling && get_v_scroll() != target_v_scroll) { double target_y = target_v_scroll - get_v_scroll(); - double dist = abs(target_y); + double dist = std::abs(target_y); // To ensure minimap is responsive override the speed setting. double vel = ((target_y / dist) * ((minimap_clicked) ? 3000 : v_scroll_speed)) * get_process_delta_time(); @@ -1055,10 +1055,10 @@ void TextEdit::_notification(int p_what) { // Calculate viewport size and y offset. int viewport_height = (draw_amount - 1) * minimap_line_height; int control_height = _get_control_height() - viewport_height; - int viewport_offset_y = round(get_scroll_pos_for_line(first_vis_line + 1) * control_height) / ((v_scroll->get_max() <= minimap_visible_lines) ? (minimap_visible_lines - draw_amount) : (v_scroll->get_max() - draw_amount)); + int viewport_offset_y = std::round(get_scroll_pos_for_line(first_vis_line + 1) * control_height) / ((v_scroll->get_max() <= minimap_visible_lines) ? (minimap_visible_lines - draw_amount) : (v_scroll->get_max() - draw_amount)); // Calculate the first line. - int num_lines_before = round((viewport_offset_y) / minimap_line_height); + int num_lines_before = std::round((viewport_offset_y) / minimap_line_height); int minimap_line = (v_scroll->get_max() <= minimap_visible_lines) ? -1 : first_vis_line; if (minimap_line >= 0) { minimap_line -= get_next_visible_line_index_offset_from(first_vis_line, 0, -num_lines_before).x; @@ -1388,9 +1388,9 @@ void TextEdit::_notification(int p_what) { float icon_ratio = icon->get_width() / icon->get_height(); float gutter_ratio = gutter_rect.size.x / gutter_rect.size.y; if (gutter_ratio > icon_ratio) { - gutter_rect.size.x = floor(icon->get_width() * (gutter_rect.size.y / icon->get_height())); + gutter_rect.size.x = std::floor(icon->get_width() * (gutter_rect.size.y / icon->get_height())); } else { - gutter_rect.size.y = floor(icon->get_height() * (gutter_rect.size.x / icon->get_width())); + gutter_rect.size.y = std::floor(icon->get_height() * (gutter_rect.size.x / icon->get_width())); } if (rtl) { gutter_rect.position.x = size.width - gutter_rect.position.x - gutter_rect.size.x; @@ -1525,7 +1525,7 @@ void TextEdit::_notification(int p_what) { } else if (rect.position.x + rect.size.x > xmargin_end) { rect.size.x = xmargin_end - rect.position.x; } - rect.position.y += ceil(TS->shaped_text_get_ascent(rid)) + ceil(theme_cache.font->get_underline_position(theme_cache.font_size)); + rect.position.y += std::ceil(TS->shaped_text_get_ascent(rid)) + std::ceil(theme_cache.font->get_underline_position(theme_cache.font_size)); rect.size.y = MAX(1, theme_cache.font->get_underline_thickness(theme_cache.font_size)); RS::get_singleton()->canvas_item_add_rect(ci, rect, highlight_underline_color); } @@ -4970,10 +4970,10 @@ int TextEdit::get_minimap_line_at_pos(const Point2i &p_pos) const { // Calculate viewport size and y offset. int viewport_height = (draw_amount - 1) * minimap_line_height; int control_height = _get_control_height() - viewport_height; - int viewport_offset_y = round(get_scroll_pos_for_line(first_vis_line + 1) * control_height) / ((v_scroll->get_max() <= minimap_visible_lines) ? (minimap_visible_lines - draw_amount) : (v_scroll->get_max() - draw_amount)); + int viewport_offset_y = std::round(get_scroll_pos_for_line(first_vis_line + 1) * control_height) / ((v_scroll->get_max() <= minimap_visible_lines) ? (minimap_visible_lines - draw_amount) : (v_scroll->get_max() - draw_amount)); // Calculate the first line. - int num_lines_before = round((viewport_offset_y) / minimap_line_height); + int num_lines_before = std::round((viewport_offset_y) / minimap_line_height); int minimap_line = (v_scroll->get_max() <= minimap_visible_lines) ? -1 : first_vis_line; if (first_vis_line > 0 && minimap_line >= 0) { minimap_line -= get_next_visible_line_index_offset_from(first_vis_line, 0, -num_lines_before).x; @@ -8471,7 +8471,7 @@ void TextEdit::_update_scrollbars() { if (first_visible_col > (total_width - visible_width)) { first_visible_col = (total_width - visible_width); } - if (fabs(h_scroll->get_value() - (double)first_visible_col) >= 1) { + if (std::fabs(h_scroll->get_value() - (double)first_visible_col) >= 1) { h_scroll->set_value(first_visible_col); } @@ -8511,7 +8511,7 @@ void TextEdit::_scroll_moved(double p_to_val) { // Set line ofs and wrap ofs. bool draw_placeholder = _using_placeholder(); - int v_scroll_i = floor(get_v_scroll()); + int v_scroll_i = std::floor(get_v_scroll()); int sc = 0; int n_line; for (n_line = 0; n_line < text.size(); n_line++) { @@ -8538,13 +8538,13 @@ void TextEdit::_scroll_moved(double p_to_val) { double TextEdit::_get_visible_lines_offset() const { double total = _get_control_height(); total /= (double)get_line_height(); - total = total - floor(total); + total = total - std::floor(total); total = -CLAMP(total, 0.001, 1) + 1; return total; } double TextEdit::_get_v_scroll_offset() const { - double val = get_v_scroll() - floor(get_v_scroll()); + double val = get_v_scroll() - std::floor(get_v_scroll()); return CLAMP(val, 0, 1); } @@ -8589,7 +8589,7 @@ void TextEdit::_scroll_down(real_t p_delta, bool p_animate) { } if (smooth_scroll_enabled) { - int max_v_scroll = round(v_scroll->get_max() - v_scroll->get_page()); + int max_v_scroll = std::round(v_scroll->get_max() - v_scroll->get_page()); if (target_v_scroll > max_v_scroll) { target_v_scroll = max_v_scroll; } diff --git a/scene/resources/2d/skeleton/skeleton_modification_2d_twoboneik.cpp b/scene/resources/2d/skeleton/skeleton_modification_2d_twoboneik.cpp index 1c3aad7fe62..310abf84fb9 100644 --- a/scene/resources/2d/skeleton/skeleton_modification_2d_twoboneik.cpp +++ b/scene/resources/2d/skeleton/skeleton_modification_2d_twoboneik.cpp @@ -174,7 +174,7 @@ void SkeletonModification2DTwoBoneIK::_execute(float p_delta) { angle_1 = -angle_1; } - if (isnan(angle_0) || isnan(angle_1)) { + if (std::isnan(angle_0) || std::isnan(angle_1)) { // We cannot solve for this angle! Do nothing to avoid setting the rotation (and scale) to NaN. } else { joint_one_bone->set_global_rotation(angle_atan - angle_0 - joint_one_bone->get_bone_angle()); @@ -222,10 +222,10 @@ void SkeletonModification2DTwoBoneIK::_draw_editor_gizmo() { if (flip_bend_direction) { float angle = -(Math::PI * 0.5) + operation_bone_one->get_bone_angle(); - stack->skeleton->draw_line(Vector2(0, 0), Vector2(Math::cos(angle), sin(angle)) * (operation_bone_one->get_length() * 0.5), bone_ik_color, 2.0); + stack->skeleton->draw_line(Vector2(0, 0), Vector2(Math::cos(angle), std::sin(angle)) * (operation_bone_one->get_length() * 0.5), bone_ik_color, 2.0); } else { float angle = (Math::PI * 0.5) + operation_bone_one->get_bone_angle(); - stack->skeleton->draw_line(Vector2(0, 0), Vector2(Math::cos(angle), sin(angle)) * (operation_bone_one->get_length() * 0.5), bone_ik_color, 2.0); + stack->skeleton->draw_line(Vector2(0, 0), Vector2(Math::cos(angle), std::sin(angle)) * (operation_bone_one->get_length() * 0.5), bone_ik_color, 2.0); } #ifdef TOOLS_ENABLED diff --git a/scene/resources/animated_texture.cpp b/scene/resources/animated_texture.cpp index 5b1f8d3057f..902d03a579a 100644 --- a/scene/resources/animated_texture.cpp +++ b/scene/resources/animated_texture.cpp @@ -45,7 +45,7 @@ void AnimatedTexture::_update_proxy() { time += delta; - float speed = speed_scale == 0 ? 0 : abs(1.0 / speed_scale); + float speed = speed_scale == 0 ? 0 : std::abs(1.0 / speed_scale); int iter_max = frame_count; while (iter_max && !pause) { diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 2b415c923d9..5bb793abf85 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -2443,7 +2443,7 @@ int Animation::_find(const Vector &p_keys, double p_time, bool p_backward, bo if (p_limit) { double diff = length - keys[middle].time; - if ((signbit(keys[middle].time) && !Math::is_zero_approx(keys[middle].time)) || (signbit(diff) && !Math::is_zero_approx(diff))) { + if ((std::signbit(keys[middle].time) && !Math::is_zero_approx(keys[middle].time)) || (std::signbit(diff) && !Math::is_zero_approx(diff))) { ERR_PRINT_ONCE_ED("Found the key outside the animation range. Consider using the clean-up option in AnimationTrackEditor to fix it."); return -1; } @@ -4110,7 +4110,7 @@ bool Animation::_float_track_optimize_key(const TKey t0, const TKey t0, const TKey= 1.0 - p_allowed_velocity_err) { return true; @@ -4153,15 +4153,15 @@ bool Animation::_vector2_track_optimize_key(const TKey t0, const TKey= 1.0 - p_allowed_angular_error * 2.0) { - v0 = abs(v0); - v1 = abs(v1); + v0 = std::abs(v0); + v1 = std::abs(v1); double ratio = v0 < v1 ? v0 / v1 : v1 / v0; if (ratio >= 1.0 - p_allowed_velocity_err) { return true; @@ -4188,15 +4188,15 @@ bool Animation::_vector3_track_optimize_key(const TKey t0, const TKey= 1.0 - p_allowed_angular_error * 2.0) { - v0 = abs(v0); - v1 = abs(v1); + v0 = std::abs(v0); + v1 = std::abs(v1); double ratio = v0 < v1 ? v0 / v1 : v1 / v0; if (ratio >= 1.0 - p_allowed_velocity_err) { return true; @@ -4229,9 +4229,9 @@ bool Animation::_quaternion_track_optimize_key(const TKey t0, const double v0 = a0 / (t1.time - t0.time); double v1 = a1 / (t2.time - t1.time); // Avoid zero div but check equality. - if (abs(v0 - v1) < p_allowed_precision_error) { + if (std::abs(v0 - v1) < p_allowed_precision_error) { return true; - } else if (abs(v0) < p_allowed_precision_error || abs(v1) < p_allowed_precision_error) { + } else if (std::abs(v0) < p_allowed_precision_error || std::abs(v1) < p_allowed_precision_error) { return false; } double ratio = v0 < v1 ? v0 / v1 : v1 / v0; @@ -4357,7 +4357,7 @@ void Animation::_blend_shape_track_optimize(int p_idx, real_t p_allowed_velocity } if (bst->blend_shapes.size() == 2) { - if (abs(bst->blend_shapes[0].value - bst->blend_shapes[1].value) < p_allowed_precision_error) { + if (std::abs(bst->blend_shapes[0].value - bst->blend_shapes[1].value) < p_allowed_precision_error) { bst->blend_shapes.remove_at(1); } } @@ -4395,11 +4395,11 @@ void Animation::_value_track_optimize(int p_idx, real_t p_allowed_velocity_err, t1.value = vt->values[i + 1].value; t2.value = vt->values[i + 2].value; if (is_using_angle) { - float diff1 = fmod(t1.value - t0.value, Math::TAU); - t1.value = t0.value + fmod(2.0 * diff1, Math::TAU) - diff1; - float diff2 = fmod(t2.value - t1.value, Math::TAU); - t2.value = t1.value + fmod(2.0 * diff2, Math::TAU) - diff2; - if (abs(abs(diff1) + abs(diff2)) >= Math::PI) { + float diff1 = std::fmod(t1.value - t0.value, Math::TAU); + t1.value = t0.value + std::fmod(2.0 * diff1, Math::TAU) - diff1; + float diff2 = std::fmod(t2.value - t1.value, Math::TAU); + t2.value = t1.value + std::fmod(2.0 * diff2, Math::TAU) - diff2; + if (std::abs(std::abs(diff1) + std::abs(diff2)) >= Math::PI) { break; // Rotation is more than 180 deg, keep key. } } @@ -4459,10 +4459,10 @@ void Animation::_value_track_optimize(int p_idx, real_t p_allowed_velocity_err, float val_0 = vt->values[0].value; float val_1 = vt->values[1].value; if (is_using_angle) { - float diff1 = fmod(val_1 - val_0, Math::TAU); - val_1 = val_0 + fmod(2.0 * diff1, Math::TAU) - diff1; + float diff1 = std::fmod(val_1 - val_0, Math::TAU); + val_1 = val_0 + std::fmod(2.0 * diff1, Math::TAU) - diff1; } - single_key = abs(val_0 - val_1) < p_allowed_precision_error; + single_key = std::abs(val_0 - val_1) < p_allowed_precision_error; } break; case Variant::VECTOR2: { Vector2 val_0 = vt->values[0].value; diff --git a/scene/resources/bit_map.cpp b/scene/resources/bit_map.cpp index 29e4fcb5fe7..85f0839d5da 100644 --- a/scene/resources/bit_map.cpp +++ b/scene/resources/bit_map.cpp @@ -370,13 +370,13 @@ static float perpendicular_distance(const Vector2 &i, const Vector2 &start, cons float intercept; if (start.x == end.x) { - res = Math::absf(i.x - end.x); + res = Math::abs(i.x - end.x); } else if (start.y == end.y) { - res = Math::absf(i.y - end.y); + res = Math::abs(i.y - end.y); } else { slope = (end.y - start.y) / (end.x - start.x); intercept = start.y - (slope * start.x); - res = Math::absf(slope * i.x - i.y + intercept) / Math::sqrt(Math::pow(slope, 2.0f) + 1.0); + res = Math::abs(slope * i.x - i.y + intercept) / Math::sqrt(Math::pow(slope, 2.0f) + 1.0); } return res; } diff --git a/scene/resources/camera_attributes.cpp b/scene/resources/camera_attributes.cpp index 3a0c207a5da..e4b18f20ae7 100644 --- a/scene/resources/camera_attributes.cpp +++ b/scene/resources/camera_attributes.cpp @@ -378,7 +378,7 @@ void CameraAttributesPhysical::_update_frustum() { Vector2i sensor_size = Vector2i(36, 24); // Matches high-end DSLR, could be made variable if there is demand. float CoC = sensor_size.length() / 1500.0; - frustum_fov = Math::rad_to_deg(2 * atan(sensor_size.height / (2 * frustum_focal_length))); + frustum_fov = Math::rad_to_deg(2 * std::atan(sensor_size.height / (2 * frustum_focal_length))); // Based on https://en.wikipedia.org/wiki/Depth_of_field. float u = MAX(frustum_focus_distance * 1000.0, frustum_focal_length + 1.0); // Focus distance expressed in mm and clamped to at least 1 mm away from lens. @@ -439,8 +439,8 @@ void CameraAttributesPhysical::_update_auto_exposure() { RS::get_singleton()->camera_attributes_set_auto_exposure( get_rid(), auto_exposure_enabled, - pow(2.0, auto_exposure_min) * (12.5 / exposure_sensitivity), // Convert from EV100 to Luminance - pow(2.0, auto_exposure_max) * (12.5 / exposure_sensitivity), // Convert from EV100 to Luminance + std::pow(2.0, auto_exposure_min) * (12.5 / exposure_sensitivity), // Convert from EV100 to Luminance + std::pow(2.0, auto_exposure_max) * (12.5 / exposure_sensitivity), // Convert from EV100 to Luminance auto_exposure_speed, auto_exposure_scale); emit_changed(); diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index f0917d44691..a14e215b9ca 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -1792,7 +1792,7 @@ void Curve3D::_bake() const { { Vector3 forward = forward_ptr[0]; - if (abs(forward.dot(Vector3(0, 1, 0))) > 1.0 - UNIT_EPSILON) { + if (std::abs(forward.dot(Vector3(0, 1, 0))) > 1.0 - UNIT_EPSILON) { frame_prev = Basis::looking_at(forward, Vector3(1, 0, 0)); } else { frame_prev = Basis::looking_at(forward, Vector3(0, 1, 0)); @@ -1835,7 +1835,7 @@ void Curve3D::_bake() const { real_t sign = SIGN(up_end.cross(up_start).dot(forward_ptr[0])); real_t full_angle = Quaternion(up_end, up_start).get_angle(); - if (abs(full_angle) < CMP_EPSILON) { + if (std::abs(full_angle) < CMP_EPSILON) { return; } else { const real_t *dists = baked_dist_cache.ptr(); diff --git a/scene/resources/particle_process_material.cpp b/scene/resources/particle_process_material.cpp index 1e6210b17e7..d248ad4a678 100644 --- a/scene/resources/particle_process_material.cpp +++ b/scene/resources/particle_process_material.cpp @@ -1787,8 +1787,8 @@ void ParticleProcessMaterial::set_turbulence_noise_scale(float p_turbulence_nois const float noise_frequency_when_slider_is_zero = 4.0; const float max_slider_value = 10.0; const float curve_exponent = 0.25; - const float curve_rescale = noise_frequency_when_slider_is_zero / pow(max_slider_value, curve_exponent); - float shader_turbulence_noise_scale = pow(p_turbulence_noise_scale, curve_exponent) * curve_rescale - noise_frequency_when_slider_is_zero; + const float curve_rescale = noise_frequency_when_slider_is_zero / std::pow(max_slider_value, curve_exponent); + float shader_turbulence_noise_scale = std::pow(p_turbulence_noise_scale, curve_exponent) * curve_rescale - noise_frequency_when_slider_is_zero; RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->turbulence_noise_scale, shader_turbulence_noise_scale); } diff --git a/servers/audio/audio_filter_sw.cpp b/servers/audio/audio_filter_sw.cpp index 7827c74b923..22293558bff 100644 --- a/servers/audio/audio_filter_sw.cpp +++ b/servers/audio/audio_filter_sw.cpp @@ -108,9 +108,9 @@ void AudioFilterSW::prepare_coefficients(Coeffs *p_coeffs) { } break; case BANDPASS: { - p_coeffs->b0 = alpha * sqrt(Q + 1); + p_coeffs->b0 = alpha * std::sqrt(Q + 1); p_coeffs->b1 = 0.0; - p_coeffs->b2 = -alpha * sqrt(Q + 1); + p_coeffs->b2 = -alpha * std::sqrt(Q + 1); p_coeffs->a1 = -2.0 * cos_v; p_coeffs->a2 = 1.0 - alpha; } break; @@ -195,19 +195,19 @@ float AudioFilterSW::get_response(float p_freq, Coeffs *p_coeffs) { float cx = p_coeffs->b0, cy = 0.0; - cx += cos(freq) * p_coeffs->b1; - cy -= sin(freq) * p_coeffs->b1; - cx += cos(2 * freq) * p_coeffs->b2; - cy -= sin(2 * freq) * p_coeffs->b2; + cx += std::cos(freq) * p_coeffs->b1; + cy -= std::sin(freq) * p_coeffs->b1; + cx += std::cos(2 * freq) * p_coeffs->b2; + cy -= std::sin(2 * freq) * p_coeffs->b2; float H = cx * cx + cy * cy; cx = 1.0; cy = 0.0; - cx -= cos(freq) * p_coeffs->a1; - cy += sin(freq) * p_coeffs->a1; - cx -= cos(2 * freq) * p_coeffs->a2; - cy += sin(2 * freq) * p_coeffs->a2; + cx -= std::cos(freq) * p_coeffs->a1; + cy += std::sin(freq) * p_coeffs->a1; + cx -= std::cos(2 * freq) * p_coeffs->a2; + cy += std::sin(2 * freq) * p_coeffs->a2; H = H / (cx * cx + cy * cy); return H; diff --git a/servers/audio/effects/audio_effect_chorus.cpp b/servers/audio/effects/audio_effect_chorus.cpp index d490cefb88d..7f19dfab3e7 100644 --- a/servers/audio/effects/audio_effect_chorus.cpp +++ b/servers/audio/effects/audio_effect_chorus.cpp @@ -72,7 +72,7 @@ void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames, A float max_depth_frames = (v.depth / 1000.0) * mix_rate; uint64_t local_cycles = cycles[vc]; - uint64_t increment = llrint(cycles_to_mix / (double)p_frame_count * (double)(1 << AudioEffectChorus::CYCLES_FRAC)); + uint64_t increment = std::rint(cycles_to_mix / (double)p_frame_count * (double)(1 << AudioEffectChorus::CYCLES_FRAC)); //check the LFO doesn't read ahead of the write pos if ((((unsigned int)max_depth_frames) + 10) > delay_frames) { //10 as some threshold to avoid precision stuff @@ -84,7 +84,7 @@ void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames, A if (v.cutoff == 0) { continue; } - float auxlp = expf(-Math::TAU * v.cutoff / mix_rate); + float auxlp = std::exp(-Math::TAU * v.cutoff / mix_rate); float c1 = 1.0 - auxlp; float c2 = auxlp; AudioFrame h = filter_h[vc]; @@ -104,9 +104,9 @@ void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames, A float phase = (float)(local_cycles & AudioEffectChorus::CYCLES_MASK) / (float)(1 << AudioEffectChorus::CYCLES_FRAC); - float wave_delay = sinf(phase * Math::TAU) * max_depth_frames; + float wave_delay = std::sin(phase * Math::TAU) * max_depth_frames; - int wave_delay_frames = lrint(floor(wave_delay)); + int wave_delay_frames = std::rint(std::floor(wave_delay)); float wave_delay_frac = wave_delay - (float)wave_delay_frames; /** COMPUTE RINGBUFFER POS**/ diff --git a/servers/audio/effects/audio_effect_compressor.cpp b/servers/audio/effects/audio_effect_compressor.cpp index 1ab1b6eaf30..80035e6fff2 100644 --- a/servers/audio/effects/audio_effect_compressor.cpp +++ b/servers/audio/effects/audio_effect_compressor.cpp @@ -35,17 +35,17 @@ void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames, Audi float threshold = Math::db_to_linear(base->threshold); float sample_rate = AudioServer::get_singleton()->get_mix_rate(); - float ratatcoef = exp(-1 / (0.00001f * sample_rate)); - float ratrelcoef = exp(-1 / (0.5f * sample_rate)); + float ratatcoef = std::exp(-1 / (0.00001f * sample_rate)); + float ratrelcoef = std::exp(-1 / (0.5f * sample_rate)); float attime = base->attack_us / 1000000.0; float reltime = base->release_ms / 1000.0; - float atcoef = exp(-1 / (attime * sample_rate)); - float relcoef = exp(-1 / (reltime * sample_rate)); + float atcoef = std::exp(-1 / (attime * sample_rate)); + float relcoef = std::exp(-1 / (reltime * sample_rate)); float makeup = Math::db_to_linear(base->gain); float mix = base->mix; - float gr_meter_decay = exp(1 / (1 * sample_rate)); + float gr_meter_decay = std::exp(1 / (1 * sample_rate)); const AudioFrame *src = p_src_frames; diff --git a/servers/audio/effects/audio_effect_delay.cpp b/servers/audio/effects/audio_effect_delay.cpp index 487c90284be..6ab30b06828 100644 --- a/servers/audio/effects/audio_effect_delay.cpp +++ b/servers/audio/effects/audio_effect_delay.cpp @@ -73,7 +73,7 @@ void AudioEffectDelayInstance::_process_chunk(const AudioFrame *p_src_frames, Au tap2_vol.right *= CLAMP(1.0 + base->tap_2_pan, 0, 1); // feedback lowpass here - float lpf_c = expf(-Math::TAU * base->feedback_lowpass / mix_rate); // 0 .. 10khz + float lpf_c = std::exp(-Math::TAU * base->feedback_lowpass / mix_rate); // 0 .. 10khz float lpf_ic = 1.0 - lpf_c; const AudioFrame *src = p_src_frames; diff --git a/servers/audio/effects/audio_effect_distortion.cpp b/servers/audio/effects/audio_effect_distortion.cpp index 39364f8e60a..8a3e8bdadb4 100644 --- a/servers/audio/effects/audio_effect_distortion.cpp +++ b/servers/audio/effects/audio_effect_distortion.cpp @@ -36,18 +36,18 @@ void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames, Audi const float *src = (const float *)p_src_frames; float *dst = (float *)p_dst_frames; - //float lpf_c=expf(-Math::TAU*keep_hf_hz.get()/(mix_rate*(float)OVERSAMPLE)); - float lpf_c = expf(-Math::TAU * base->keep_hf_hz / (AudioServer::get_singleton()->get_mix_rate())); + //float lpf_c=std::exp(-Math::TAU*keep_hf_hz.get()/(mix_rate*(float)OVERSAMPLE)); + float lpf_c = std::exp(-Math::TAU * base->keep_hf_hz / (AudioServer::get_singleton()->get_mix_rate())); float lpf_ic = 1.0 - lpf_c; float drive_f = base->drive; float pregain_f = Math::db_to_linear(base->pre_gain); float postgain_f = Math::db_to_linear(base->post_gain); - float atan_mult = pow(10, drive_f * drive_f * 3.0) - 1.0 + 0.001; - float atan_div = 1.0 / (atanf(atan_mult) * (1.0 + drive_f * 8)); + float atan_mult = std::pow(10, drive_f * drive_f * 3.0) - 1.0 + 0.001; + float atan_div = 1.0 / (std::atan(atan_mult) * (1.0 + drive_f * 8)); - float lofi_mult = powf(2.0, 2.0 + (1.0 - drive_f) * 14); //goes from 16 to 2 bits + float lofi_mult = std::pow(2.0, 2.0 + (1.0 - drive_f) * 14); //goes from 16 to 2 bits for (int i = 0; i < p_frame_count * 2; i++) { float out = undenormalize(src[i] * lpf_ic + lpf_c * h[i & 1]); @@ -59,7 +59,7 @@ void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames, Audi switch (base->mode) { case AudioEffectDistortion::MODE_CLIP: { float a_sign = a < 0 ? -1.0f : 1.0f; - a = powf(abs(a), 1.0001 - drive_f) * a_sign; + a = std::pow(std::abs(a), 1.0001 - drive_f) * a_sign; if (a > 1.0) { a = 1.0; } else if (a < (-1.0)) { @@ -68,23 +68,23 @@ void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames, Audi } break; case AudioEffectDistortion::MODE_ATAN: { - a = atanf(a * atan_mult) * atan_div; + a = std::atan(a * atan_mult) * atan_div; } break; case AudioEffectDistortion::MODE_LOFI: { - a = floorf(a * lofi_mult + 0.5) / lofi_mult; + a = std::floor(a * lofi_mult + 0.5) / lofi_mult; } break; case AudioEffectDistortion::MODE_OVERDRIVE: { const double x = a * 0.686306; - const double z = 1 + exp(sqrt(fabs(x)) * -0.75); - a = (expf(x) - expf(-x * z)) / (expf(x) + expf(-x)); + const double z = 1 + std::exp(std::sqrt(std::abs(x)) * -0.75); + a = (std::exp(x) - std::exp(-x * z)) / (std::exp(x) + std::exp(-x)); } break; case AudioEffectDistortion::MODE_WAVESHAPE: { float x = a; float k = 2 * drive_f / (1.00001 - drive_f); - a = (1.0 + k) * x / (1.0 + k * fabsf(x)); + a = (1.0 + k) * x / (1.0 + k * std::abs(x)); } break; } diff --git a/servers/audio/effects/audio_effect_phaser.cpp b/servers/audio/effects/audio_effect_phaser.cpp index a6de12158bc..8edf1c774c6 100644 --- a/servers/audio/effects/audio_effect_phaser.cpp +++ b/servers/audio/effects/audio_effect_phaser.cpp @@ -46,7 +46,7 @@ void AudioEffectPhaserInstance::process(const AudioFrame *p_src_frames, AudioFra phase -= Math::TAU; } - float d = dmin + (dmax - dmin) * ((sin(phase) + 1.f) / 2.f); + float d = dmin + (dmax - dmin) * ((std::sin(phase) + 1.f) / 2.f); //update filter coeffs for (int j = 0; j < 6; j++) { diff --git a/servers/audio/effects/audio_effect_pitch_shift.cpp b/servers/audio/effects/audio_effect_pitch_shift.cpp index 3f8a459453a..9220be7a527 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.cpp +++ b/servers/audio/effects/audio_effect_pitch_shift.cpp @@ -112,7 +112,7 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff /* do windowing and re,im interleave */ for (k = 0; k < fftFrameSize;k++) { - window = -.5*cos(2.*Math::PI*(double)k/(double)fftFrameSize)+.5; + window = -.5*std::cos(2.*Math::PI*(double)k/(double)fftFrameSize)+.5; gFFTworksp[2*k] = gInFIFO[k] * window; gFFTworksp[2*k+1] = 0.; } @@ -129,8 +129,8 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff imag = gFFTworksp[2*k+1]; /* compute magnitude and phase */ - magn = 2.*sqrt(real*real + imag*imag); - phase = atan2(imag,real); + magn = 2.*std::sqrt(real*real + imag*imag); + phase = std::atan2(imag,real); /* compute phase difference */ tmp = phase - gLastPhase[k]; @@ -199,8 +199,8 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff phase = gSumPhase[k]; /* get real and imag part and re-interleave */ - gFFTworksp[2*k] = magn*cos(phase); - gFFTworksp[2*k+1] = magn*sin(phase); + gFFTworksp[2*k] = magn*std::cos(phase); + gFFTworksp[2*k+1] = magn*std::sin(phase); } /* zero negative frequencies */ @@ -212,7 +212,7 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff /* do windowing and add to output accumulator */ for(k=0; k < fftFrameSize; k++) { - window = -.5*cos(2.*Math::PI*(double)k/(double)fftFrameSize)+.5; + window = -.5*std::cos(2.*Math::PI*(double)k/(double)fftFrameSize)+.5; gOutputAccum[k] += 2.*window*gFFTworksp[2*k]/(fftFrameSize2*osamp); } for (k = 0; k < stepSize; k++) { gOutFIFO[k] = gOutputAccum[k]; @@ -260,14 +260,14 @@ void SMBPitchShift::smbFft(float *fftBuffer, long fftFrameSize, long sign) *p1 = *p2; *p2 = temp; } } - for (k = 0, le = 2; k < (long)(log((double)fftFrameSize)/log(2.)+.5); k++) { + for (k = 0, le = 2; k < (long)(std::log((double)fftFrameSize)/std::log(2.)+.5); k++) { le <<= 1; le2 = le>>1; ur = 1.0; ui = 0.0; arg = Math::PI / (le2>>1); - wr = cos(arg); - wi = sign*sin(arg); + wr = std::cos(arg); + wi = sign*std::sin(arg); for (j = 0; j < le2; j += 2) { p1r = fftBuffer+j; p1i = p1r+1; p2r = p1r+le2; p2i = p2r+1; diff --git a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp index 9ba58b0fbc2..208a7b8e759 100644 --- a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp +++ b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp @@ -66,14 +66,14 @@ static void smbFft(float *fftBuffer, long fftFrameSize, long sign) *p2 = temp; } } - for (k = 0, le = 2; k < (long)(log((double)fftFrameSize) / log(2.) + .5); k++) { + for (k = 0, le = 2; k < (long)(std::log((double)fftFrameSize) / std::log(2.) + .5); k++) { le <<= 1; le2 = le >> 1; ur = 1.0; ui = 0.0; arg = Math::PI / (le2 >> 1); - wr = cos(arg); - wi = sign * sin(arg); + wr = std::cos(arg); + wi = sign * std::sin(arg); for (j = 0; j < le2; j += 2) { p1r = fftBuffer + j; p1i = p1r + 1; diff --git a/servers/audio/effects/eq_filter.cpp b/servers/audio/effects/eq_filter.cpp index 9b774833cce..3cf2674e275 100644 --- a/servers/audio/effects/eq_filter.cpp +++ b/servers/audio/effects/eq_filter.cpp @@ -31,9 +31,7 @@ #include "eq_filter.h" #include "core/error/error_macros.h" -#include "core/math/math_defs.h" - -#include +#include "core/math/math_funcs.h" #define POW2(v) ((v) * (v)) @@ -51,7 +49,7 @@ static int solve_quadratic(double a, double b, double c, double *r1, double *r2) return 0; } - squared = sqrt(squared); + squared = std::sqrt(squared); *r1 = (-b + squared) / base; *r2 = (-b - squared) / base; @@ -69,7 +67,7 @@ EQ::BandProcess::BandProcess() { } void EQ::recalculate_band_coefficients() { -#define BAND_LOG(m_f) (log((m_f)) / log(2.)) +#define BAND_LOG(m_f) (std::log((m_f)) / std::log(2.)) for (int i = 0; i < band.size(); i++) { double octave_size; @@ -86,17 +84,17 @@ void EQ::recalculate_band_coefficients() { octave_size = (next + prev) / 2.0; } - double frq_l = round(frq / pow(2.0, octave_size / 2.0)); + double frq_l = std::round(frq / std::pow(2.0, octave_size / 2.0)); double side_gain2 = POW2(Math::SQRT12); double th = Math::TAU * frq / mix_rate; double th_l = Math::TAU * frq_l / mix_rate; - double c2a = side_gain2 * POW2(cos(th)) - 2.0 * side_gain2 * cos(th_l) * cos(th) + side_gain2 - POW2(sin(th_l)); + double c2a = side_gain2 * POW2(std::cos(th)) - 2.0 * side_gain2 * std::cos(th_l) * std::cos(th) + side_gain2 - POW2(std::sin(th_l)); - double c2b = 2.0 * side_gain2 * POW2(cos(th_l)) + side_gain2 * POW2(cos(th)) - 2.0 * side_gain2 * cos(th_l) * cos(th) - side_gain2 + POW2(sin(th_l)); + double c2b = 2.0 * side_gain2 * POW2(std::cos(th_l)) + side_gain2 * POW2(std::cos(th)) - 2.0 * side_gain2 * std::cos(th_l) * std::cos(th) - side_gain2 + POW2(std::sin(th_l)); - double c2c = 0.25 * side_gain2 * POW2(cos(th)) - 0.5 * side_gain2 * cos(th_l) * cos(th) + 0.25 * side_gain2 - 0.25 * POW2(sin(th_l)); + double c2c = 0.25 * side_gain2 * POW2(std::cos(th)) - 0.5 * side_gain2 * std::cos(th_l) * std::cos(th) + 0.25 * side_gain2 - 0.25 * POW2(std::sin(th_l)); //printf("band %i, precoefs = %f,%f,%f\n",i,c2a,c2b,c2c); @@ -109,7 +107,7 @@ void EQ::recalculate_band_coefficients() { band.write[i].c1 = 2.0 * ((0.5 - r1) / 2.0); band.write[i].c2 = 2.0 * r1; - band.write[i].c3 = 2.0 * (0.5 + r1) * cos(th); + band.write[i].c3 = 2.0 * (0.5 + r1) * std::cos(th); //printf("band %i, coefs = %f,%f,%f\n",i,(float)bands[i].c1,(float)bands[i].c2,(float)bands[i].c3); } } diff --git a/servers/audio/effects/reverb_filter.cpp b/servers/audio/effects/reverb_filter.cpp index eba6c924b4c..90a350b347f 100644 --- a/servers/audio/effects/reverb_filter.cpp +++ b/servers/audio/effects/reverb_filter.cpp @@ -33,8 +33,6 @@ #include "core/math/audio_frame.h" #include "core/os/memory.h" -#include - const float Reverb::comb_tunings[MAX_COMBS] = { //freeverb comb tunings 0.025306122448979593f, @@ -60,7 +58,7 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) { p_frames = INPUT_BUFFER_MAX_SIZE; } - int predelay_frames = lrint((params.predelay / 1000.0) * params.mix_rate); + int predelay_frames = std::rint((params.predelay / 1000.0) * params.mix_rate); if (predelay_frames < 10) { predelay_frames = 10; } @@ -90,7 +88,7 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) { } if (params.hpf > 0) { - float hpaux = expf(-Math::TAU * params.hpf * 6000 / params.mix_rate); + float hpaux = std::exp(-Math::TAU * params.hpf * 6000 / params.mix_rate); float hp_a1 = (1.0 + hpaux) / 2.0; float hp_a2 = -(1.0 + hpaux) / 2.0; float hp_b1 = hpaux; @@ -106,7 +104,7 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) { for (int i = 0; i < MAX_COMBS; i++) { Comb &c = comb[i]; - int size_limit = c.size - lrintf((float)c.extra_spread_frames * (1.0 - params.extra_spread)); + int size_limit = c.size - std::rint((float)c.extra_spread_frames * (1.0 - params.extra_spread)); for (int j = 0; j < p_frames; j++) { if (c.pos >= size_limit) { //reset this now just in case c.pos = 0; @@ -127,7 +125,7 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) { for (int i=0;i= size_limit) { @@ -233,9 +231,9 @@ void Reverb::configure_buffers() { for (int i = 0; i < MAX_COMBS; i++) { Comb &c = comb[i]; - c.extra_spread_frames = lrint(params.extra_spread_base * params.mix_rate); + c.extra_spread_frames = std::rint(params.extra_spread_base * params.mix_rate); - int len = lrint(comb_tunings[i] * params.mix_rate) + c.extra_spread_frames; + int len = std::rint(comb_tunings[i] * params.mix_rate) + c.extra_spread_frames; if (len < 5) { len = 5; //may this happen? } @@ -251,9 +249,9 @@ void Reverb::configure_buffers() { for (int i = 0; i < MAX_ALLPASS; i++) { AllPass &a = allpass[i]; - a.extra_spread_frames = lrint(params.extra_spread_base * params.mix_rate); + a.extra_spread_frames = std::rint(params.extra_spread_base * params.mix_rate); - int len = lrint(allpass_tunings[i] * params.mix_rate) + a.extra_spread_frames; + int len = std::rint(allpass_tunings[i] * params.mix_rate) + a.extra_spread_frames; if (len < 5) { len = 5; //may this happen? } @@ -292,7 +290,7 @@ void Reverb::update_parameters() { float auxdmp = params.damp / 2.0 + 0.5; //only half the range (0.5 .. 1.0 is enough) auxdmp *= auxdmp; - c.damp = expf(-Math::TAU * auxdmp * 10000 / params.mix_rate); // 0 .. 10khz + c.damp = std::exp(-Math::TAU * auxdmp * 10000 / params.mix_rate); // 0 .. 10khz } } diff --git a/servers/display_server.h b/servers/display_server.h index e40be3ff4ce..a6a4d4eb85e 100644 --- a/servers/display_server.h +++ b/servers/display_server.h @@ -360,7 +360,7 @@ public: float scale = 1.f; int screen_count = get_screen_count(); for (int i = 0; i < screen_count; i++) { - scale = fmax(scale, screen_get_scale(i)); + scale = std::fmax(scale, screen_get_scale(i)); } return scale; } diff --git a/servers/rendering/renderer_canvas_cull.cpp b/servers/rendering/renderer_canvas_cull.cpp index b7285e9d8e0..ea904dd357d 100644 --- a/servers/rendering/renderer_canvas_cull.cpp +++ b/servers/rendering/renderer_canvas_cull.cpp @@ -925,8 +925,8 @@ static Vector2 compute_polyline_edge_offset_clamped(const Vector2 &p_segment_dir bisector = (p_prev_segment_dir * p_segment_dir.length() - p_segment_dir * p_prev_segment_dir.length()).normalized(); - float angle = atan2f(bisector.cross(p_prev_segment_dir), bisector.dot(p_prev_segment_dir)); - float sin_angle = sinf(angle); + float angle = std::atan2(bisector.cross(p_prev_segment_dir), bisector.dot(p_prev_segment_dir)); + float sin_angle = std::sin(angle); if (!Math::is_zero_approx(sin_angle) && !p_segment_dir.is_equal_approx(p_prev_segment_dir)) { length = 1.0f / sin_angle; diff --git a/servers/rendering/renderer_rd/effects/fsr2.cpp b/servers/rendering/renderer_rd/effects/fsr2.cpp index f5f48772bda..9e3cbfdc45e 100644 --- a/servers/rendering/renderer_rd/effects/fsr2.cpp +++ b/servers/rendering/renderer_rd/effects/fsr2.cpp @@ -216,7 +216,7 @@ static FfxErrorCode create_resource_rd(FfxFsr2Interface *p_backend_interface, co if (res_desc.mipCount == 0) { // Mipmap count must be derived from the resource's dimensions. - res_desc.mipCount = uint32_t(1 + floor(log2(MAX(MAX(res_desc.width, res_desc.height), res_desc.depth)))); + res_desc.mipCount = uint32_t(1 + std::floor(std::log2(MAX(MAX(res_desc.width, res_desc.height), res_desc.depth)))); } Vector initial_data; diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp index 3d5e8630a94..5ab4ce570d4 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp @@ -1058,7 +1058,7 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color base_specialization.disable_fog = false; base_specialization.use_fog_aerial_perspective = environment_get_fog_aerial_perspective(p_render_data->environment) > 0.0; base_specialization.use_fog_sun_scatter = environment_get_fog_sun_scatter(p_render_data->environment) > 0.001; - base_specialization.use_fog_height_density = abs(environment_get_fog_height_density(p_render_data->environment)) >= 0.0001; + base_specialization.use_fog_height_density = std::abs(environment_get_fog_height_density(p_render_data->environment)) >= 0.0001; base_specialization.use_depth_fog = p_render_data->environment.is_valid() && environment_get_fog_mode(p_render_data->environment) == RS::EnvironmentFogMode::ENV_FOG_MODE_DEPTH; } diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index b00916c0297..af250893377 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -247,7 +247,7 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { if (scaling_type == RS::VIEWPORT_SCALING_3D_TYPE_TEMPORAL) { // Implementation has been copied from ffxFsr2GetJitterPhaseCount. // Also used for MetalFX Temporal scaling. - jitter_phase_count = uint32_t(8.0f * pow(float(target_width) / render_width, 2.0f)); + jitter_phase_count = uint32_t(8.0f * std::pow(float(target_width) / render_width, 2.0f)); } else if (use_taa) { // Default jitter count for TAA. jitter_phase_count = 16; @@ -258,7 +258,7 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) { // At resolution scales lower than 1.0, use negative texture mipmap bias // to compensate for the loss of sharpness. - const float texture_mipmap_bias = log2f(MIN(scaling_3d_scale, 1.0)) + p_viewport->texture_mipmap_bias; + const float texture_mipmap_bias = std::log2(MIN(scaling_3d_scale, 1.0)) + p_viewport->texture_mipmap_bias; RenderSceneBuffersConfiguration rb_config; rb_config.set_render_target(p_viewport->render_target); diff --git a/tests/core/io/test_json.h b/tests/core/io/test_json.h index 155f3787f79..15137d5ca7e 100644 --- a/tests/core/io/test_json.h +++ b/tests/core/io/test_json.h @@ -248,8 +248,8 @@ TEST_CASE("[JSON] Serialization") { { -1000.1234567890123456789, "-1000.12345678901" }, { DBL_MAX, "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0" }, { DBL_MAX - 1, "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0" }, - { pow(2, 53), "9007199254740992.0" }, - { -pow(2, 53), "-9007199254740992.0" }, + { std::pow(2, 53), "9007199254740992.0" }, + { -std::pow(2, 53), "-9007199254740992.0" }, { 0.00000000000000011, "0.00000000000000011" }, { -0.00000000000000011, "-0.00000000000000011" }, { 1.0 / 3.0, "0.333333333333333" }, @@ -263,8 +263,8 @@ TEST_CASE("[JSON] Serialization") { { -1000.1234567890123456789, "-1000.12345678901238" }, { DBL_MAX, "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0" }, { DBL_MAX - 1, "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0" }, - { pow(2, 53), "9007199254740992.0" }, - { -pow(2, 53), "-9007199254740992.0" }, + { std::pow(2, 53), "9007199254740992.0" }, + { -std::pow(2, 53), "-9007199254740992.0" }, { 0.00000000000000011, "0.00000000000000011" }, { -0.00000000000000011, "-0.00000000000000011" }, { 1.0 / 3.0, "0.333333333333333315" }, diff --git a/tests/core/math/test_random_number_generator.h b/tests/core/math/test_random_number_generator.h index 948fb1d7a54..57360a27105 100644 --- a/tests/core/math/test_random_number_generator.h +++ b/tests/core/math/test_random_number_generator.h @@ -258,7 +258,7 @@ TEST_CASE_MAY_FAIL("[RandomNumberGenerator] randi_range bias check") { int val = rng->randi_range(0, 1); val == 0 ? zeros++ : ones++; } - CHECK_MESSAGE(abs(zeros * 1.0 / ones - 1.0) < 0.1, "The ratio of zeros to ones should be nearly 1"); + CHECK_MESSAGE(std::abs(zeros * 1.0 / ones - 1.0) < 0.1, "The ratio of zeros to ones should be nearly 1"); int vals[10] = { 0 }; for (int i = 0; i < 1000000; i++) { @@ -266,7 +266,7 @@ TEST_CASE_MAY_FAIL("[RandomNumberGenerator] randi_range bias check") { } for (int i = 0; i < 10; i++) { - CHECK_MESSAGE(abs(vals[i] / 1000000.0 - 0.1) < 0.01, "Each element should appear roughly 10% of the time"); + CHECK_MESSAGE(std::abs(vals[i] / 1000000.0 - 0.1) < 0.01, "Each element should appear roughly 10% of the time"); } } } // namespace TestRandomNumberGenerator