/* Minimal math.h stub for freestanding Nim builds */
#ifndef _MATH_H_STUB
#define _MATH_H_STUB

static inline double fabs(double x) { return x < 0 ? -x : x; }
static inline float fabsf(float x) { return x < 0 ? -x : x; }
static inline double fmod(double x, double y) { return x - (long long)(x / y) * y; }
static inline double floor(double x) { return (double)(long long)x - (x < (double)(long long)x); }
static inline double ceil(double x) { return (double)(long long)x + (x > (double)(long long)x); }
static inline double round(double x) { return floor(x + 0.5); }

#define HUGE_VAL __builtin_huge_val()
#define NAN __builtin_nan("")
#define INFINITY __builtin_inf()

#endif
