tesseract  4.0.0-beta.1-59-g2cc4
host.h
Go to the documentation of this file.
1 /******************************************************************************
2  ** Filename: host.h
3  ** Purpose: This is the system independent typedefs and defines
4  ** Author: MN, JG, MD
5  **
6  ** (c) Copyright Hewlett-Packard Company, 1988-1996.
7  ** Licensed under the Apache License, Version 2.0 (the "License");
8  ** you may not use this file except in compliance with the License.
9  ** You may obtain a copy of the License at
10  ** http://www.apache.org/licenses/LICENSE-2.0
11  ** Unless required by applicable law or agreed to in writing, software
12  ** distributed under the License is distributed on an "AS IS" BASIS,
13  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  ** See the License for the specific language governing permissions and
15  ** limitations under the License.
16  */
17 
18 #ifndef TESSERACT_CCUTIL_HOST_H_
19 #define TESSERACT_CCUTIL_HOST_H_
20 
21 #include <limits>
22 #include "platform.h"
23 /* _WIN32 */
24 #ifdef _WIN32
25 #include <windows.h>
26 #undef min
27 #undef max
28 #endif
29 
30 #include <cinttypes> // PRId32, ...
31 #include <cstdint> // int32_t, ...
32 
33 // definitions of portable data types (numbers and characters)
34 typedef float FLOAT32;
35 typedef double FLOAT64;
36 typedef unsigned char BOOL8;
37 
38 #if defined(_WIN32)
39 
40 /* MinGW defines the standard PRI... macros, but MSVS doesn't. */
41 
42 #if !defined(PRId32)
43 #define PRId32 "d"
44 #endif
45 
46 #if !defined(PRId64)
47 #define PRId64 "I64d"
48 #endif
49 
50 #endif /* _WIN32 */
51 
52 #define MAX_FLOAT32 std::numeric_limits<float>::max()
53 
54 // Minimum positive value ie 1e-37ish.
55 #define MIN_FLOAT32 std::numeric_limits<float>::min()
56 
57 // Defines
58 #ifndef TRUE
59 #define TRUE 1
60 #endif
61 
62 #ifndef FALSE
63 #define FALSE 0
64 #endif
65 
66 // Return true if x is within tolerance of y
67 template<class T> bool NearlyEqual(T x, T y, T tolerance) {
68  T diff = x - y;
69  return diff <= tolerance && -diff <= tolerance;
70 }
71 
72 #endif // TESSERACT_CCUTIL_HOST_H_
unsigned char BOOL8
Definition: host.h:36
float FLOAT32
Definition: host.h:34
double FLOAT64
Definition: host.h:35
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:67