1 // -*- C++ -*-
2 //===---------------------- support/win32/math_win32.h --------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 
11 #ifndef _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H
12 #define _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H
13 
14 #if !defined(_LIBCPP_MSVCRT)
15 #error "This header complements Microsoft's C Runtime library, and should not be included otherwise."
16 #else
17 
18 #include <math.h>
19 #include <float.h> // _FPCLASS_PN etc.
20 #include <crtversion.h>
21 
22 #if ((_VC_CRT_MAJOR_VERSION-0) < 12)
23 // Necessary?
24 typedef float float_t;
25 typedef double double_t;
26 
isfinite(double num)27 _LIBCPP_ALWAYS_INLINE bool isfinite( double num )
28 {
29     return _finite(num) != 0;
30 }
isinf(double num)31 _LIBCPP_ALWAYS_INLINE bool isinf( double num )
32 {
33     return !isfinite(num) && !_isnan(num);
34 }
isnan(double num)35 _LIBCPP_ALWAYS_INLINE bool isnan( double num )
36 {
37     return _isnan(num) != 0;
38 }
isnormal(double num)39 _LIBCPP_ALWAYS_INLINE bool isnormal( double num )
40 {
41     int class_ = _fpclass(num);
42     return class_ == _FPCLASS_NN || class_ == _FPCLASS_PN;
43 }
44 
isgreater(double x,double y)45 _LIBCPP_ALWAYS_INLINE bool isgreater( double x, double y )
46 {
47     if(_fpclass(x) == _FPCLASS_SNAN || _fpclass(y) == _FPCLASS_SNAN) return false;
48     else return x > y;
49 }
50 
isgreaterequal(double x,double y)51 _LIBCPP_ALWAYS_INLINE bool isgreaterequal( double x, double y )
52 {
53     if(_fpclass(x) == _FPCLASS_SNAN || _fpclass(y) == _FPCLASS_SNAN) return false;
54     else return x >= y;
55 }
56 
isless(double x,double y)57 _LIBCPP_ALWAYS_INLINE bool isless( double x, double y )
58 {
59     if(_fpclass(x) == _FPCLASS_SNAN || _fpclass(y) == _FPCLASS_SNAN) return false;
60     else return x < y;
61 }
62 
islessequal(double x,double y)63 _LIBCPP_ALWAYS_INLINE bool islessequal( double x, double y )
64 {
65     if(::_fpclass(x) == _FPCLASS_SNAN || ::_fpclass(y) == _FPCLASS_SNAN) return false;
66     else return x <= y;
67 }
68 
islessgreater(double x,double y)69 _LIBCPP_ALWAYS_INLINE bool islessgreater( double x, double y )
70 {
71     if(::_fpclass(x) == _FPCLASS_SNAN || ::_fpclass(y) == _FPCLASS_SNAN) return false;
72     else return x < y || x > y;
73 }
74 
isunordered(double x,double y)75 _LIBCPP_ALWAYS_INLINE bool isunordered( double x, double y )
76 {
77     return isnan(x) || isnan(y);
78 }
signbit(double num)79 _LIBCPP_ALWAYS_INLINE bool signbit( double num )
80 {
81     switch(_fpclass(num))
82     {
83         case _FPCLASS_SNAN:
84         case _FPCLASS_QNAN:
85         case _FPCLASS_NINF:
86         case _FPCLASS_NN:
87         case _FPCLASS_ND:
88         case _FPCLASS_NZ:
89             return true;
90         case _FPCLASS_PZ:
91         case _FPCLASS_PD:
92         case _FPCLASS_PN:
93         case _FPCLASS_PINF:
94             return false;
95     }
96     return false;
97 }
copysignf(float x,float y)98 _LIBCPP_ALWAYS_INLINE float copysignf( float x, float y )
99 {
100     return (signbit (x) != signbit (y) ? - x : x);
101 }
copysign(double x,double y)102 _LIBCPP_ALWAYS_INLINE double copysign( double x, double y )
103 {
104     return ::_copysign(x,y);
105 }
copysignl(long double x,long double y)106 _LIBCPP_ALWAYS_INLINE double copysignl( long double x, long double y )
107 {
108     return ::_copysignl(x,y);
109 }
fpclassify(double num)110 _LIBCPP_ALWAYS_INLINE int fpclassify( double num )
111 {
112     return _fpclass(num);
113 }
114 #endif
115 #endif // _LIBCPP_MSVCRT
116 
117 #endif // _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H
118