DotNetDupe 5.0.4
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
Math.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "System/Math.h"
5#include <cmath>
6
7namespace DotNetDupe {
8 namespace System {
9
10 int Math::Abs(int iValue) {
12 return std::abs(iValue);
13 }
14
15 long long Math::Abs(long long llValue) {
17 return std::abs(llValue);
18 }
19
20 float Math::Abs(float fValue) {
22 return std::fabs(fValue);
23 }
24
25 double Math::Abs(double dValue) {
27 return std::fabs(dValue);
28 }
29
30 int Math::Max(int iVal1, int iVal2) {
32 return (iVal1 >= iVal2) ? iVal1 : iVal2;
33 }
34
35 long long Math::Max(long long llVal1, long long llVal2) {
37 return (llVal1 >= llVal2) ? llVal1 : llVal2;
38 }
39
40 float Math::Max(float fVal1, float fVal2) {
42 return (fVal1 >= fVal2) ? fVal1 : fVal2;
43 }
44
45 double Math::Max(double dVal1, double dVal2) {
47 return (dVal1 >= dVal2) ? dVal1 : dVal2;
48 }
49
50 int Math::Min(int iVal1, int iVal2) {
52 return (iVal1 <= iVal2) ? iVal1 : iVal2;
53 }
54
55 long long Math::Min(long long llVal1, long long llVal2) {
57 return (llVal1 <= llVal2) ? llVal1 : llVal2;
58 }
59
60 float Math::Min(float fVal1, float fVal2) {
62 return (fVal1 <= fVal2) ? fVal1 : fVal2;
63 }
64
65 double Math::Min(double dVal1, double dVal2) {
67 return (dVal1 <= dVal2) ? dVal1 : dVal2;
68 }
69
70 int Math::Clamp(int iValue, int iMin, int iMax) {
72 if (iMin > iMax) throw ArgumentException("min cannot be greater than max.");
73 if (iValue < iMin) return iMin;
74 if (iValue > iMax) return iMax;
75 return iValue;
76 }
77
78 long long Math::Clamp(long long llValue, long long llMin, long long llMax) {
80 if (llMin > llMax) throw ArgumentException("min cannot be greater than max.");
81 if (llValue < llMin) return llMin;
82 if (llValue > llMax) return llMax;
83 return llValue;
84 }
85
86 double Math::Clamp(double dValue, double dMin, double dMax) {
88 if (dMin > dMax) throw ArgumentException("min cannot be greater than max.");
89 if (dValue < dMin) return dMin;
90 if (dValue > dMax) return dMax;
91 return dValue;
92 }
93
94 int Math::Sign(int iValue) {
96 if (iValue > 0) return 1;
97 if (iValue < 0) return -1;
98 return 0;
99 }
100
101 int Math::Sign(long long llValue) {
103 if (llValue > 0) return 1;
104 if (llValue < 0) return -1;
105 return 0;
106 }
107
108 int Math::Sign(double dValue) {
110 if (dValue > 0.0) return 1;
111 if (dValue < 0.0) return -1;
112 return 0;
113 }
114
115 double Math::Floor(double dValue) {
117 return std::floor(dValue);
118 }
119
120 double Math::Ceiling(double dValue) {
122 return std::ceil(dValue);
123 }
124
125 double Math::Round(double dValue) {
127 return std::round(dValue);
128 }
129
130 double Math::Round(double dValue, int iDigits) {
132 if (iDigits < 0 || iDigits > 15) throw ArgumentOutOfRangeException("Digits must be between 0 and 15.");
133 double dFactor = std::pow(10.0, iDigits);
134 return std::round(dValue * dFactor) / dFactor;
135 }
136
137 double Math::Truncate(double dValue) {
139 return std::trunc(dValue);
140 }
141
142 double Math::Sqrt(double dValue) {
144 return std::sqrt(dValue);
145 }
146
147 double Math::Cbrt(double dValue) {
149 return std::cbrt(dValue);
150 }
151
152 double Math::Pow(double dBase, double dExponent) {
154 return std::pow(dBase, dExponent);
155 }
156
157 double Math::Exp(double dValue) {
159 return std::exp(dValue);
160 }
161
162 double Math::Log(double dValue) {
164 return std::log(dValue);
165 }
166
167 double Math::Log(double dValue, double dNewBase) {
169 if (dNewBase <= 0.0 || dNewBase == 1.0) throw ArgumentException("Base must be positive and not equal to 1.");
170 return std::log(dValue) / std::log(dNewBase);
171 }
172
173 double Math::Log10(double dValue) {
175 return std::log10(dValue);
176 }
177
178 double Math::Log2(double dValue) {
180 return std::log2(dValue);
181 }
182
183 double Math::Sin(double dValue) {
185 return std::sin(dValue);
186 }
187
188 double Math::Cos(double dValue) {
190 return std::cos(dValue);
191 }
192
193 double Math::Tan(double dValue) {
195 return std::tan(dValue);
196 }
197
198 double Math::Asin(double dValue) {
200 return std::asin(dValue);
201 }
202
203 double Math::Acos(double dValue) {
205 return std::acos(dValue);
206 }
207
208 double Math::Atan(double dValue) {
210 return std::atan(dValue);
211 }
212
213 double Math::Atan2(double dY, double dX) {
215 return std::atan2(dY, dX);
216 }
217
218 double Math::Sinh(double dValue) {
220 return std::sinh(dValue);
221 }
222
223 double Math::Cosh(double dValue) {
225 return std::cosh(dValue);
226 }
227
228 double Math::Tanh(double dValue) {
230 return std::tanh(dValue);
231 }
232
233 }
234}
Defines the exception thrown when an invalid argument is provided to a method.
Defines the exception thrown when an argument value is outside the acceptable range of values.
Provides constants and static methods for trigonometric, logarithmic, and other common mathematical f...
ArgumentException(const String &sMessage)
Initializes a new instance of the ArgumentException class with a specified error message.
ArgumentOutOfRangeException(const String &sMessage)
Initializes a new instance of the ArgumentOutOfRangeException class with a specified error message.
static double Cos(double dValue)
Returns the cosine of the specified angle.
Definition Math.cpp:188
static double Floor(double dValue)
Returns the largest integral value less than or equal to the specified number.
Definition Math.cpp:115
static double Log2(double dValue)
Returns the base 2 logarithm of a specified number.
Definition Math.cpp:178
static double Round(double dValue)
Rounds a double-precision floating-point value to the nearest integral value.
Definition Math.cpp:125
static double Exp(double dValue)
Returns e raised to the specified power.
Definition Math.cpp:157
static double Sin(double dValue)
Returns the sine of the specified angle.
Definition Math.cpp:183
static int Clamp(int iValue, int iMin, int iMax)
Returns a value clamped to the inclusive range of min and max.
Definition Math.cpp:70
static double Asin(double dValue)
Returns the angle whose sine is the specified number.
Definition Math.cpp:198
static int Sign(int iValue)
Returns an integer that indicates the sign of a 32-bit signed integer.
Definition Math.cpp:94
static double Acos(double dValue)
Returns the angle whose cosine is the specified number.
Definition Math.cpp:203
static int Min(int iVal1, int iVal2)
Returns the smaller of two 32-bit signed integers.
Definition Math.cpp:50
static double Tan(double dValue)
Returns the tangent of the specified angle.
Definition Math.cpp:193
static double Log(double dValue)
Returns the natural (base e) logarithm of a specified number.
Definition Math.cpp:162
static int Max(int iVal1, int iVal2)
Returns the larger of two 32-bit signed integers.
Definition Math.cpp:30
static double Truncate(double dValue)
Calculates the integral part of a specified double-precision floating-point number.
Definition Math.cpp:137
static double Cbrt(double dValue)
Returns the cube root of a specified number.
Definition Math.cpp:147
static double Ceiling(double dValue)
Returns the smallest integral value that is greater than or equal to the specified number.
Definition Math.cpp:120
static double Log10(double dValue)
Returns the base 10 logarithm of a specified number.
Definition Math.cpp:173
static double Sqrt(double dValue)
Returns the square root of a specified number.
Definition Math.cpp:142
static double Pow(double dBase, double dExponent)
Returns a specified number raised to the specified power.
Definition Math.cpp:152
static double Cosh(double dValue)
Returns the hyperbolic cosine of the specified angle.
Definition Math.cpp:223
static double Sinh(double dValue)
Returns the hyperbolic sine of the specified angle.
Definition Math.cpp:218
static double Atan2(double dY, double dX)
Returns the angle whose tangent is the quotient of two specified numbers.
Definition Math.cpp:213
static double Atan(double dValue)
Returns the angle whose tangent is the specified number.
Definition Math.cpp:208
static int Abs(int iValue)
Returns the absolute value of a 32-bit signed integer.
Definition Math.cpp:10
static double Tanh(double dValue)
Returns the hyperbolic tangent of the specified angle.
Definition Math.cpp:228