CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
math.h
1
3#ifndef _aspose_system_math_h_
4#define _aspose_system_math_h_
5
6#include <system/primitive_types.h>
7#include <system/decimal.h>
8
9#include <cmath>
10#include <type_traits>
11
12#include <fwd.h>
13
14namespace System
15{
45 struct Math
46 {
48 static const double ASPOSECPP_SHARED_API PI; // 3.1415926535897931
50 static const double ASPOSECPP_SHARED_API E; // 2.7182818284590451
51
55 static ASPOSECPP_SHARED_API double Acos(double d);
59 static ASPOSECPP_SHARED_API double Asin(double d);
63 static ASPOSECPP_SHARED_API double Atan(double d);
68 static ASPOSECPP_SHARED_API double Atan2(double y, double x);
72 static ASPOSECPP_SHARED_API Decimal Ceiling(const Decimal& d);
76 static ASPOSECPP_SHARED_API double Ceiling(double a);
80 static ASPOSECPP_SHARED_API double Cos(double d);
84 static ASPOSECPP_SHARED_API double Cosh(double value);
88 static ASPOSECPP_SHARED_API Decimal Floor(const Decimal& d);
92 static ASPOSECPP_SHARED_API double Floor(double d);
96 static ASPOSECPP_SHARED_API double Sin(double a);
100 static ASPOSECPP_SHARED_API double Tan(double a);
104 static ASPOSECPP_SHARED_API double Sinh(double value);
108 static ASPOSECPP_SHARED_API double Tanh(double value);
112 static ASPOSECPP_SHARED_API double Round(double a);
117 static ASPOSECPP_SHARED_API double Round(double value, int digits);
123 static ASPOSECPP_SHARED_API double Round(double value, MidpointRounding mode);
130 static ASPOSECPP_SHARED_API double Round(double value, int digits, MidpointRounding mode);
134 static ASPOSECPP_SHARED_API Decimal Round(const Decimal& d);
139 static ASPOSECPP_SHARED_API Decimal Round(const Decimal& value, int digits);
145 static ASPOSECPP_SHARED_API Decimal Round(const Decimal& d, MidpointRounding mode);
152 static ASPOSECPP_SHARED_API Decimal Round(const Decimal& d, int digits, MidpointRounding mode);
158 static ASPOSECPP_SHARED_API Decimal Truncate(const Decimal& d);
164 static ASPOSECPP_SHARED_API double Truncate(double d);
168 static ASPOSECPP_SHARED_API double Sqrt(double d);
172 static ASPOSECPP_SHARED_API double Log(double d);
176 static ASPOSECPP_SHARED_API double Log10(double d);
180 static ASPOSECPP_SHARED_API double Exp(double d);
185 static ASPOSECPP_SHARED_API double Pow(double x, double y);
190 static ASPOSECPP_SHARED_API double IEEERemainder(double x, double y);
195 template<class T>
196 static T Abs(T value)
197 {
198 static_assert(std::is_arithmetic<T>::value, "Math::Abs template argument must be an arithmetic type.");
199
200 return std::abs(value);
201 }
205 static inline Decimal Abs(const Decimal &d)
206 {
207 return d < 0 ? -d : d;
208 }
209
214 static ASPOSECPP_SHARED_API double Log(double a, double newBase);
215
220 template<typename T>
221 static typename std::enable_if<std::is_integral<T>::value && !std::is_unsigned<T>::value, int>::type Sign(T value)
222 {
223 if (value == 0)
224 return 0;
225 else if (value > 0)
226 return 1;
227 else
228 return -1;
229 }
230
235 template<typename T>
236 static typename std::enable_if<std::is_floating_point<T>::value, int>::type Sign(T value)
237 {
238 if (value < 0)
239 return -1;
240 else if (value > 0)
241 return 1;
242 else if (value == 0)
243 return 0;
244
245 throw ArithmeticException(u"NaN");
246 }
247
251 static inline int Sign(const Decimal &value)
252 {
253 return value.CompareTo(Decimal::Zero);
254 }
255
260 static ASPOSECPP_SHARED_API int64_t BigMul(int a, int b);
261
267 static ASPOSECPP_SHARED_API int DivRem(int a, int b, int &result);
273 static ASPOSECPP_SHARED_API int64_t DivRem(int64_t a, int64_t b, int64_t &result);
274
275 // >= .Net 2.0
276 //static float Round(float a);
277
278 // not a .Net
280 static const double ASPOSECPP_SHARED_API PositiveInfinity;
282 static const double ASPOSECPP_SHARED_API NegativeInfinity;
284 static const double ASPOSECPP_SHARED_API NaN;
285
291 template<class T>
292 static T Modulus(T x, T y)
293 {
294 return std::fmod(x,y);
295 }
296
303 template<class T0, class T1, class = typename std::enable_if<!std::is_same<T0, T1>::value, void>::type>
304 static auto Min(T0 val1, T1 val2) -> decltype(val1 + val2)
305 {
306 return Min_<decltype(val1 + val2)>(val1, val2);
307 }
314 template<class T0, class T1, class = typename std::enable_if<std::is_same<T0, T1>::value, void>::type>
315 static T0 Min(T0 val1, T1 val2)
316 {
317 return Min_<decltype(val1 + val2)>(val1, val2);
318 }
319
326 template<class T0, class T1, class = typename std::enable_if<!std::is_same<T0, T1>::value, void>::type>
327 static auto Max(T0 val1, T1 val2) -> decltype(val1 + val2)
328 {
329 using T = decltype(val1 + val2);
330 return Max_<T>(static_cast<T>(val1), static_cast<T>(val2));
331 }
338 template<class T0, class T1, class = typename std::enable_if<std::is_same<T0, T1>::value, void>::type>
339 static T0 Max(T0 val1, T1 val2)
340 {
341 return Max_<T0>(val1, static_cast<T0>(val2));
342 }
343
344 private:
350 template <class T>
351 static T Min_(T val1, T val2)
352 {
353 return val1 <= val2 ? val1 : val2;
354 }
355
361 template <class T>
362 static T Max_(T val1, T val2)
363 {
364 return val1 >= val2 ? val1 : val2;
365 }
366
368 enum { MaxRoundingDigits = 15 };
369
370 static const double RoundPower10Double[];
371 static const double DoubleRoundLimit; // 1e16d
372
379 static ASPOSECPP_SHARED_API double RoundImpl(double value, int digits, MidpointRounding mode);
380 }; // class Math
381
386 template <>
387 inline float Math::Min_(float val1, float val2)
388 {
389 if (val1 < val2)
390 return val1;
391 if (System::IsNaN<float>(val1))
392 return val1;
393 return val2;
394 }
395
400 template <>
401 inline double Math::Min_(double val1, double val2)
402 {
403 if (val1 < val2)
404 return val1;
405 if (System::IsNaN<double>(val1))
406 return val1;
407 return val2;
408 }
409
414 template <>
415 inline float Math::Max_(float val1, float val2)
416 {
417 if (val1 > val2)
418 return val1;
419 if (System::IsNaN<float>(val1))
420 return val1;
421 return val2;
422 }
423
428 template <>
429 inline double Math::Max_(double val1, double val2)
430 {
431 if (val1 > val2)
432 return val1;
433 if (System::IsNaN<double>(val1))
434 return val1;
435 return val2;
436 }
437
438} // namespace System
439
440#endif // _math_h_
Represents a decimal number. This type should be allocated on stack and passed to functions by value ...
Definition: decimal.h:107
int CompareTo(const Decimal &d) const
Determines if the value represented by the current object is less than, equal to or greater than the ...
static const Decimal Zero
Represents number 0.
Definition: decimal.h:123
Definition: db_command.h:9
MidpointRounding
Specifies the behavior of rounding functions.
Definition: midpoint_rounding.h:10
Contains math functions. This is a static type with no instance services. You should never create ins...
Definition: math.h:46
static T Modulus(T x, T y)
Calculates the remainder resulting from the division one specified value by another specified value.
Definition: math.h:292
static std::enable_if< std::is_integral< T >::value &&!std::is_unsigned< T >::value, int >::type Sign(T value)
Determines the sign of the specified signed integral value.
Definition: math.h:221
static const double PI
The number Pi constant.
Definition: math.h:48
static double Round(double value, int digits)
Rounds the specified value to the nearest value with the specified number of fractional digits.
static T0 Min(T0 val1, T1 val2)
Returns the smallest value out of two numeric ones specified.
Definition: math.h:315
static double Acos(double d)
Calculates the arccosine of the specified value.
static auto Min(T0 val1, T1 val2) -> decltype(val1+val2)
Returns the smallest value out of two numeric ones specified.
Definition: math.h:304
static double Pow(double x, double y)
Returns the specified value raised to the specified power.
static double Atan2(double y, double x)
Calculates the arctan of the ration of the specified values.
static double Sinh(double value)
Calculates the hyperbolic sine of the specified value.
static Decimal Round(const Decimal &value, int digits)
Rounds the specified value to the nearest value with the specified number of fractional digits.
static double Log10(double d)
Returns the base-10 logarithm of the specified value.
static T0 Max(T0 val1, T1 val2)
Returns the greatest value out of two numeric ones specified.
Definition: math.h:339
static T Abs(T value)
Returns the absolute value of the specified value.
Definition: math.h:196
static double Tan(double a)
Calculates the tangen of the specified value.
static Decimal Round(const Decimal &d, MidpointRounding mode)
Rounds the specified value to the nearest integral number. A parameter specifies the function's behav...
static double Floor(double d)
Returns the largest integral value that is less than or equal to the specified value.
static Decimal Round(const Decimal &d, int digits, MidpointRounding mode)
Rounds the specified value to the nearest value with the specified number of fractional digits....
static auto Max(T0 val1, T1 val2) -> decltype(val1+val2)
Returns the greatest value out of two numeric ones specified.
Definition: math.h:327
static double IEEERemainder(double x, double y)
Returns the remainder resulting from the division of a specified number by another specified number.
static Decimal Round(const Decimal &d)
Rounds the specified value to the nearest integral value.
static int64_t BigMul(int a, int b)
Returns the full product of two 32-bit integers.
static double Sin(double a)
Calculates the sine of the specified value.
static Decimal Floor(const Decimal &d)
Returns the largest integral value that is less than or equal to the specified value.
static std::enable_if< std::is_floating_point< T >::value, int >::type Sign(T value)
Determines the sign of the specified floating-point value.
Definition: math.h:236
static double Log(double a, double newBase)
Returns the logarithm of the specified value in the specified base.
static double Tanh(double value)
Calculates the hyperbolic tangen of the specified value.
static double Round(double value, MidpointRounding mode)
Rounds the specified value to the nearest integral number. A parameter specifies the function's behav...
static double Exp(double d)
Returns e constant raised to the specified power.
static Decimal Abs(const Decimal &d)
Returns the absolute value of a value represented by the specified Decimal object.
Definition: math.h:205
static double Sqrt(double d)
Returns the square root of the specified value.
static const double NegativeInfinity
Represents the negative infinity.
Definition: math.h:282
static double Atan(double d)
Calculates the arctan of the specified value.
static double Ceiling(double a)
Returns the smallest integral value that is greater than or equal to the specified value.
static const double NaN
Represents a not-a-number value.
Definition: math.h:284
static int64_t DivRem(int64_t a, int64_t b, int64_t &result)
Calculates the quotient of two 64-bit integers and the remainder.
static const double E
Natural logarithm's base.
Definition: math.h:50
static int Sign(const Decimal &value)
Determines the sign of the specified decimal value.
Definition: math.h:251
static double Truncate(double d)
Returns a double-precision floating point value that has integral part equal to that of the specified...
static double Round(double value, int digits, MidpointRounding mode)
Rounds the specified value to the nearest value with the specified number of fractional digits....
static double Round(double a)
Rounds the specified value to the nearest integral value.
static const double PositiveInfinity
Represents the positive infinity.
Definition: math.h:280
static Decimal Truncate(const Decimal &d)
Returns the Decimal object representing a value that has integral part equal to that of the value rep...
static double Cos(double d)
Calculates the cosine of the specified value.
static double Asin(double d)
Calculates the arcsin of the specified value.
static double Cosh(double value)
Calculates the hyperbolic cosine of the specified value.
static double Log(double d)
Returns the natural logarithm of the specified value.
static Decimal Ceiling(const Decimal &d)
Returns the smallest integral value that is greater than or equal to the specified value.
static int DivRem(int a, int b, int &result)
Calculates the quotient of two 32-bit integers and the remainder.