ReactOS 0.4.16-dev-1489-g8fbbb41
libm.h
Go to the documentation of this file.
1//
2// libm.h
3//
4// Partly imported from musl libc
5//
6// Support header for musl math code.
7//
8// SPDX-License-Identifier: MIT
9//
10
11#pragma once
12
13#include <stdint.h>
14#include <float.h>
15#include <math.h>
16
17// Define _STATIC_ASSERT for compatibility with legacy CRT headers
18#ifndef _STATIC_ASSERT
19#define _STATIC_ASSERT(expr) extern char (*__static_assert__(void)) [(expr) ? 1 : -1]
20#endif
21
22// Make sure the sizes are correct
23_STATIC_ASSERT(sizeof(float) == 4);
24_STATIC_ASSERT(sizeof(double) == 8);
25_STATIC_ASSERT(sizeof(long double) == 8);
26
28#define isnan _isnan
29#define isnanf _isnanf
30
31// musl has this in math.h
33{
34 union {float __f; uint32_t __i;} __u;
35 __u.__f = __f;
36 return __u.__i;
37}
38
40{
41 union {double __f; uint64_t __i;} __u;
42 __u.__f = __f;
43 return __u.__i;
44}
45
46#define signbit(x) \
47 ((sizeof(x) == sizeof(float)) ? (int)(__FLOAT_BITS(x)>>31) : \
48 (int)(__DOUBLE_BITS(x)>>63))
49
50static inline void fp_force_evalf(float x)
51{
52 volatile float y;
53 y = x;
54 (void)y;
55}
56
57static inline void fp_force_eval(double x)
58{
59 volatile double y;
60 y = x;
61 (void)y;
62}
63
64#define FORCE_EVAL(x) do { \
65 if (sizeof(x) == sizeof(float)) { \
66 fp_force_evalf(x); \
67 } else { \
68 fp_force_eval(x); \
69 } \
70} while(0)
#define _X(x)
Definition: CPath.cpp:42
#define __inline
Definition: _wctype.cpp:15
#define __cdecl
Definition: accygwin.h:79
UINT32 uint32_t
Definition: types.h:75
UINT64 uint64_t
Definition: types.h:77
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
static void fp_force_evalf(float x)
Definition: libm.h:50
#define _STATIC_ASSERT(expr)
Definition: libm.h:19
static __inline uint64_t __DOUBLE_BITS(double __f)
Definition: libm.h:39
static void fp_force_eval(double x)
Definition: libm.h:57
static __inline uint32_t __FLOAT_BITS(float __f)
Definition: libm.h:32
_Check_return_ int __cdecl _isnanf(_In_ float _X)
Definition: _isnanf.c:13
#define _Check_return_
Definition: no_sal2.h:60
#define _In_
Definition: no_sal2.h:158