Merge pull request #104386 from Repiteo/core/cpp-math

Core: Replace C math headers with C++ equivalents
This commit is contained in:
Thaddeus Crews
2025-04-27 19:21:22 -05:00
101 changed files with 414 additions and 498 deletions

View File

@@ -38,8 +38,6 @@
#include "core/templates/hash_map.h"
#include "core/variant/dictionary.h"
#include <cmath>
const char *Image::format_names[Image::FORMAT_MAX] = {
"Lum8",
"LumAlpha8",
@@ -4418,12 +4416,12 @@ Dictionary Image::compute_image_metrics(const Ref<Image> 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;

View File

@@ -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));

View File

@@ -525,11 +525,11 @@ Ref<PListNode> PList::read_bplist_obj(Ref<FileAccess> p_file, uint64_t p_offset_
} break;
case 0x10: {
node->data_type = PL_NODE_TYPE_INTEGER;
node->data_int = static_cast<int64_t>(read_bplist_var_size_int(p_file, pow(2, marker_size)));
node->data_int = static_cast<int64_t>(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<int64_t>(read_bplist_var_size_int(p_file, pow(2, marker_size)));
node->data_int = static_cast<int64_t>(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<PListNode> PList::read_bplist_obj(Ref<FileAccess> 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<PListNode> PList::read_bplist_obj(Ref<FileAccess> 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<PListNode> PList::read_bplist_obj(Ref<FileAccess> 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<PListNode> PList::read_bplist_obj(Ref<FileAccess> 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<PListNode> PList::read_bplist_obj(Ref<FileAccess> 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();