Skip to content

Commit

Permalink
fix: use math macros instead of redefining them
Browse files Browse the repository at this point in the history
  • Loading branch information
mookums committed Nov 28, 2023
1 parent 1328d9f commit 4511cc3
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/decimal.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef DECIMAL_H
#define DECIMAL_H

#include <cmath>
#include <string>

#ifdef LOST_FLOAT_MODE
typedef float decimal;
#define STR_TO_DECIMAL(x) std::stof(x)
Expand All @@ -18,19 +21,19 @@
#define DECIMAL(x) (decimal) x

// Math Constants wrapped with Decimal typecast
#define DECIMAL_M_E (decimal) 2.7182818284590452354 /* e */
#define DECIMAL_M_LOG2E (decimal) 1.4426950408889634074 /* log_2 e */
#define DECIMAL_M_LOG10E (decimal) 0.43429448190325182765 /* log_10 e */
#define DECIMAL_M_LN2 (decimal) 0.69314718055994530942 /* log_e 2 */
#define DECIMAL_M_LN10 (decimal) 2.30258509299404568402 /* log_e 10 */
#define DECIMAL_M_PI (decimal) 3.14159265358979323846 /* pi */
#define DECIMAL_M_PI_2 (decimal) 1.57079632679489661923 /* pi/2 */
#define DECIMAL_M_PI_4 (decimal) 0.78539816339744830962 /* pi/4 */
#define DECIMAL_M_1_PI (decimal) 0.31830988618379067154 /* 1/pi */
#define DECIMAL_M_2_PI (decimal) 0.63661977236758134308 /* 2/pi */
#define DECIMAL_M_2_SQRTPI (decimal) 1.12837916709551257390 /* 2/sqrt(pi) */
#define DECIMAL_M_SQRT2 (decimal) 1.41421356237309504880 /* sqrt(2) */
#define DECIMAL_M_SQRT1_2 (decimal) 0.70710678118654752440 /* 1/sqrt(2) */
#define DECIMAL_M_E (decimal) M_E /* e */
#define DECIMAL_M_LOG2E (decimal) M_LOG2E /* log_2 e */
#define DECIMAL_M_LOG10E (decimal) M_LOG10E /* log_10 e */
#define DECIMAL_M_LN2 (decimal) M_LN2 /* log_e 2 */
#define DECIMAL_M_LN10 (decimal) M_LN10 /* log_e 10 */
#define DECIMAL_M_PI (decimal) M_PI /* pi */
#define DECIMAL_M_PI_2 (decimal) M_PI_2 /* pi/2 */
#define DECIMAL_M_PI_4 (decimal) M_PI_4 /* pi/4 */
#define DECIMAL_M_1_PI (decimal) M_1_PI /* 1/pi */
#define DECIMAL_M_2_PI (decimal) M_2_PI /* 2/pi */
#define DECIMAL_M_2_SQRTPI (decimal) M_2_SQRTPI /* 2/sqrt(pi) */
#define DECIMAL_M_SQRT2 (decimal) M_SQRT2 /* sqrt(2) */
#define DECIMAL_M_SQRT1_2 (decimal) M_SQRT1_2 /* 1/sqrt(2) */

// Math Functions wrapped with Decimal typecast
#define DECIMAL_POW(base,power) (decimal) std::pow(base, power)
Expand Down

0 comments on commit 4511cc3

Please sign in to comment.