added round to Math, and fixed the type of the double pow's arguments.

This commit is contained in:
Relintai 2022-02-04 11:31:43 +01:00
parent d0c80ffe6a
commit 5503e58d54

View File

@ -1,12 +1,12 @@
#ifndef MATH_H
#define MATH_H
#include "core/typedefs.h"
#include "math_defs.h"
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <cstdint>
#include "math_defs.h"
#include "core/typedefs.h"
#define MATH_PI 3.1415926535897932384626433833
#define EPSILON 0.00001
@ -63,8 +63,11 @@ public:
inline static float ceil(const float x) { return ::ceilf(x); }
inline static double ceil(const double x) { return ::ceil(x); }
inline static float round(const float x) { return ::roundf(x); }
inline static double round(const double x) { return ::round(x); }
inline static float pow(const float x, const float y) { return ::powf(x, y); }
inline static double pow(const double x, const float y) { return ::pow(x, y); }
inline static double pow(const double x, const double y) { return ::pow(x, y); }
inline static float log(const float x) { return ::logf(x); }
inline static double log(const double x) { return ::log(x); }
@ -105,6 +108,15 @@ public:
return diff < epsilon;
}
// Taken from the Godot Engine (MIT License)
// Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.
// Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md).
// 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);
}
static void seed(const unsigned int s);
static void randomize();