Home | History | Annotate | Download | only in win32
      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 
     21 // Necessary?
     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 
    113 #endif // _LIBCPP_MSVCRT
    114 
    115 #endif // _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H
    116