reactos/sdk/lib/crt/math/libm.h
Timo Kreuzer a9ee20cb9a [CRT:MATH] Import nextafter, nextafterf and nexttowardf from musl
Note: On Windows, where a long double is the same as a double, nextafterl is the same as nextafter, nexttowardl is the same as nexttoward.
Also nexttoward is the same as nextafter.
2025-06-30 09:19:47 +00:00

70 lines
1.5 KiB
C

//
// libm.h
//
// Partly imported from musl libc
//
// Support header for musl math code.
//
// SPDX-License-Identifier: MIT
//
#pragma once
#include <stdint.h>
#include <float.h>
#include <math.h>
// Define _STATIC_ASSERT for compatibility with legacy CRT headers
#ifndef _STATIC_ASSERT
#define _STATIC_ASSERT(expr) extern char (*__static_assert__(void)) [(expr) ? 1 : -1]
#endif
// Make sure the sizes are correct
_STATIC_ASSERT(sizeof(float) == 4);
_STATIC_ASSERT(sizeof(double) == 8);
_STATIC_ASSERT(sizeof(long double) == 8);
_Check_return_ int __cdecl _isnanf(_In_ float _X);
#define isnan _isnan
#define isnanf _isnanf
// musl has this in math.h
static __inline uint32_t __FLOAT_BITS(float __f)
{
union {float __f; uint32_t __i;} __u;
__u.__f = __f;
return __u.__i;
}
static __inline uint64_t __DOUBLE_BITS(double __f)
{
union {double __f; uint64_t __i;} __u;
__u.__f = __f;
return __u.__i;
}
#define signbit(x) \
((sizeof(x) == sizeof(float)) ? (int)(__FLOAT_BITS(x)>>31) : \
(int)(__DOUBLE_BITS(x)>>63))
static inline void fp_force_evalf(float x)
{
volatile float y;
y = x;
(void)y;
}
static inline void fp_force_eval(double x)
{
volatile double y;
y = x;
(void)y;
}
#define FORCE_EVAL(x) do { \
if (sizeof(x) == sizeof(float)) { \
fp_force_evalf(x); \
} else { \
fp_force_eval(x); \
} \
} while(0)