6 /* TCC uses 8 bytes for double and long double, so effectively the l variants
7 * are never used. For now, they just run the normal (double) variant.
11 * most of the code in this file is taken from MUSL rs-1.0 (MIT license)
12 * - musl-libc: http://git.musl-libc.org/cgit/musl/tree/src/math?h=rs-1.0
13 * - License: http://git.musl-libc.org/cgit/musl/tree/COPYRIGHT?h=rs-1.0
16 /*******************************************************************************
17 Start of code based on MUSL
18 *******************************************************************************/
20 musl as a whole is licensed under the following standard MIT license:
22 ----------------------------------------------------------------------
23 Copyright © 2005-2014 Rich Felker, et al.
25 Permission is hereby granted, free of charge, to any person obtaining
26 a copy of this software and associated documentation files (the
27 "Software"), to deal in the Software without restriction, including
28 without limitation the rights to use, copy, modify, merge, publish,
29 distribute, sublicense, and/or sell copies of the Software, and to
30 permit persons to whom the Software is furnished to do so, subject to
31 the following conditions:
33 The above copyright notice and this permission notice shall be
34 included in all copies or substantial portions of the Software.
36 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
37 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
38 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
39 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
40 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
41 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
42 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43 ----------------------------------------------------------------------
48 __CRT_INLINE
int __cdecl
__fpclassify (double x
) {
49 union {double f
; uint64_t i
;} u
= {x
};
50 int e
= u
.i
>>52 & 0x7ff;
51 if (!e
) return u
.i
<<1 ? FP_SUBNORMAL
: FP_ZERO
;
52 if (e
==0x7ff) return u
.i
<<12 ? FP_NAN
: FP_INFINITE
;
56 __CRT_INLINE
int __cdecl
__fpclassifyf (float x
) {
57 union {float f
; uint32_t i
;} u
= {x
};
58 int e
= u
.i
>>23 & 0xff;
59 if (!e
) return u
.i
<<1 ? FP_SUBNORMAL
: FP_ZERO
;
60 if (e
==0xff) return u
.i
<<9 ? FP_NAN
: FP_INFINITE
;
64 __CRT_INLINE
int __cdecl
__fpclassifyl (long double x
) {
65 return __fpclassify(x
);
71 __CRT_INLINE
int __cdecl
__signbit (double x
) {
72 union {double d
; uint64_t i
;} y
= { x
};
76 __CRT_INLINE
int __cdecl
__signbitf (float x
) {
77 union {float f
; uint32_t i
; } y
= { x
};
81 __CRT_INLINE
int __cdecl
__signbitl (long double x
) {
88 #define TCCFP_FMIN_EVAL (isnan(x) ? y : \
90 (signbit(x) != signbit(y)) ? (signbit(x) ? x : y) : \
93 __CRT_INLINE
double __cdecl
fmin (double x
, double y
) {
94 return TCCFP_FMIN_EVAL
;
97 __CRT_INLINE
float __cdecl
fminf (float x
, float y
) {
98 return TCCFP_FMIN_EVAL
;
101 __CRT_INLINE
long double __cdecl
fminl (long double x
, long double y
) {
102 return TCCFP_FMIN_EVAL
;
105 #define TCCFP_FMAX_EVAL (isnan(x) ? y : \
107 (signbit(x) != signbit(y)) ? (signbit(x) ? y : x) : \
110 __CRT_INLINE
double __cdecl
fmax (double x
, double y
) {
111 return TCCFP_FMAX_EVAL
;
114 __CRT_INLINE
float __cdecl
fmaxf (float x
, float y
) {
115 return TCCFP_FMAX_EVAL
;
118 __CRT_INLINE
long double __cdecl
fmaxl (long double x
, long double y
) {
119 return TCCFP_FMAX_EVAL
;
125 #define TCCFP_FORCE_EVAL(x) do { \
126 if (sizeof(x) == sizeof(float)) { \
127 volatile float __x; \
129 } else if (sizeof(x) == sizeof(double)) { \
130 volatile double __x; \
133 volatile long double __x; \
138 __CRT_INLINE
double __cdecl
round (double x
) {
139 union {double f
; uint64_t i
;} u
= {x
};
140 int e
= u
.i
>> 52 & 0x7ff;
148 /* raise inexact if x!=0 */
149 TCCFP_FORCE_EVAL(x
+ 0x1p
52);
152 y
= (double)(x
+ 0x1p
52) - 0x1p
52 - x
;
164 __CRT_INLINE
long __cdecl
lround (double x
) {
168 __CRT_INLINE
long long __cdecl
llround (double x
) {
172 __CRT_INLINE
float __cdecl
roundf (float x
) {
176 __CRT_INLINE
long __cdecl
lroundf (float x
) {
180 __CRT_INLINE
long long __cdecl
llroundf (float x
) {
184 __CRT_INLINE
long double __cdecl
roundl (long double x
) {
188 __CRT_INLINE
long __cdecl
lroundl (long double x
) {
192 __CRT_INLINE
long long __cdecl
llroundl (long double x
) {
197 /*******************************************************************************
198 End of code based on MUSL
199 *******************************************************************************/
201 #endif /* _TCC_LIBM_H_ */