blob: 80eabc1353d6a093945a09f8b61137577267a2aa [file] [log] [blame]
Howard Hinnant9563a092011-10-27 16:24:42 +00001// -*- 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(_MSC_VER)
15#error "This header is MSVC specific, Clang and GCC should not include it"
16#else
17
18#include <math.h>
19
20typedef float float_t;
21typedef double double_t;
22
23_LIBCPP_ALWAYS_INLINE bool isfinite( double num )
24{
25 return _finite(num) != 0;
26}
27_LIBCPP_ALWAYS_INLINE bool isinf( double num )
28{
29 return !isfinite(num) && !_isnan(num);
30}
31_LIBCPP_ALWAYS_INLINE bool isnan( double num )
32{
33 return _isnan(num) != 0;
34}
35_LIBCPP_ALWAYS_INLINE bool isnormal( double num )
36{
37 int class_ = _fpclass(num);
38 return class_ == _FPCLASS_NN || class_ == _FPCLASS_PN;
39}
40
41_LIBCPP_ALWAYS_INLINE bool isgreater( double x, double y )
42{
43 if(_fpclass(x) == _FPCLASS_SNAN || _fpclass(y) == _FPCLASS_SNAN) return false;
44 else return x > y;
45}
46
47_LIBCPP_ALWAYS_INLINE bool isgreaterequal( double x, double y )
48{
49 if(_fpclass(x) == _FPCLASS_SNAN || _fpclass(y) == _FPCLASS_SNAN) return false;
50 else return x >= y;
51}
52
53_LIBCPP_ALWAYS_INLINE bool isless( double x, double y )
54{
55 if(_fpclass(x) == _FPCLASS_SNAN || _fpclass(y) == _FPCLASS_SNAN) return false;
56 else return x < y;
57}
58
59_LIBCPP_ALWAYS_INLINE bool islessequal( double x, double y )
60{
61 if(::_fpclass(x) == _FPCLASS_SNAN || ::_fpclass(y) == _FPCLASS_SNAN) return false;
62 else return x <= y;
63}
64
65_LIBCPP_ALWAYS_INLINE bool islessgreater( double x, double y )
66{
67 if(::_fpclass(x) == _FPCLASS_SNAN || ::_fpclass(y) == _FPCLASS_SNAN) return false;
68 else return x < y || x > y;
69}
70
71_LIBCPP_ALWAYS_INLINE bool isunordered( double x, double y )
72{
73 return isnan(x) || isnan(y);
74}
75_LIBCPP_ALWAYS_INLINE bool signbit( double num )
76{
77 switch(_fpclass(num))
78 {
79 case _FPCLASS_SNAN:
80 case _FPCLASS_QNAN:
81 case _FPCLASS_NINF:
82 case _FPCLASS_NN:
83 case _FPCLASS_ND:
84 case _FPCLASS_NZ:
85 return true;
86 case _FPCLASS_PZ:
87 case _FPCLASS_PD:
88 case _FPCLASS_PN:
89 case _FPCLASS_PINF:
90 return false;
91 }
92 return false;
93}
94_LIBCPP_ALWAYS_INLINE float copysignf( float x, float y )
95{
96 return (signbit (x) != signbit (y) ? - x : x);
97}
98_LIBCPP_ALWAYS_INLINE double copysign( double x, double y )
99{
100 return ::_copysign(x,y);
101}
102_LIBCPP_ALWAYS_INLINE double copysignl( long double x, long double y )
103{
104 return ::_copysignl(x,y);
105}
106_LIBCPP_ALWAYS_INLINE int fpclassify( double num )
107{
108 return _fpclass(num);
109}
110
111#endif // _MSC_VER
112
113#endif // _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H