Overte C++ Documentation
NumericalConstants.h
1 //
2 // NumericalConstants.h
3 // libraries/shared/src
4 //
5 // Created by Stephen Birarda on 05/01/15.
6 // Copyright 2015 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_NumericalConstants_h
13 #define hifi_NumericalConstants_h
14 
15 #pragma once
16 
17 #include <cmath>
18 
19 #include <QtGlobal>
20 
21 const float PI = 3.14159265358979f;
22 const float TWO_PI = 2.0f * PI;
23 const float PI_OVER_TWO = 0.5f * PI;
24 const float RADIANS_PER_DEGREE = PI / 180.0f;
25 const float DEGREES_PER_RADIAN = 180.0f / PI;
26 const float ARCMINUTES_PER_DEGREE = 60.0f;
27 const float ARCSECONDS_PER_ARCMINUTE = 60.0f;
28 const float ARCSECONDS_PER_DEGREE = ARCMINUTES_PER_DEGREE * ARCSECONDS_PER_ARCMINUTE;
29 
30 const float EPSILON = 0.000001f; //smallish positive number - used as margin of error for some computations
31 const float SQUARE_ROOT_OF_2 = 1.414214f;
32 const float SQUARE_ROOT_OF_3 = 1.732051f;
33 const float METERS_PER_DECIMETER = 0.1f;
34 const float METERS_PER_CENTIMETER = 0.01f;
35 const float METERS_PER_MILLIMETER = 0.001f;
36 const float MILLIMETERS_PER_METER = 1000.0f;
37 const quint64 NSECS_PER_USEC = 1000;
38 const quint64 NSECS_PER_MSEC = 1000000;
39 const quint64 NSECS_PER_SECOND = 1e9;
40 const quint64 USECS_PER_MSEC = 1000;
41 const quint64 MSECS_PER_SECOND = 1000;
42 const quint64 USECS_PER_SECOND = USECS_PER_MSEC * MSECS_PER_SECOND;
43 const quint64 SECS_PER_MINUTE = 60;
44 const quint64 MINS_PER_HOUR = 60;
45 const quint64 SECS_PER_HOUR = SECS_PER_MINUTE * MINS_PER_HOUR;
46 
47 const int BITS_IN_BYTE = 8;
48 const int BYTES_PER_KILOBYTE = 1000;
49 const int BYTES_PER_KILOBIT = BYTES_PER_KILOBYTE / BITS_IN_BYTE;
50 const int KILO_PER_MEGA = 1000;
51 
52 const float SQRT_THREE = 1.73205080f;
53 
54 #define KB_TO_BYTES_SHIFT 10
55 #define MB_TO_BYTES_SHIFT 20
56 #define GB_TO_BYTES_SHIFT 30
57 
58 #define GB_TO_BYTES(X) ((size_t)(X) << GB_TO_BYTES_SHIFT)
59 #define MB_TO_BYTES(X) ((size_t)(X) << MB_TO_BYTES_SHIFT)
60 #define KB_TO_BYTES(X) ((size_t)(X) << KB_TO_BYTES_SHIFT)
61 
62 #define BYTES_TO_GB(X) (X >> GB_TO_BYTES_SHIFT)
63 #define BYTES_TO_MB(X) (X >> MB_TO_BYTES_SHIFT)
64 #define BYTES_TO_KB(X) (X >> KB_TO_BYTES_SHIFT)
65 
66 #endif // hifi_NumericalConstants_h