Kiwano Engine v1.3.x
Scalar.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <cmath>
23#include <kiwano/math/Constants.h>
24
25namespace kiwano
26{
27namespace math
28{
29
30inline int Abs(int val)
31{
32 return ::abs(val);
33}
34inline float Abs(float val)
35{
36 return ::fabsf(val);
37}
38inline double Abs(double val)
39{
40 return ::fabs(val);
41}
42
43inline float Sqrt(float val)
44{
45 return ::sqrtf(val);
46}
47inline double Sqrt(double val)
48{
49 return ::sqrt(val);
50}
51
52inline float Pow(float core, float exponent)
53{
54 return ::powf(core, exponent);
55}
56inline double Pow(double core, double exponent)
57{
58 return ::pow(core, exponent);
59}
60
61inline int Sign(int val)
62{
63 return val < 0 ? -1 : 1;
64}
65inline float Sign(float val)
66{
67 return val < 0 ? -1.f : 1.f;
68}
69inline double Sign(double val)
70{
71 return val < 0 ? -1.0 : 1.0;
72}
73
74inline float Degree2Radian(float angle)
75{
76 return angle * math::PI_F / 180.f;
77}
78inline double Degree2Radian(double angle)
79{
80 return angle * math::PI_D / 180.0;
81}
82
83inline float Radian2Degree(float radian)
84{
85 return radian * 180.f / math::PI_F;
86}
87inline double Radian2Degree(double radian)
88{
89 return radian * 180.0 / math::PI_D;
90}
91
92inline float Sin(float val)
93{
94 return ::sinf(Degree2Radian(val));
95}
96inline double Sin(double val)
97{
98 return ::sin(Degree2Radian(val));
99}
100
101inline float Cos(float val)
102{
103 return ::cosf(Degree2Radian(val));
104}
105inline double Cos(double val)
106{
107 return ::cos(Degree2Radian(val));
108}
109
110inline float Tan(float val)
111{
112 return ::tanf(Degree2Radian(val));
113}
114inline double Tan(double val)
115{
116 return ::tan(Degree2Radian(val));
117}
118
119inline float Asin(float val)
120{
121 return Radian2Degree(::asinf(val));
122}
123inline double Asin(double val)
124{
125 return Radian2Degree(::asin(val));
126}
127
128inline float Acos(float val)
129{
130 return Radian2Degree(::acosf(val));
131}
132inline double Acos(double val)
133{
134 return Radian2Degree(::acos(val));
135}
136
137inline float Atan(float val)
138{
139 return Radian2Degree(::atanf(val));
140}
141inline double Atan(double val)
142{
143 return Radian2Degree(::atan(val));
144}
145
146inline float Ceil(float val)
147{
148 return ::ceil(val);
149}
150inline double Ceil(double val)
151{
152 return ::ceil(val);
153}
154
155inline float Floor(float val)
156{
157 return ::floor(val);
158}
159inline double Floor(double val)
160{
161 return ::floor(val);
162}
163
164} // namespace math
165} // namespace kiwano