our_dick/include/math/math_common.hpp
2020-08-30 10:48:06 -07:00

61 lines
1.8 KiB
C++

/**
This file is a part of our_dick
Copyright (C) 2020 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef REXY_DETAIL_MATH_HPP
#define REXY_DETAIL_MATH_HPP
namespace math{
namespace detail{
//sentinel classes saying how to initialize some math classes
struct zero_initialize_t {};
struct no_initialize_t {};
struct id_initialize_t {};
struct manual_initialize_t {};
}
//instantiation of sentinels
static inline constexpr detail::zero_initialize_t zero_initialize;
static inline constexpr detail::no_initialize_t no_initialize;
static inline constexpr detail::id_initialize_t id_initialize;
static inline constexpr detail::manual_initialize_t manual_initialize;
template<typename T>
static constexpr T pi(){
return static_cast<T>(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821);
}
template<typename T>
static constexpr T to_degrees(T t){
return (t * 180.0) / pi<T>();
}
template<typename T>
static constexpr T to_radians(T t){
return (t * pi<T>()) / 180.0;
}
constexpr long double operator"" _rad(long double f){
return f;
}
constexpr long double operator"" _deg(long double f){
return to_radians(f);
}
}
#endif