From cfa2d42ea488088a2010519c4434b3a608064973 Mon Sep 17 00:00:00 2001 From: Thaddeus Crews Date: Wed, 19 Mar 2025 14:18:09 -0500 Subject: [PATCH] Core: Replace C math headers with C++ equivalents - Minor restructuring to ensure `math_funcs.h` is the central point for math functions --- core/io/image.cpp | 6 +- core/io/json.cpp | 2 +- core/io/plist.cpp | 14 +- core/io/resource.cpp | 1 + core/math/basis.cpp | 20 +- core/math/math_funcs.cpp | 3 +- core/math/math_funcs.h | 216 ++++++------------ core/math/projection.cpp | 2 +- core/math/quaternion.cpp | 14 +- core/math/quaternion.h | 2 +- core/math/random_pcg.h | 22 +- core/string/ustring.cpp | 10 +- core/variant/variant_call.cpp | 8 +- core/variant/variant_parser.cpp | 4 +- core/variant/variant_utility.cpp | 4 +- drivers/gles3/effects/cubemap_filter.cpp | 10 +- editor/animation_bezier_editor.cpp | 6 +- editor/animation_track_editor.cpp | 8 +- editor/code_editor.cpp | 2 +- editor/editor_properties.cpp | 2 +- editor/export/editor_export_platform.cpp | 1 + editor/gui/editor_spin_slider.cpp | 2 +- editor/import/3d/editor_import_collada.cpp | 2 +- ...post_import_plugin_skeleton_rest_fixer.cpp | 4 +- editor/import/3d/resource_importer_obj.cpp | 2 +- editor/plugins/canvas_item_editor_plugin.cpp | 26 +-- .../editor_resource_tooltip_plugins.cpp | 2 +- .../navigation_region_3d_gizmo_plugin.cpp | 1 + editor/plugins/particles_editor_plugin.cpp | 2 +- editor/plugins/path_3d_editor_plugin.cpp | 2 +- editor/plugins/tiles/tile_data_editors.cpp | 1 + .../plugins/tiles/tile_map_layer_editor.cpp | 1 + main/main_timer_sync.cpp | 8 +- modules/gltf/gltf_document.cpp | 2 +- modules/godot_physics_2d/godot_body_2d.cpp | 2 +- modules/godot_physics_3d/godot_shape_3d.cpp | 2 +- .../godot_physics_3d/godot_soft_body_3d.cpp | 2 +- modules/hdr/image_loader_hdr.cpp | 2 +- .../jolt_physics_direct_space_state_3d.cpp | 2 +- modules/mobile_vr/mobile_vr_interface.cpp | 2 +- modules/mobile_vr/mobile_vr_interface.h | 4 +- modules/noise/noise.cpp | 2 - .../openxr_hand_tracking_extension.cpp | 2 +- modules/openxr/openxr_util.cpp | 12 +- modules/svg/image_loader_svg.cpp | 4 +- modules/text_server_adv/thorvg_svg_in_ot.cpp | 1 - modules/text_server_fb/thorvg_svg_in_ot.cpp | 1 - modules/webxr/webxr_interface_js.cpp | 2 +- platform/linuxbsd/joypad_linux.cpp | 6 +- platform/linuxbsd/tts_linux.cpp | 4 +- platform/linuxbsd/wayland/wayland_thread.cpp | 12 +- platform/linuxbsd/x11/display_server_x11.cpp | 2 +- platform/macos/display_server_macos.mm | 8 +- platform/macos/godot_content_view.mm | 8 +- platform/windows/display_server_windows.cpp | 20 +- platform/windows/native_menu_windows.cpp | 2 +- platform/windows/tts_windows.cpp | 2 +- scene/2d/animated_sprite_2d.cpp | 8 +- scene/2d/gpu_particles_2d.cpp | 2 +- scene/2d/line_builder.cpp | 2 +- scene/2d/navigation_region_2d.cpp | 1 + scene/2d/parallax_layer.cpp | 4 +- scene/2d/path_2d.cpp | 2 +- scene/2d/tile_map_layer.cpp | 1 + scene/3d/audio_stream_player_3d.cpp | 4 +- scene/3d/look_at_modifier_3d.cpp | 10 +- scene/3d/mesh_instance_3d.cpp | 2 +- scene/3d/navigation_obstacle_3d.cpp | 8 +- scene/3d/navigation_region_3d.cpp | 1 + scene/3d/path_3d.cpp | 2 +- scene/3d/physics/ray_cast_3d.cpp | 2 +- scene/3d/spring_bone_simulator_3d.cpp | 2 +- scene/3d/sprite_3d.cpp | 8 +- scene/animation/animation_blend_space_1d.cpp | 2 +- scene/animation/animation_mixer.cpp | 4 +- scene/animation/animation_player.cpp | 10 +- scene/animation/easing_equations.h | 60 ++--- scene/gui/code_edit.cpp | 2 +- scene/gui/control.cpp | 8 +- scene/gui/graph_edit.cpp | 4 +- scene/gui/grid_container.cpp | 2 +- scene/gui/line_edit.cpp | 6 +- scene/gui/progress_bar.cpp | 8 +- scene/gui/range.cpp | 2 +- scene/gui/rich_text_label.cpp | 10 +- scene/gui/scroll_bar.cpp | 2 +- scene/gui/text_edit.cpp | 26 +-- .../skeleton_modification_2d_twoboneik.cpp | 6 +- scene/resources/animated_texture.cpp | 2 +- scene/resources/animation.cpp | 52 ++--- scene/resources/bit_map.cpp | 6 +- scene/resources/camera_attributes.cpp | 6 +- scene/resources/curve.cpp | 4 +- scene/resources/particle_process_material.cpp | 4 +- servers/audio/audio_filter_sw.cpp | 20 +- servers/audio/effects/audio_effect_chorus.cpp | 8 +- .../audio/effects/audio_effect_compressor.cpp | 10 +- servers/audio/effects/audio_effect_delay.cpp | 2 +- .../audio/effects/audio_effect_distortion.cpp | 20 +- servers/audio/effects/audio_effect_phaser.cpp | 2 +- .../effects/audio_effect_pitch_shift.cpp | 18 +- .../audio_effect_spectrum_analyzer.cpp | 6 +- servers/audio/effects/eq_filter.cpp | 18 +- servers/audio/effects/reverb_filter.cpp | 22 +- servers/display_server.h | 2 +- servers/rendering/renderer_canvas_cull.cpp | 4 +- .../rendering/renderer_rd/effects/fsr2.cpp | 2 +- .../forward_mobile/render_forward_mobile.cpp | 2 +- servers/rendering/renderer_viewport.cpp | 4 +- tests/core/io/test_json.h | 8 +- .../core/math/test_random_number_generator.h | 4 +- 111 files changed, 430 insertions(+), 523 deletions(-) diff --git a/core/io/image.cpp b/core/io/image.cpp index 515062587257..ec0c45cc656f 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -39,8 +39,6 @@ #include "core/templates/hash_map.h" #include "core/variant/dictionary.h" -#include - const char *Image::format_names[Image::FORMAT_MAX] = { "Lum8", "LumAlpha8", @@ -4383,12 +4381,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 41ec634ba08c..00b778de31a9 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 5a70a8332d23..2d8c26bf10d6 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/io/resource.cpp b/core/io/resource.cpp index 71a61fed2215..09d1c15c1f7d 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -32,6 +32,7 @@ #include "core/io/resource_loader.h" #include "core/math/math_funcs.h" +#include "core/math/random_pcg.h" #include "core/os/os.h" #include "scene/main/node.h" //only so casting works diff --git a/core/math/basis.cpp b/core/math/basis.cpp index 71ceb8a409c2..c18cee6d0b40 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -262,16 +262,16 @@ 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; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - dots[j] += s[i] * abs(m.get_column(i).normalized().dot(b.get_column(j))); + dots[j] += s[i] * std::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.cpp b/core/math/math_funcs.cpp index 0d5b0faa9d18..d2a22bd22c55 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -31,8 +31,9 @@ #include "math_funcs.h" #include "core/error/error_macros.h" +#include "core/math/random_pcg.h" -RandomPCG Math::default_rand(RandomPCG::DEFAULT_SEED, RandomPCG::DEFAULT_INC); +static RandomPCG default_rand; uint32_t Math::rand_from_seed(uint64_t *seed) { RandomPCG rng = RandomPCG(*seed, RandomPCG::DEFAULT_INC); diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 47e5b7c65b77..d79d5203d725 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -32,173 +32,99 @@ #include "core/error/error_macros.h" #include "core/math/math_defs.h" -#include "core/math/random_pcg.h" #include "core/typedefs.h" -#include "thirdparty/misc/pcg.h" - -#include -#include +#include +#include class Math { - static RandomPCG default_rand; - public: - Math() {} // useless to instance + Math() = delete; // useless to instance - // Not using 'RANDOM_MAX' to avoid conflict with system headers on some OSes (at least NetBSD). - static const uint64_t RANDOM_32BIT_MAX = 0xFFFFFFFF; + static _ALWAYS_INLINE_ double sin(double p_x) { return std::sin(p_x); } + static _ALWAYS_INLINE_ float sin(float p_x) { return std::sin(p_x); } - static _ALWAYS_INLINE_ double sin(double p_x) { return ::sin(p_x); } - static _ALWAYS_INLINE_ float sin(float p_x) { return ::sinf(p_x); } + static _ALWAYS_INLINE_ double cos(double p_x) { return std::cos(p_x); } + static _ALWAYS_INLINE_ float cos(float p_x) { return std::cos(p_x); } - static _ALWAYS_INLINE_ double cos(double p_x) { return ::cos(p_x); } - static _ALWAYS_INLINE_ float cos(float p_x) { return ::cosf(p_x); } + static _ALWAYS_INLINE_ double tan(double p_x) { return std::tan(p_x); } + static _ALWAYS_INLINE_ float tan(float p_x) { return std::tan(p_x); } - static _ALWAYS_INLINE_ double tan(double p_x) { return ::tan(p_x); } - static _ALWAYS_INLINE_ float tan(float p_x) { return ::tanf(p_x); } + static _ALWAYS_INLINE_ double sinh(double p_x) { return std::sinh(p_x); } + static _ALWAYS_INLINE_ float sinh(float p_x) { return std::sinh(p_x); } - static _ALWAYS_INLINE_ double sinh(double p_x) { return ::sinh(p_x); } - static _ALWAYS_INLINE_ float sinh(float p_x) { return ::sinhf(p_x); } - - static _ALWAYS_INLINE_ float sinc(float p_x) { return p_x == 0 ? 1 : ::sin(p_x) / p_x; } - static _ALWAYS_INLINE_ double sinc(double p_x) { return p_x == 0 ? 1 : ::sin(p_x) / p_x; } + static _ALWAYS_INLINE_ float sinc(float p_x) { return p_x == 0 ? 1 : std::sin(p_x) / p_x; } + static _ALWAYS_INLINE_ double sinc(double p_x) { return p_x == 0 ? 1 : std::sin(p_x) / p_x; } static _ALWAYS_INLINE_ float sincn(float p_x) { return sinc((float)Math_PI * p_x); } static _ALWAYS_INLINE_ double sincn(double p_x) { return sinc(Math_PI * p_x); } - static _ALWAYS_INLINE_ double cosh(double p_x) { return ::cosh(p_x); } - static _ALWAYS_INLINE_ float cosh(float p_x) { return ::coshf(p_x); } + static _ALWAYS_INLINE_ double cosh(double p_x) { return std::cosh(p_x); } + static _ALWAYS_INLINE_ float cosh(float p_x) { return std::cosh(p_x); } - static _ALWAYS_INLINE_ double tanh(double p_x) { return ::tanh(p_x); } - static _ALWAYS_INLINE_ float tanh(float p_x) { return ::tanhf(p_x); } + static _ALWAYS_INLINE_ double tanh(double p_x) { return std::tanh(p_x); } + static _ALWAYS_INLINE_ float tanh(float p_x) { return std::tanh(p_x); } // Always does clamping so always safe to use. - static _ALWAYS_INLINE_ double asin(double p_x) { return p_x < -1 ? (-Math_PI / 2) : (p_x > 1 ? (Math_PI / 2) : ::asin(p_x)); } - static _ALWAYS_INLINE_ float asin(float p_x) { return p_x < -1 ? (-Math_PI / 2) : (p_x > 1 ? (Math_PI / 2) : ::asinf(p_x)); } + static _ALWAYS_INLINE_ double asin(double p_x) { return p_x < -1 ? (-Math_PI / 2) : (p_x > 1 ? (Math_PI / 2) : std::asin(p_x)); } + static _ALWAYS_INLINE_ float asin(float p_x) { return p_x < -1 ? (-Math_PI / 2) : (p_x > 1 ? (Math_PI / 2) : std::asin(p_x)); } // Always does clamping so always safe to use. - static _ALWAYS_INLINE_ double acos(double p_x) { return p_x < -1 ? Math_PI : (p_x > 1 ? 0 : ::acos(p_x)); } - static _ALWAYS_INLINE_ float acos(float p_x) { return p_x < -1 ? Math_PI : (p_x > 1 ? 0 : ::acosf(p_x)); } + static _ALWAYS_INLINE_ double acos(double p_x) { return p_x < -1 ? Math_PI : (p_x > 1 ? 0 : std::acos(p_x)); } + static _ALWAYS_INLINE_ float acos(float p_x) { return p_x < -1 ? Math_PI : (p_x > 1 ? 0 : std::acos(p_x)); } - static _ALWAYS_INLINE_ double atan(double p_x) { return ::atan(p_x); } - static _ALWAYS_INLINE_ float atan(float p_x) { return ::atanf(p_x); } + static _ALWAYS_INLINE_ double atan(double p_x) { return std::atan(p_x); } + static _ALWAYS_INLINE_ float atan(float p_x) { return std::atan(p_x); } - static _ALWAYS_INLINE_ double atan2(double p_y, double p_x) { return ::atan2(p_y, p_x); } - static _ALWAYS_INLINE_ float atan2(float p_y, float p_x) { return ::atan2f(p_y, p_x); } + static _ALWAYS_INLINE_ double atan2(double p_y, double p_x) { return std::atan2(p_y, p_x); } + static _ALWAYS_INLINE_ float atan2(float p_y, float p_x) { return std::atan2(p_y, p_x); } - static _ALWAYS_INLINE_ double asinh(double p_x) { return ::asinh(p_x); } - static _ALWAYS_INLINE_ float asinh(float p_x) { return ::asinhf(p_x); } + static _ALWAYS_INLINE_ double asinh(double p_x) { return std::asinh(p_x); } + static _ALWAYS_INLINE_ float asinh(float p_x) { return std::asinh(p_x); } // Always does clamping so always safe to use. - static _ALWAYS_INLINE_ double acosh(double p_x) { return p_x < 1 ? 0 : ::acosh(p_x); } - static _ALWAYS_INLINE_ float acosh(float p_x) { return p_x < 1 ? 0 : ::acoshf(p_x); } + static _ALWAYS_INLINE_ double acosh(double p_x) { return p_x < 1 ? 0 : std::acosh(p_x); } + static _ALWAYS_INLINE_ float acosh(float p_x) { return p_x < 1 ? 0 : std::acosh(p_x); } // Always does clamping so always safe to use. - static _ALWAYS_INLINE_ double atanh(double p_x) { return p_x <= -1 ? -INFINITY : (p_x >= 1 ? INFINITY : ::atanh(p_x)); } - static _ALWAYS_INLINE_ float atanh(float p_x) { return p_x <= -1 ? -INFINITY : (p_x >= 1 ? INFINITY : ::atanhf(p_x)); } + static _ALWAYS_INLINE_ double atanh(double p_x) { return p_x <= -1 ? -INFINITY : (p_x >= 1 ? INFINITY : std::atanh(p_x)); } + static _ALWAYS_INLINE_ float atanh(float p_x) { return p_x <= -1 ? -INFINITY : (p_x >= 1 ? INFINITY : std::atanh(p_x)); } - static _ALWAYS_INLINE_ double sqrt(double p_x) { return ::sqrt(p_x); } - static _ALWAYS_INLINE_ float sqrt(float p_x) { return ::sqrtf(p_x); } + static _ALWAYS_INLINE_ double sqrt(double p_x) { return std::sqrt(p_x); } + static _ALWAYS_INLINE_ float sqrt(float p_x) { return std::sqrt(p_x); } - static _ALWAYS_INLINE_ double fmod(double p_x, double p_y) { return ::fmod(p_x, p_y); } - static _ALWAYS_INLINE_ float fmod(float p_x, float p_y) { return ::fmodf(p_x, p_y); } + static _ALWAYS_INLINE_ double fmod(double p_x, double p_y) { return std::fmod(p_x, p_y); } + static _ALWAYS_INLINE_ float fmod(float p_x, float p_y) { return std::fmod(p_x, p_y); } - static _ALWAYS_INLINE_ double modf(double p_x, double *r_y) { return ::modf(p_x, r_y); } - static _ALWAYS_INLINE_ float modf(float p_x, float *r_y) { return ::modff(p_x, r_y); } + static _ALWAYS_INLINE_ double modf(double p_x, double *r_y) { return std::modf(p_x, r_y); } + static _ALWAYS_INLINE_ float modf(float p_x, float *r_y) { return std::modf(p_x, r_y); } - static _ALWAYS_INLINE_ double floor(double p_x) { return ::floor(p_x); } - static _ALWAYS_INLINE_ float floor(float p_x) { return ::floorf(p_x); } + static _ALWAYS_INLINE_ double floor(double p_x) { return std::floor(p_x); } + static _ALWAYS_INLINE_ float floor(float p_x) { return std::floor(p_x); } - static _ALWAYS_INLINE_ double ceil(double p_x) { return ::ceil(p_x); } - static _ALWAYS_INLINE_ float ceil(float p_x) { return ::ceilf(p_x); } + static _ALWAYS_INLINE_ double ceil(double p_x) { return std::ceil(p_x); } + static _ALWAYS_INLINE_ float ceil(float p_x) { return std::ceil(p_x); } - static _ALWAYS_INLINE_ double pow(double p_x, double p_y) { return ::pow(p_x, p_y); } - static _ALWAYS_INLINE_ float pow(float p_x, float p_y) { return ::powf(p_x, p_y); } + static _ALWAYS_INLINE_ double pow(double p_x, double p_y) { return std::pow(p_x, p_y); } + static _ALWAYS_INLINE_ float pow(float p_x, float p_y) { return std::pow(p_x, p_y); } - static _ALWAYS_INLINE_ double log(double p_x) { return ::log(p_x); } - static _ALWAYS_INLINE_ float log(float p_x) { return ::logf(p_x); } + static _ALWAYS_INLINE_ double log(double p_x) { return std::log(p_x); } + static _ALWAYS_INLINE_ float log(float p_x) { return std::log(p_x); } - static _ALWAYS_INLINE_ double log1p(double p_x) { return ::log1p(p_x); } - static _ALWAYS_INLINE_ float log1p(float p_x) { return ::log1pf(p_x); } + static _ALWAYS_INLINE_ double log1p(double p_x) { return std::log1p(p_x); } + static _ALWAYS_INLINE_ float log1p(float p_x) { return std::log1p(p_x); } - static _ALWAYS_INLINE_ double log2(double p_x) { return ::log2(p_x); } - static _ALWAYS_INLINE_ float log2(float p_x) { return ::log2f(p_x); } + static _ALWAYS_INLINE_ double log2(double p_x) { return std::log2(p_x); } + static _ALWAYS_INLINE_ float log2(float p_x) { return std::log2(p_x); } - static _ALWAYS_INLINE_ double exp(double p_x) { return ::exp(p_x); } - static _ALWAYS_INLINE_ float exp(float p_x) { return ::expf(p_x); } + static _ALWAYS_INLINE_ double exp(double p_x) { return std::exp(p_x); } + static _ALWAYS_INLINE_ float exp(float p_x) { return std::exp(p_x); } - static _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 - } - - static _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 - } - - static _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 - } - - static _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 - } + static _ALWAYS_INLINE_ bool is_nan(double p_val) { return std::isnan(p_val); } + static _ALWAYS_INLINE_ bool is_nan(float p_val) { return std::isnan(p_val); } + + static _ALWAYS_INLINE_ bool is_inf(double p_val) { return std::isinf(p_val); } + static _ALWAYS_INLINE_ bool is_inf(float p_val) { return std::isinf(p_val); } // These methods assume (p_num + p_den) doesn't overflow. static _ALWAYS_INLINE_ int32_t division_round_up(int32_t p_num, int32_t p_den) { @@ -216,15 +142,15 @@ class Math { return (p_num + p_den - 1) / p_den; } - static _ALWAYS_INLINE_ bool is_finite(double p_val) { return isfinite(p_val); } - static _ALWAYS_INLINE_ bool is_finite(float p_val) { return isfinite(p_val); } + static _ALWAYS_INLINE_ bool is_finite(double p_val) { return std::isfinite(p_val); } + static _ALWAYS_INLINE_ bool is_finite(float p_val) { return std::isfinite(p_val); } - static _ALWAYS_INLINE_ double abs(double g) { return absd(g); } - static _ALWAYS_INLINE_ float abs(float g) { return absf(g); } + static _ALWAYS_INLINE_ double abs(double g) { return std::abs(g); } + static _ALWAYS_INLINE_ float abs(float g) { return std::abs(g); } static _ALWAYS_INLINE_ int8_t abs(int8_t g) { return g > 0 ? g : -g; } static _ALWAYS_INLINE_ int16_t abs(int16_t g) { return g > 0 ? g : -g; } - static _ALWAYS_INLINE_ int32_t abs(int32_t g) { return ::abs(g); } - static _ALWAYS_INLINE_ int64_t abs(int64_t g) { return ::llabs(g); } + static _ALWAYS_INLINE_ int32_t abs(int32_t g) { return std::abs(g); } + static _ALWAYS_INLINE_ int64_t abs(int64_t g) { return std::abs(g); } static _ALWAYS_INLINE_ double fposmod(double p_x, double p_y) { double value = Math::fmod(p_x, p_y); @@ -507,8 +433,8 @@ class Math { return Math::exp(p_db * (float)0.11512925464970228420089957273422); } - static _ALWAYS_INLINE_ double round(double p_val) { return ::round(p_val); } - static _ALWAYS_INLINE_ float round(float p_val) { return ::roundf(p_val); } + static _ALWAYS_INLINE_ double round(double p_val) { return std::round(p_val); } + static _ALWAYS_INLINE_ float round(float p_val) { return std::round(p_val); } static _ALWAYS_INLINE_ int64_t wrapi(int64_t value, int64_t min, int64_t max) { int64_t range = max - min; @@ -562,8 +488,8 @@ class Math { static void randomize(); static uint32_t rand_from_seed(uint64_t *seed); static uint32_t rand(); - static _ALWAYS_INLINE_ double randd() { return (double)rand() / (double)Math::RANDOM_32BIT_MAX; } - static _ALWAYS_INLINE_ float randf() { return (float)rand() / (float)Math::RANDOM_32BIT_MAX; } + static _ALWAYS_INLINE_ double randd() { return (double)rand() / (double)UINT32_MAX; } + static _ALWAYS_INLINE_ float randf() { return (float)rand() / (float)UINT32_MAX; } static double randfn(double mean, double deviation); static double random(double from, double to); @@ -630,18 +556,10 @@ class Math { return (a == b) || (is_nan(a) && is_nan(b)); } - static _ALWAYS_INLINE_ float absf(float g) { - return ::fabsf(g); - } - - static _ALWAYS_INLINE_ double absd(double g) { - return ::fabs(g); - } - // This function should be as fast as possible and rounding mode should not matter. static _ALWAYS_INLINE_ int fast_ftoi(float a) { // Assuming every supported compiler has `lrint()`. - return lrintf(a); + return std::lrint(a); } static _ALWAYS_INLINE_ uint32_t halfbits_to_floatbits(uint16_t h) { diff --git a/core/math/projection.cpp b/core/math/projection.cpp index a71e44d903da..e0b8dcf815d0 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 6c0b491aa100..536682de8d81 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/quaternion.h b/core/math/quaternion.h index 6dae7a795ffd..3bc85334a21c 100644 --- a/core/math/quaternion.h +++ b/core/math/quaternion.h @@ -143,7 +143,7 @@ struct [[nodiscard]] Quaternion { Vector3 n0 = p_v0.normalized(); Vector3 n1 = p_v1.normalized(); real_t d = n0.dot(n1); - if (abs(d) > ALMOST_ONE) { + if (std::abs(d) > ALMOST_ONE) { if (d >= 0) { return; // Vectors are same. } diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h index c3a754a639de..e595b66a562d 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 @@ class RandomPCG { 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 @@ class RandomPCG { 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 @@ class RandomPCG { 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 a180176fc387..f8a408a52096 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -1604,7 +1604,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"; @@ -1617,7 +1617,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) { @@ -1783,7 +1783,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); @@ -1806,7 +1806,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); } @@ -5641,7 +5641,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 56253139593c..d88e4a12edc2 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -707,7 +707,7 @@ struct _VariantCall { String s; if (p_instance->size() > 0) { const uint8_t *r = p_instance->ptr(); - s.parse_utf16((const char16_t *)r, floor((double)p_instance->size() / (double)sizeof(char16_t))); + s.parse_utf16((const char16_t *)r, std::floor((double)p_instance->size() / (double)sizeof(char16_t))); } return s; } @@ -716,7 +716,7 @@ struct _VariantCall { String s; if (p_instance->size() > 0) { const uint8_t *r = p_instance->ptr(); - s.parse_utf32(Span((const char32_t *)r, floor((double)p_instance->size() / (double)sizeof(char32_t)))); + s.parse_utf32(Span((const char32_t *)r, std::floor((double)p_instance->size() / (double)sizeof(char32_t)))); } return s; } @@ -726,9 +726,9 @@ struct _VariantCall { if (p_instance->size() > 0) { const uint8_t *r = p_instance->ptr(); #ifdef WINDOWS_ENABLED - s.parse_utf16((const char16_t *)r, floor((double)p_instance->size() / (double)sizeof(char16_t))); + s.parse_utf16((const char16_t *)r, std::floor((double)p_instance->size() / (double)sizeof(char16_t))); #else - s.parse_utf32(Span((const char32_t *)r, floor((double)p_instance->size() / (double)sizeof(char32_t)))); + s.parse_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 207e77d8610a..450bf25abb41 100644 --- a/core/variant/variant_parser.cpp +++ b/core/variant/variant_parser.cpp @@ -1933,9 +1933,9 @@ Error VariantParser::parse(Stream *p_stream, Variant &r_ret, String &r_err_str, static String rtos_fix(double p_value) { 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 { diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index b07cc2a85b9b..cd332ff3996f 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -247,7 +247,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(); @@ -277,7 +277,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 685fee6d1b59..dd2871c00ff6 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 2c8fa257869e..342b47cb78af 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -1318,7 +1318,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; } @@ -1334,7 +1334,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)) { //combit it EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); @@ -1480,7 +1480,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; } float moving_selection_begin_value = animation->bezier_track_get_key_value(moving_selection_from_track, moving_selection_from_key); diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index e36790e3467b..370faa079692 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -3164,7 +3164,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) { @@ -3245,7 +3245,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; } @@ -6898,8 +6898,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 bc678b5ba1be..dd528555e765 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -927,7 +927,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 2a12f5b2ced0..914865f60c83 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -1527,7 +1527,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/export/editor_export_platform.cpp b/editor/export/editor_export_platform.cpp index c5853164ab0b..faf618d81b33 100644 --- a/editor/export/editor_export_platform.cpp +++ b/editor/export/editor_export_platform.cpp @@ -38,6 +38,7 @@ #include "core/io/image_loader.h" #include "core/io/resource_uid.h" #include "core/io/zip_io.h" +#include "core/math/random_pcg.h" #include "core/version.h" #include "editor/editor_file_system.h" #include "editor/editor_node.h" diff --git a/editor/gui/editor_spin_slider.cpp b/editor/gui/editor_spin_slider.cpp index 5461c9b8773f..3bb5b6639416 100644 --- a/editor/gui/editor_spin_slider.cpp +++ b/editor/gui/editor_spin_slider.cpp @@ -244,7 +244,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 ed9ea1bf9ce8..0e6727b73318 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 ebfe706876eb..652c00a7475f 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 1ed69837eb1f..63bb87276a72 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 423b6e0f8413..61edd0d5c831 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -333,7 +333,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()); @@ -438,7 +438,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()); @@ -453,7 +453,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) { @@ -3119,8 +3119,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; } @@ -3265,8 +3265,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); @@ -3314,16 +3314,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 dfeb59214c2a..fbed78b15bd7 100644 --- a/editor/plugins/editor_resource_tooltip_plugins.cpp +++ b/editor/plugins/editor_resource_tooltip_plugins.cpp @@ -131,7 +131,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/gizmos/navigation_region_3d_gizmo_plugin.cpp b/editor/plugins/gizmos/navigation_region_3d_gizmo_plugin.cpp index d782e3b1b619..a15c801bd692 100644 --- a/editor/plugins/gizmos/navigation_region_3d_gizmo_plugin.cpp +++ b/editor/plugins/gizmos/navigation_region_3d_gizmo_plugin.cpp @@ -30,6 +30,7 @@ #include "navigation_region_3d_gizmo_plugin.h" +#include "core/math/random_pcg.h" #include "scene/3d/navigation_region_3d.h" #include "servers/navigation_server_3d.h" diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp index a83576d1f39a..f4bec01d7052 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 81e93cc460d4..430f8a49c3c3 100644 --- a/editor/plugins/path_3d_editor_plugin.cpp +++ b/editor/plugins/path_3d_editor_plugin.cpp @@ -434,7 +434,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, path_tilt_material, Mesh::PRIMITIVE_LINE_STRIP); diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp index 00649a7829ab..ffc525b242de 100644 --- a/editor/plugins/tiles/tile_data_editors.cpp +++ b/editor/plugins/tiles/tile_data_editors.cpp @@ -33,6 +33,7 @@ #include "tile_set_editor.h" #include "core/math/geometry_2d.h" +#include "core/math/random_pcg.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" diff --git a/editor/plugins/tiles/tile_map_layer_editor.cpp b/editor/plugins/tiles/tile_map_layer_editor.cpp index 4f09e738d1c8..57c84c8d4783 100644 --- a/editor/plugins/tiles/tile_map_layer_editor.cpp +++ b/editor/plugins/tiles/tile_map_layer_editor.cpp @@ -44,6 +44,7 @@ #include "core/input/input.h" #include "core/math/geometry_2d.h" +#include "core/math/random_pcg.h" #include "core/os/keyboard.h" TileMapLayer *TileMapLayerSubEditorPlugin::_get_edited_layer() const { diff --git a/main/main_timer_sync.cpp b/main/main_timer_sync.cpp index 569930d42777..08b861b88209 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 c17649f2cbf3..512996da589f 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -3584,7 +3584,7 @@ Error GLTFDocument::_parse_meshes(Ref p_state) { Vector tangents = array[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. 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 35d021e3cfda..7ec5790c3bb7 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 84f3e9bfe306..e7f25767e263 100644 --- a/modules/godot_physics_3d/godot_shape_3d.cpp +++ b/modules/godot_physics_3d/godot_shape_3d.cpp @@ -755,7 +755,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 bbee0ecf71f7..499c04a882b3 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 91b3e0b436b6..1b69fe5302df 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 ba904f0e9192..71c0f6010925 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 8134a17fd3aa..5a9ea8dae290 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 36e6c0e8b0b0..f09be9117a06 100644 --- a/modules/mobile_vr/mobile_vr_interface.h +++ b/modules/mobile_vr/mobile_vr_interface.h @@ -94,8 +94,8 @@ class MobileVRInterface : public XRInterface { ///@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 9b9fd640f453..345ba3c4a581 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 ea64f077c5ab..882fa480967c 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 1d4423333781..59f29206c0e6 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 1f7d5504b6f4..a3d22e3a38f6 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 e88cb6820150..51fa264ff7e1 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 e88cb6820150..51fa264ff7e1 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 f45135a61188..743c983d0a8d 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 49f2690e6115..006c3cebac34 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 2ef89747ecf6..1b0a83b38919 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 47f1a460ec30..e471af44a518 100644 --- a/platform/linuxbsd/wayland/wayland_thread.cpp +++ b/platform/linuxbsd/wayland/wayland_thread.cpp @@ -1743,7 +1743,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); @@ -3099,8 +3099,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); } @@ -3856,8 +3856,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) { @@ -4048,7 +4048,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 34443a1d7952..f72736c8266f 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -3331,7 +3331,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 e835bdb08226..87896763f2d8 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -1645,7 +1645,7 @@ 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); } } @@ -1660,7 +1660,7 @@ 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]); } } } @@ -3069,7 +3069,7 @@ 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(); @@ -3695,7 +3695,7 @@ 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 c408001ac662..08ec9aada96c 100644 --- a/platform/macos/godot_content_view.mm +++ b/platform/macos/godot_content_view.mm @@ -873,11 +873,11 @@ - (void)scrollWheel:(NSEvent *)event { 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 eb5955ac56c2..bbfd875df9e2 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -1026,31 +1026,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); } @@ -2899,7 +2899,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); @@ -5457,7 +5457,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); @@ -5471,7 +5471,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 84d9302403e4..f79862449cd5 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 e9ef50d73672..c04cb7dd4444 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 09ca2b3ccfb8..accedc1b4945 100644 --- a/scene/2d/animated_sprite_2d.cpp +++ b/scene/2d/animated_sprite_2d.cpp @@ -193,7 +193,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) { @@ -325,7 +325,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 { @@ -487,7 +487,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); @@ -559,7 +559,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 5a3cb7be0ad4..c8f476b54f74 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 efc531a08c59..aec60840f876 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/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp index ef83027fa0c4..e5a310cec241 100644 --- a/scene/2d/navigation_region_2d.cpp +++ b/scene/2d/navigation_region_2d.cpp @@ -30,6 +30,7 @@ #include "navigation_region_2d.h" +#include "core/math/random_pcg.h" #include "scene/resources/world_2d.h" #include "servers/navigation_server_2d.h" diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp index 24f261deb6bc..b0379608fd98 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 9f528715e255..da849753f393 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -331,7 +331,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/2d/tile_map_layer.cpp b/scene/2d/tile_map_layer.cpp index 587a5f934228..6872910b13ec 100644 --- a/scene/2d/tile_map_layer.cpp +++ b/scene/2d/tile_map_layer.cpp @@ -32,6 +32,7 @@ #include "core/io/marshalls.h" #include "core/math/geometry_2d.h" +#include "core/math/random_pcg.h" #include "scene/2d/tile_map.h" #include "scene/gui/control.h" #include "scene/resources/2d/navigation_mesh_source_geometry_data_2d.h" diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index ed8dc3452b9f..33c952a54620 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -78,13 +78,13 @@ class Spcap { 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 1046cb67061c..eea84e5557e5 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() { (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); @@ -602,7 +602,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) { @@ -653,7 +653,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)) { @@ -713,7 +713,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 { @@ -746,7 +746,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 0157e864ac43..6297b7d4f4be 100644 --- a/scene/3d/mesh_instance_3d.cpp +++ b/scene/3d/mesh_instance_3d.cpp @@ -584,7 +584,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 91b3906edf77..889fa764daeb 100644 --- a/scene/3d/spring_bone_simulator_3d.cpp +++ b/scene/3d/spring_bone_simulator_3d.cpp @@ -1283,7 +1283,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 fb62b46e8637..8e983e9dfc56 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 acbc892d478f..5d69b87e4959 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 1c53d3784db4..1cddec96b591 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 8d24859422ec..baaa1543ef2c 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; @@ -285,7 +285,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 b2a1d323d7a7..ea745347dc3a 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 37552f7597d5..e099d261c68f 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -3721,7 +3721,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 a64de8fb3c5d..343818026e19 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -154,7 +154,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); } @@ -782,7 +782,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; } @@ -1448,7 +1448,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) { @@ -1657,7 +1657,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 8b0fe63f5a18..c3f7d0166914 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -2204,8 +2204,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 0fdca084895b..75de126b9f1b 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 aa65e939ad94..ab02471c35f6 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -1219,7 +1219,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); } @@ -1234,7 +1234,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)) { @@ -1573,7 +1573,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 baf0c394ac93..1d51e3b5f325 100644 --- a/scene/gui/progress_bar.cpp +++ b/scene/gui/progress_bar.cpp @@ -106,13 +106,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))); @@ -122,13 +122,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 d7b1a4933d02..bcee4e1a795e 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -209,7 +209,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 2359e135da4f..1192457954ae 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -626,8 +626,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++; } @@ -744,7 +744,7 @@ 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 = MAX(p_table->columns[column].width, std::ceil(frame->lines[i].text_buf->get_size().x)); frame->lines[i].offset.y = prev_h; @@ -1928,9 +1928,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 b81927f1e00f..2f9418d1fecc 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -327,7 +327,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_physics_process_delta_time(); if (Math::abs(vel) >= dist) { diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index f6f700de2a6a..b8a12db3333f 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -617,7 +617,7 @@ void TextEdit::_notification(int p_what) { case NOTIFICATION_INTERNAL_PHYSICS_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_physics_process_delta_time(); @@ -864,10 +864,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; @@ -1197,9 +1197,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; @@ -1334,7 +1334,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); } @@ -4646,10 +4646,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; @@ -8092,7 +8092,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); } @@ -8132,7 +8132,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++) { @@ -8158,13 +8158,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); } @@ -8208,7 +8208,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 41e4ea828e7e..ea26b75979db 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 5b1f8d3057f5..902d03a579ab 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 5c5febd7b544..c5864802470c 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -2441,7 +2441,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; } @@ -4108,21 +4108,21 @@ bool Animation::_float_track_optimize_key(const TKey t0, const TKey= 1.0 - p_allowed_velocity_err) { return true; @@ -4145,15 +4145,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; @@ -4176,15 +4176,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; @@ -4214,9 +4214,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; @@ -4325,7 +4325,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); } } @@ -4357,11 +4357,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. } } @@ -4421,10 +4421,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 29e4fcb5fe72..85f0839d5da3 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 3a0c207a5dab..e4b18f20ae7e 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 de68737b8c93..2799dc457b3f 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -1772,7 +1772,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)); @@ -1815,7 +1815,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 a8584e7fed05..f7ab307e3d94 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 94bb311fc9ec..1916a3361221 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 56fe8831cbbb..4dc5fd2bebe8 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::llrint(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::lrint(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 1ab1b6eaf30c..80035e6fff29 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 3014dc703f4a..f381a757a7e5 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 bd7ac03bd19e..96bb5ab8556d 100644 --- a/servers/audio/effects/audio_effect_distortion.cpp +++ b/servers/audio/effects/audio_effect_distortion.cpp @@ -37,17 +37,17 @@ void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames, Audi 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 * 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 4055ecc9b09f..d26fff3d4752 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 1fba20983c03..0737e8531f7d 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]; @@ -194,8 +194,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 */ @@ -207,7 +207,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]; @@ -255,14 +255,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 aa554dad4aa7..24da8f70a593 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 94ae7404d260..f3383224825f 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 e3a438d97bcd..08650a976219 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::lrint((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::lrint((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::lrint(params.extra_spread_base * params.mix_rate); - int len = lrint(comb_tunings[i] * params.mix_rate) + c.extra_spread_frames; + int len = std::lrint(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::lrint(params.extra_spread_base * params.mix_rate); - int len = lrint(allpass_tunings[i] * params.mix_rate) + a.extra_spread_frames; + int len = std::lrint(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 e26d6833e0cb..48edb9c623a7 100644 --- a/servers/display_server.h +++ b/servers/display_server.h @@ -356,7 +356,7 @@ class DisplayServer : public Object { 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 786a51fa5450..8ace11dd26cf 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 f5f48772bdab..9e3cbfdc45e2 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 f6157437ee78..65fab3f02124 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp @@ -1048,7 +1048,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 b00916c0297f..af250893377c 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 f4cb5bf0aa38..622e500148d5 100644 --- a/tests/core/io/test_json.h +++ b/tests/core/io/test_json.h @@ -256,8 +256,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" }, @@ -271,8 +271,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 948fb1d7a548..57360a27105c 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