blob: 0d6b422a165cf9b89bc9dcf1f558bca3f1ed92d9 [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
Howard Hinnant0be8f642013-08-01 18:17:34 +000014#if !defined(_LIBCPP_MSVCRT)
15#error "This header complements Microsoft's C Runtime library, and should not be included otherwise."
Howard Hinnant9563a092011-10-27 16:24:42 +000016#else
17
18#include <math.h>
Howard Hinnant5f878d42013-09-17 01:34:47 +000019#include <float.h> // _FPCLASS_PN etc.
Saleem Abdulrasool66d4c6e2015-02-28 20:18:39 +000020#include <crtversion.h>
Howard Hinnant9563a092011-10-27 16:24:42 +000021
Saleem Abdulrasool66d4c6e2015-02-28 20:18:39 +000022#if ((_VC_CRT_MAJOR_VERSION-0) < 12)
Howard Hinnant5f878d42013-09-17 01:34:47 +000023// Necessary?
Howard Hinnant9563a092011-10-27 16:24:42 +000024typedef float float_t;
25typedef double double_t;
26
27_LIBCPP_ALWAYS_INLINE bool isfinite( double num )
28{
29 return _finite(num) != 0;
30}
31_LIBCPP_ALWAYS_INLINE bool isinf( double num )
32{
33 return !isfinite(num) && !_isnan(num);
34}
35_LIBCPP_ALWAYS_INLINE bool isnan( double num )
36{
37 return _isnan(num) != 0;
38}
39_LIBCPP_ALWAYS_INLINE bool isnormal( double num )
40{
41 int class_ = _fpclass(num);
42 return class_ == _FPCLASS_NN || class_ == _FPCLASS_PN;
43}
44
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
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
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
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
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
75_LIBCPP_ALWAYS_INLINE bool isunordered( double x, double y )
76{
77 return isnan(x) || isnan(y);
78}
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}
98_LIBCPP_ALWAYS_INLINE float copysignf( float x, float y )
99{
100 return (signbit (x) != signbit (y) ? - x : x);
101}
102_LIBCPP_ALWAYS_INLINE double copysign( double x, double y )
103{
104 return ::_copysign(x,y);
105}
106_LIBCPP_ALWAYS_INLINE double copysignl( long double x, long double y )
107{
108 return ::_copysignl(x,y);
109}
110_LIBCPP_ALWAYS_INLINE int fpclassify( double num )
111{
112 return _fpclass(num);
113}
Saleem Abdulrasool66d4c6e2015-02-28 20:18:39 +0000114#endif
Howard Hinnant0be8f642013-08-01 18:17:34 +0000115#endif // _LIBCPP_MSVCRT
Howard Hinnant9563a092011-10-27 16:24:42 +0000116
Bob Wilsona4fd70e2012-02-20 16:56:13 +0000117#endif // _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H