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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions core/func_defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**************************************************************************/
/* func_defs.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#pragma once

#include <type_traits>

#define EXPLICIT_PARAM_FUNC(RETURN_TYPE, TYPE, EXTRA) \
template <typename T> \
EXTRA typename std::enable_if<std::is_same<T, TYPE>::value, RETURN_TYPE>::type
7 changes: 5 additions & 2 deletions core/math/math_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#pragma once

#include "core/error/error_macros.h"
#include "core/func_defs.h"
#include "core/math/math_defs.h"
#include "core/typedefs.h"

Expand Down Expand Up @@ -622,10 +623,12 @@ _ALWAYS_INLINE_ float db_to_linear(float p_db) {
return exp(p_db * (float)0.11512925464970228420089957273422);
}

_ALWAYS_INLINE_ double round(double p_val) {
EXPLICIT_PARAM_FUNC(double, double, _ALWAYS_INLINE_)
round(T p_val) {
return std::round(p_val);
}
_ALWAYS_INLINE_ float round(float p_val) {
EXPLICIT_PARAM_FUNC(float, float, _ALWAYS_INLINE_)
round(T p_val) {
return std::round(p_val);
}

Expand Down