\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 2023 51 Degrees Mobile Experts Limited, Davidson House,
4  * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5  *
6  * This Original Work is licensed under the European Union Public Licence
7  * (EUPL) v.1.2 and is subject to its terms as set out below.
8  *
9  * If a copy of the EUPL was not distributed with this file, You can obtain
10  * one at https://opensource.org/licenses/EUPL-1.2.
11  *
12  * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13  * amended by the European Commission) shall be deemed incompatible for
14  * the purposes of the Work and the provisions of the compatibility
15  * clause in Article 5 of the EUPL shall not apply.
16  *
17  * If using the Work as, or as part of, a network application, by
18  * including the attribution notice(s) required under Article 5 of the EUPL
19  * in the end user terms of the application under an appropriate heading,
20  * such notice(s) shall fulfill the requirements of that article.
21  * ********************************************************************* */
22 
23 #ifndef FIFTYONE_DEGREES_FLOAT_H_INCLUDED
24 #define FIFTYONE_DEGREES_FLOAT_H_INCLUDED
25 
55 #include <stdint.h>
56 #include "data.h"
57 #include "common.h"
58 
62 #define FIFTYONE_DEGREES_FLOAT_BIAS 127
63 
66 #define FIFTYONE_DEGREES_FLOAT_SIZE 4
67 
70 #define FIFTYONE_DEGREES_FLOAT_RADIX 2
71 
74 #define FIFTYONE_DEGREES_FLOAT_SIGN_SIZE 1
75 
78 #define FIFTYONE_DEGREES_FLOAT_EXP_SIZE 8
79 
82 #define FIFTYONE_DEGREES_FLOAT_MANT_SIZE 23
83 
86 #define FIFTYONE_DEGREES_FLOAT_MAX 3.402823466E38f
87 
90 #define FIFTYONE_DEGREES_FLOAT_MIN 1.175494351E-38f
91 
94 #define FIFTYONE_DEGREES_FLOAT_MIN_NEG -3.402823466E38f
95 
99 #define FIFTYONE_DEGREES_FLOAT_EXP_MAX 255
100 
104 #define FIFTYONE_DEGREES_FLOAT_MANT_MAX 8388607
105 
111 typedef struct fiftyone_degrees_float_type {
112  byte value[FIFTYONE_DEGREES_FLOAT_SIZE];
114 
119 typedef union {
121  struct {
122  uint32_t mantissa : FIFTYONE_DEGREES_FLOAT_MANT_SIZE;
123  uint32_t exponent : FIFTYONE_DEGREES_FLOAT_EXP_SIZE;
124  uint32_t sign : FIFTYONE_DEGREES_FLOAT_SIGN_SIZE;
125  } parts;
127 
149 
155 #if _MSC_VER || (FLT_RADIX == 2 && FLT_MANT_DIG == 24 && FLT_MAX_EXP == 128 && FLT_MIN_EXP == -125)
156 
159 typedef float fiftyoneDegreesFloat;
160 
167 #define FIFTYONE_DEGREES_FLOAT_TO_NATIVE(f) f
168 
174 #define FIFTYONE_DEGREES_NATIVE_TO_FLOAT(f) f
175 
181 #define FIFTYONE_DEGREES_FLOAT_IS_EQUAL(f1, f2) (f1 == f2 ? 0 : 1)
182 #else
183 
194 #define FIFTYONE_DEGREES_FLOAT_TO_NATIVE(f) fiftyoneDegreesFloatToNative(f)
195 
201 #define FIFTYONE_DEGREES_NATIVE_TO_FLOAT(f) fiftyoneDegreesNativeToFloat(f)
202 
208 #define FIFTYONE_DEGREES_FLOAT_IS_EQUAL(f1, f2) fiftyoneDegreesFloatIsEqual(f1, f2)
209 #endif
210 
215 #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:74
#define FIFTYONE_DEGREES_FLOAT_MANT_SIZE
IEEE single precision floating point number of bits for mantissa.
Definition: float.h:82
fiftyoneDegreesFloatInternal fiftyoneDegreesFloat
For some compilers such as clang and Microsoft C or computers where the IEEE single precision standar...
Definition: float.h:187
#define FIFTYONE_DEGREES_FLOAT_EXP_SIZE
IEEE single precision floating point number of bits for exponent.
Definition: float.h:78
Struture that represents 51Degrees implementation, which encapsulate an array of 4 bytes.
Definition: float.h:111
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:119
#define FIFTYONE_DEGREES_FLOAT_SIZE
IEEE single precision floating point number of bytes.
Definition: float.h:66
int fiftyoneDegreesFloatIsEqual(fiftyoneDegreesFloatInternal f1, fiftyoneDegreesFloatInternal f2)
Function that compare if two 51Degrees float values are equal.