File: math.cc

package info (click to toggle)
dcmtk 3.6.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 54,900 kB
  • sloc: cpp: 274,805; ansic: 47,345; makefile: 5,313; sh: 4,250; perl: 277; xml: 182; lex: 103
file content (129 lines) | stat: -rw-r--r-- 2,624 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 *
 *  Copyright (C) 2015-2016, OFFIS e.V.
 *  All rights reserved.  See COPYRIGHT file for details.
 *
 *  This software and supporting documentation were developed by
 *
 *    OFFIS e.V.
 *    R&D Division Health
 *    Escherweg 2
 *    D-26121 Oldenburg, Germany
 *
 *
 *  Module:  ofstd
 *
 *  Author:  Jan Schlamelcher
 *
 *  Purpose: Platform independent definition of basic functions declared
 *           in <math.h> resp. <cmath>.
 *
 */


#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */

#define INCLUDE_CMATH
#define INCLUDE_CFLOAT
#define INCLUDE_IOSTREAM
#include "dcmtk/ofstd/ofstdinc.h"
#include "dcmtk/ofstd/oftypes.h"

#ifdef HAVE_WINDOWS_H
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif

/* Some MacOS X versions define isinf() and isnan() in <math.h> but not in <cmath> */
#if defined(__APPLE__) && defined(__MACH__) && !defined (__INTEL_COMPILER)
#undef HAVE_PROTOTYPE_ISINF
#undef HAVE_PROTOTYPE_ISNAN
#endif


// some systems don't properly define isnan()
#ifdef HAVE_ISNAN
#ifndef HAVE_PROTOTYPE_ISNAN
extern "C"
{
  int isnan(double value);
}
#endif
#endif


// some systems don't properly define finite()
#ifdef HAVE_FINITE
#ifndef HAVE_PROTOTYPE_FINITE
extern "C"
{
  int finite(double value);
}
#endif
#endif

#if !defined(HAVE_ISINF) && defined(HAVE_PROTOTYPE_ISINF)
#   define HAVE_ISINF 1
#endif

// some systems don't properly define isinf()
#ifdef HAVE_ISINF
#ifndef HAVE_PROTOTYPE_ISINF
extern "C"
{
  int isinf(double value);
}
#endif
#endif /* HAVE_ISINF */

struct dcmtk_config_math
{
  static inline OFBool isnan( float f )
  {
#ifdef HAVE_WINDOWS_H
    return _isnan(f) != 0;
#elif defined(HAVE_PROTOTYPE_STD__ISNAN)
    return STD_NAMESPACE isnan(f);
#else
    return ::isnan(f);
#endif
  }

  static inline OFBool isnan( double d )
  {
#ifdef HAVE_WINDOWS_H
    return _isnan(d) != 0;
#elif defined(HAVE_PROTOTYPE_STD__ISNAN)
    return STD_NAMESPACE isnan(d);
#else
    return ::isnan(d);
#endif
  }

  static inline OFBool isinf( float f )
  {
#ifdef HAVE_PROTOTYPE_STD__ISINF
    return STD_NAMESPACE isinf( f );
#elif defined(HAVE_ISINF)
    return ::isinf( f );
#else
    return dcmtk_config_math::isinf( OFstatic_cast( double, f ) );
#endif
  }

  static inline OFBool isinf( double d )
  {
#ifdef HAVE_PROTOTYPE_STD__ISINF
    return STD_NAMESPACE isinf( d );
#elif defined(HAVE_ISINF)
    return ::isinf( d );
#else
#ifdef HAVE_WINDOWS_H
    return (! _finite(d)) && (! _isnan(d));
#else
    // Solaris 2.5.1 has finite() and isnan() but not isinf().
    return (! finite(d)) && (! isnan(d));
#endif
#endif
  }
};