\r\n

51Degrees Device Detection C/C++  4.3

A device detection library that is used natively or by 51Degrees products

float.h

1 /* *********************************************************************
2  * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3  * Copyright 2020 51 Degrees Mobile Experts Limited, 5 Charlotte Close,
4  * Caversham, Reading, Berkshire, United Kingdom RG4 7BY.
5  *
6  * This Original Work is the subject of the following patents and patent
7  * applications, owned by 51 Degrees Mobile Experts Limited of 5 Charlotte
8  * Close, Caversham, Reading, Berkshire, United Kingdom RG4 7BY:
9  * European Patent No. 2871816; and
10  * United States Patent Nos. 9,332,086 and 9,350,823.
11  *
12  * This Original Work is licensed under the European Union Public Licence (EUPL)
13  * v.1.2 and is subject to its terms as set out below.
14  *
15  * If a copy of the EUPL was not distributed with this file, You can obtain
16  * one at https://opensource.org/licenses/EUPL-1.2.
17  *
18  * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
19  * amended by the European Commission) shall be deemed incompatible for
20  * the purposes of the Work and the provisions of the compatibility
21  * clause in Article 5 of the EUPL shall not apply.
22  *
23  * If using the Work as, or as part of, a network application, by
24  * including the attribution notice(s) required under Article 5 of the EUPL
25  * in the end user terms of the application under an appropriate heading,
26  * such notice(s) shall fulfill the requirements of that article.
27  * ********************************************************************* */
28 
29 #ifndef FIFTYONE_DEGREES_FLOAT_H_INCLUDED
30 #define FIFTYONE_DEGREES_FLOAT_H_INCLUDED
31 
61 #include <stdint.h>
62 #include "data.h"
63 
64 #ifdef __cplusplus
65 #define EXTERNAL extern "C"
66 #else
67 #define EXTERNAL
68 #endif
69 
73 #define FIFTYONE_DEGREES_FLOAT_BIAS 127
74 
77 #define FIFTYONE_DEGREES_FLOAT_SIZE 4
78 
81 #define FIFTYONE_DEGREES_FLOAT_RADIX 2
82 
85 #define FIFTYONE_DEGREES_FLOAT_SIGN_SIZE 1
86 
89 #define FIFTYONE_DEGREES_FLOAT_EXP_SIZE 8
90 
93 #define FIFTYONE_DEGREES_FLOAT_MANT_SIZE 23
94 
97 #define FIFTYONE_DEGREES_FLOAT_MAX 3.402823466E38f
98 
101 #define FIFTYONE_DEGREES_FLOAT_MIN 1.175494351E-38f
102 
105 #define FIFTYONE_DEGREES_FLOAT_MIN_NEG -3.402823466E38f
106 
110 #define FIFTYONE_DEGREES_FLOAT_EXP_MAX 255
111 
115 #define FIFTYONE_DEGREES_FLOAT_MANT_MAX 8388607
116 
122 typedef struct fiftyone_degrees_float_type {
123  byte value[FIFTYONE_DEGREES_FLOAT_SIZE];
125 
130 typedef union {
132  struct {
133  uint32_t mantissa : FIFTYONE_DEGREES_FLOAT_MANT_SIZE;
134  uint32_t exponent : FIFTYONE_DEGREES_FLOAT_EXP_SIZE;
135  uint32_t sign : FIFTYONE_DEGREES_FLOAT_SIGN_SIZE;
136  } parts;
138 
160 
166 #if _MSC_VER || (FLT_RADIX == 2 && FLT_MANT_DIG == 24 && FLT_MAX_EXP == 128 && FLT_MIN_EXP == -125)
167 
170 typedef float fiftyoneDegreesFloat;
171 
178 #define FIFTYONE_DEGREES_FLOAT_TO_NATIVE(f) f
179 
185 #define FIFTYONE_DEGREES_NATIVE_TO_FLOAT(f) f
186 
192 #define FIFTYONE_DEGREES_FLOAT_IS_EQUAL(f1, f2) (f1 == f2 ? 0 : 1)
193 #else
194 
205 #define FIFTYONE_DEGREES_FLOAT_TO_NATIVE(f) fiftyoneDegreesFloatToNative(f)
206 
212 #define FIFTYONE_DEGREES_NATIVE_TO_FLOAT(f) fiftyoneDegreesNativeToFloat(f)
213 
219 #define FIFTYONE_DEGREES_FLOAT_IS_EQUAL(f1, f2) fiftyoneDegreesFloatIsEqual(f1, f2)
220 #endif
221 
226 #endif
fiftyoneDegreesFloatInternal fiftyoneDegreesNativeToFloat(float f)
Function that converts from a native float value to 51Degrees float value.
#define FIFTYONE_DEGREES_FLOAT_SIGN_SIZE
IEEE single precision floating point number of bits for sgn.
Definition: float.h:85
#define FIFTYONE_DEGREES_FLOAT_MANT_SIZE
IEEE single precision floating point number of bits for mantissa.
Definition: float.h:93
fiftyoneDegreesFloatInternal fiftyoneDegreesFloat
For some compilers such as clang and Microsoft C or computers where the IEEE single precision standar...
Definition: float.h:198
#define FIFTYONE_DEGREES_FLOAT_EXP_SIZE
IEEE single precision floating point number of bits for exponent.
Definition: float.h:89
Struture that represents 51Degrees implementation, which encapsulate an array of 4 bytes.
Definition: float.h:122
float fiftyoneDegreesFloatToNative(fiftyoneDegreesFloatInternal f)
Function that converts from a 51Degrees float implementation to a native float value.
Union that breaks down 51Degrees implementation to its components: sign, exponent and mantissa.
Definition: float.h:130
#define FIFTYONE_DEGREES_FLOAT_SIZE
IEEE single precision floating point number of bytes.
Definition: float.h:77
int fiftyoneDegreesFloatIsEqual(fiftyoneDegreesFloatInternal f1, fiftyoneDegreesFloatInternal f2)
Function that compare if two 51Degrees float values are equal.