\r\n

51Degrees Device Detection C/C++  4.4

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 #include "common.h"
64 
68 #define FIFTYONE_DEGREES_FLOAT_BIAS 127
69 
72 #define FIFTYONE_DEGREES_FLOAT_SIZE 4
73 
76 #define FIFTYONE_DEGREES_FLOAT_RADIX 2
77 
80 #define FIFTYONE_DEGREES_FLOAT_SIGN_SIZE 1
81 
84 #define FIFTYONE_DEGREES_FLOAT_EXP_SIZE 8
85 
88 #define FIFTYONE_DEGREES_FLOAT_MANT_SIZE 23
89 
92 #define FIFTYONE_DEGREES_FLOAT_MAX 3.402823466E38f
93 
96 #define FIFTYONE_DEGREES_FLOAT_MIN 1.175494351E-38f
97 
100 #define FIFTYONE_DEGREES_FLOAT_MIN_NEG -3.402823466E38f
101 
105 #define FIFTYONE_DEGREES_FLOAT_EXP_MAX 255
106 
110 #define FIFTYONE_DEGREES_FLOAT_MANT_MAX 8388607
111 
117 typedef struct fiftyone_degrees_float_type {
118  byte value[FIFTYONE_DEGREES_FLOAT_SIZE];
120 
125 typedef union {
127  struct {
128  uint32_t mantissa : FIFTYONE_DEGREES_FLOAT_MANT_SIZE;
129  uint32_t exponent : FIFTYONE_DEGREES_FLOAT_EXP_SIZE;
130  uint32_t sign : FIFTYONE_DEGREES_FLOAT_SIGN_SIZE;
131  } parts;
133 
155 
161 #if _MSC_VER || (FLT_RADIX == 2 && FLT_MANT_DIG == 24 && FLT_MAX_EXP == 128 && FLT_MIN_EXP == -125)
162 
165 typedef float fiftyoneDegreesFloat;
166 
173 #define FIFTYONE_DEGREES_FLOAT_TO_NATIVE(f) f
174 
180 #define FIFTYONE_DEGREES_NATIVE_TO_FLOAT(f) f
181 
187 #define FIFTYONE_DEGREES_FLOAT_IS_EQUAL(f1, f2) (f1 == f2 ? 0 : 1)
188 #else
189 
200 #define FIFTYONE_DEGREES_FLOAT_TO_NATIVE(f) fiftyoneDegreesFloatToNative(f)
201 
207 #define FIFTYONE_DEGREES_NATIVE_TO_FLOAT(f) fiftyoneDegreesNativeToFloat(f)
208 
214 #define FIFTYONE_DEGREES_FLOAT_IS_EQUAL(f1, f2) fiftyoneDegreesFloatIsEqual(f1, f2)
215 #endif
216 
221 #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:80
#define FIFTYONE_DEGREES_FLOAT_MANT_SIZE
IEEE single precision floating point number of bits for mantissa.
Definition: float.h:88
fiftyoneDegreesFloatInternal fiftyoneDegreesFloat
For some compilers such as clang and Microsoft C or computers where the IEEE single precision standar...
Definition: float.h:193
#define FIFTYONE_DEGREES_FLOAT_EXP_SIZE
IEEE single precision floating point number of bits for exponent.
Definition: float.h:84
Struture that represents 51Degrees implementation, which encapsulate an array of 4 bytes.
Definition: float.h:117
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:125
#define FIFTYONE_DEGREES_FLOAT_SIZE
IEEE single precision floating point number of bytes.
Definition: float.h:72
int fiftyoneDegreesFloatIsEqual(fiftyoneDegreesFloatInternal f1, fiftyoneDegreesFloatInternal f2)
Function that compare if two 51Degrees float values are equal.