Howard Hinnant | 9563a09 | 2011-10-27 16:24:42 +0000 | [diff] [blame] | 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 | |
Howard Hinnant | 0be8f64 | 2013-08-01 18:17:34 +0000 | [diff] [blame] | 14 | #if !defined(_LIBCPP_MSVCRT) |
| 15 | #error "This header complements Microsoft's C Runtime library, and should not be included otherwise." |
Howard Hinnant | 9563a09 | 2011-10-27 16:24:42 +0000 | [diff] [blame] | 16 | #else |
| 17 | |
| 18 | #include <math.h> |
Howard Hinnant | 5f878d4 | 2013-09-17 01:34:47 +0000 | [diff] [blame] | 19 | #include <float.h> // _FPCLASS_PN etc. |
Howard Hinnant | 9563a09 | 2011-10-27 16:24:42 +0000 | [diff] [blame] | 20 | |
Howard Hinnant | 5f878d4 | 2013-09-17 01:34:47 +0000 | [diff] [blame] | 21 | // Necessary? |
Howard Hinnant | 9563a09 | 2011-10-27 16:24:42 +0000 | [diff] [blame] | 22 | typedef float float_t; |
| 23 | typedef double double_t; |
| 24 | |
| 25 | _LIBCPP_ALWAYS_INLINE bool isfinite( double num ) |
| 26 | { |
| 27 | return _finite(num) != 0; |
| 28 | } |
| 29 | _LIBCPP_ALWAYS_INLINE bool isinf( double num ) |
| 30 | { |
| 31 | return !isfinite(num) && !_isnan(num); |
| 32 | } |
| 33 | _LIBCPP_ALWAYS_INLINE bool isnan( double num ) |
| 34 | { |
| 35 | return _isnan(num) != 0; |
| 36 | } |
| 37 | _LIBCPP_ALWAYS_INLINE bool isnormal( double num ) |
| 38 | { |
| 39 | int class_ = _fpclass(num); |
| 40 | return class_ == _FPCLASS_NN || class_ == _FPCLASS_PN; |
| 41 | } |
| 42 | |
| 43 | _LIBCPP_ALWAYS_INLINE bool isgreater( double x, double y ) |
| 44 | { |
| 45 | if(_fpclass(x) == _FPCLASS_SNAN || _fpclass(y) == _FPCLASS_SNAN) return false; |
| 46 | else return x > y; |
| 47 | } |
| 48 | |
| 49 | _LIBCPP_ALWAYS_INLINE bool isgreaterequal( double x, double y ) |
| 50 | { |
| 51 | if(_fpclass(x) == _FPCLASS_SNAN || _fpclass(y) == _FPCLASS_SNAN) return false; |
| 52 | else return x >= y; |
| 53 | } |
| 54 | |
| 55 | _LIBCPP_ALWAYS_INLINE bool isless( double x, double y ) |
| 56 | { |
| 57 | if(_fpclass(x) == _FPCLASS_SNAN || _fpclass(y) == _FPCLASS_SNAN) return false; |
| 58 | else return x < y; |
| 59 | } |
| 60 | |
| 61 | _LIBCPP_ALWAYS_INLINE bool islessequal( double x, double y ) |
| 62 | { |
| 63 | if(::_fpclass(x) == _FPCLASS_SNAN || ::_fpclass(y) == _FPCLASS_SNAN) return false; |
| 64 | else return x <= y; |
| 65 | } |
| 66 | |
| 67 | _LIBCPP_ALWAYS_INLINE bool islessgreater( double x, double y ) |
| 68 | { |
| 69 | if(::_fpclass(x) == _FPCLASS_SNAN || ::_fpclass(y) == _FPCLASS_SNAN) return false; |
| 70 | else return x < y || x > y; |
| 71 | } |
| 72 | |
| 73 | _LIBCPP_ALWAYS_INLINE bool isunordered( double x, double y ) |
| 74 | { |
| 75 | return isnan(x) || isnan(y); |
| 76 | } |
| 77 | _LIBCPP_ALWAYS_INLINE bool signbit( double num ) |
| 78 | { |
| 79 | switch(_fpclass(num)) |
| 80 | { |
| 81 | case _FPCLASS_SNAN: |
| 82 | case _FPCLASS_QNAN: |
| 83 | case _FPCLASS_NINF: |
| 84 | case _FPCLASS_NN: |
| 85 | case _FPCLASS_ND: |
| 86 | case _FPCLASS_NZ: |
| 87 | return true; |
| 88 | case _FPCLASS_PZ: |
| 89 | case _FPCLASS_PD: |
| 90 | case _FPCLASS_PN: |
| 91 | case _FPCLASS_PINF: |
| 92 | return false; |
| 93 | } |
| 94 | return false; |
| 95 | } |
| 96 | _LIBCPP_ALWAYS_INLINE float copysignf( float x, float y ) |
| 97 | { |
| 98 | return (signbit (x) != signbit (y) ? - x : x); |
| 99 | } |
| 100 | _LIBCPP_ALWAYS_INLINE double copysign( double x, double y ) |
| 101 | { |
| 102 | return ::_copysign(x,y); |
| 103 | } |
| 104 | _LIBCPP_ALWAYS_INLINE double copysignl( long double x, long double y ) |
| 105 | { |
| 106 | return ::_copysignl(x,y); |
| 107 | } |
| 108 | _LIBCPP_ALWAYS_INLINE int fpclassify( double num ) |
| 109 | { |
| 110 | return _fpclass(num); |
| 111 | } |
| 112 | |
Howard Hinnant | 0be8f64 | 2013-08-01 18:17:34 +0000 | [diff] [blame] | 113 | #endif // _LIBCPP_MSVCRT |
Howard Hinnant | 9563a09 | 2011-10-27 16:24:42 +0000 | [diff] [blame] | 114 | |
Bob Wilson | a4fd70e | 2012-02-20 16:56:13 +0000 | [diff] [blame] | 115 | #endif // _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H |