WPILibC++ 2023.4.3-108-ge5452e3
fmod.hpp
Go to the documentation of this file.
1/*################################################################################
2 ##
3 ## Copyright (C) 2016-2022 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21#ifndef _gcem_fmod_HPP
22#define _gcem_fmod_HPP
23
24namespace internal
25{
26
27template<typename T>
28constexpr
29T
30fmod_check(const T x, const T y)
31noexcept
32{
33 return( // NaN check
34 any_nan(x, y) ? \
35 GCLIM<T>::quiet_NaN() :
36 // +/- infinite
37 !all_finite(x, y) ? \
38 GCLIM<T>::quiet_NaN() :
39 // else
40 x - trunc(x/y)*y );
41}
42
43template<typename T1, typename T2, typename TC = common_return_t<T1,T2>>
44constexpr
45TC
46fmod_type_check(const T1 x, const T2 y)
47noexcept
48{
49 return fmod_check(static_cast<TC>(x),static_cast<TC>(y));
50}
51
52}
53
54/**
55 * Compile-time remainder of division function
56 * @param x a real-valued input.
57 * @param y a real-valued input.
58 * @return computes the floating-point remainder of \f$ x / y \f$ (rounded towards zero) using \f[ \text{fmod}(x,y) = x - \text{trunc}(x/y) \times y \f]
59 */
60
61template<typename T1, typename T2>
62constexpr
63common_return_t<T1,T2>
64fmod(const T1 x, const T2 y)
65noexcept
66{
68}
69
70#endif
constexpr common_return_t< T1, T2 > fmod(const T1 x, const T2 y) noexcept
Compile-time remainder of division function.
Definition: fmod.hpp:64
const Scalar & y
Definition: MathFunctions.h:821
Definition: Eigen_Colamd.h:50
constexpr TC fmod_type_check(const T1 x, const T2 y) noexcept
Definition: fmod.hpp:46
constexpr T fmod_check(const T x, const T y) noexcept
Definition: fmod.hpp:30
constexpr bool all_finite(const T1 x, const T2 y) noexcept
Definition: is_finite.hpp:52
constexpr bool any_nan(const T1 x, const T2 y) noexcept
Definition: is_nan.hpp:45
constexpr return_t< T > trunc(const T x) noexcept
Compile-time trunc function.
Definition: trunc.hpp:115