#pragma once #include #define M_PI 3.14159265359 #define M_PI_2 1.57079632679 #define abs(x) (((x) < 0) ? -(x) : (x)) #define max(a, b) (((a) > (b)) ? (a) : (b)) #define min(a, b) (((a) < (b)) ? (a) : (b)) #ifdef __cplusplus extern "C" { #endif static inline bool isnan(double x) { return x != x; } static inline bool isinf(double x) { return !isnan(x) && isnan(x - x); } #define IMPORT_UNARY(fn) __attribute__((import_module("Math"), import_name(#fn))) double fn(double); #define IMPORT_BINARY(fn) __attribute__((import_module("Math"), import_name(#fn))) double fn(double, double); IMPORT_UNARY(floor) IMPORT_UNARY(ceil) IMPORT_UNARY(round) IMPORT_UNARY(trunc) IMPORT_UNARY(exp) IMPORT_UNARY(log) IMPORT_UNARY(log10) IMPORT_UNARY(sqrt) IMPORT_UNARY(sin) IMPORT_UNARY(cos) IMPORT_UNARY(tan) IMPORT_UNARY(asin) IMPORT_UNARY(acos) IMPORT_UNARY(atan) IMPORT_UNARY(sinh) IMPORT_UNARY(cosh) IMPORT_UNARY(tanh) IMPORT_BINARY(fmod) IMPORT_BINARY(pow) IMPORT_BINARY(atan2) #undef IMPORT_UNARY #undef IMPORT_BINARY #ifdef __cplusplus } #endif