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 2026 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
26#ifdef FIFTYONE_DEGREES_IPI_SYMBOLS
27#include "ipiSymbols.h"
28#endif
29
58
59#include <stdint.h>
60#include "data.h"
61#include "common.h"
62
66#define FIFTYONE_DEGREES_FLOAT_BIAS 127
70#define FIFTYONE_DEGREES_FLOAT_SIZE 4
74#define FIFTYONE_DEGREES_FLOAT_RADIX 2
78#define FIFTYONE_DEGREES_FLOAT_SIGN_SIZE 1
82#define FIFTYONE_DEGREES_FLOAT_EXP_SIZE 8
86#define FIFTYONE_DEGREES_FLOAT_MANT_SIZE 23
90#define FIFTYONE_DEGREES_FLOAT_MAX 3.402823466E38f
94#define FIFTYONE_DEGREES_FLOAT_MIN 1.175494351E-38f
98#define FIFTYONE_DEGREES_FLOAT_MIN_NEG -3.402823466E38f
103#define FIFTYONE_DEGREES_FLOAT_EXP_MAX 255
108#define FIFTYONE_DEGREES_FLOAT_MANT_MAX 8388607
109
115typedef struct fiftyone_degrees_float_type {
116 byte value[FIFTYONE_DEGREES_FLOAT_SIZE];
118
123typedef union {
125 struct {
126 uint32_t mantissa : FIFTYONE_DEGREES_FLOAT_MANT_SIZE;
127 uint32_t exponent : FIFTYONE_DEGREES_FLOAT_EXP_SIZE;
128 uint32_t sign : FIFTYONE_DEGREES_FLOAT_SIGN_SIZE;
129 } parts;
131
153
159#if _MSC_VER || (FLT_RADIX == 2 && FLT_MANT_DIG == 24 && FLT_MAX_EXP == 128 && FLT_MIN_EXP == -125)
163typedef float fiftyoneDegreesFloat;
164
171#define FIFTYONE_DEGREES_FLOAT_TO_NATIVE(f) f
178#define FIFTYONE_DEGREES_NATIVE_TO_FLOAT(f) f
185#define FIFTYONE_DEGREES_FLOAT_IS_EQUAL(f1, f2) (f1 == f2 ? 0 : 1)
186#else
198#define FIFTYONE_DEGREES_FLOAT_TO_NATIVE(f) fiftyoneDegreesFloatToNative(f)
205#define FIFTYONE_DEGREES_NATIVE_TO_FLOAT(f) fiftyoneDegreesNativeToFloat(f)
212#define FIFTYONE_DEGREES_FLOAT_IS_EQUAL(f1, f2) fiftyoneDegreesFloatIsEqual(f1, f2)
213#endif
214
218
219#endif
float fiftyoneDegreesFloatToNative(fiftyoneDegreesFloatInternal f)
Function that converts from a 51Degrees float implementation to a native float value.
#define FIFTYONE_DEGREES_FLOAT_MANT_SIZE
IEEE single precision floating point number of bits for mantissa.
Definition float.h:86
fiftyoneDegreesFloatInternal fiftyoneDegreesFloat
For some compilers such as clang and Microsoft C or computers where the IEEE single precision standar...
Definition float.h:191
int fiftyoneDegreesFloatIsEqual(fiftyoneDegreesFloatInternal f1, fiftyoneDegreesFloatInternal f2)
Function that compare if two 51Degrees float values are equal.
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:78
#define FIFTYONE_DEGREES_FLOAT_EXP_SIZE
IEEE single precision floating point number of bits for exponent.
Definition float.h:82
#define FIFTYONE_DEGREES_FLOAT_SIZE
IEEE single precision floating point number of bytes.
Definition float.h:70
Struture that represents 51Degrees implementation, which encapsulate an array of 4 bytes.
Definition float.h:115
Union that breaks down 51Degrees implementation to its components: sign, exponent and mantissa.
Definition float.h:123