KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
float.h
Go to the documentation of this file.
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2013 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : float.h
11  * Created : 11 apr. 2014
12  * Author : Vincent van Beveren
13  */
14 
15 #ifndef FLOAT_H_
16 #define FLOAT_H_
17 
18 #include <stdint.h>
19 #include <stdbool.h>
20 
21 /**
22  * @file
23  *
24  * @ingroup util
25  *
26  * Special library for primitive IEEE 754 floating point handling without dragging all float support along.
27  */
28 
29 /** 32 bit representation for float. */
30 typedef uint32_t f32_t;
31 
32 /** 642 bit representation for float */
33 typedef uint64_t f64_t;
34 
35 /**
36  * This takes a f32_t IEEE 754 single precision floating point, and converts it to a multiplied
37  * integer. E.g. if you supply 3.75 with multiplier 100 the resulting integer will be 375.
38  *
39  * @note Rounding has not yet been applied.
40  *
41  * @param value The floating point value
42  * @param multiplier The value to multiply with before chopping of the decimal part
43  * @param applySign Whether or not to apply the sign.
44  * @return The integer representing the floating point value.
45  */
46 int32_t fltToI32(f32_t value, uint32_t multiplier);
47 
48 /**
49  * Returns the fractional part of the floating point with the specified number of decimals.
50  *
51  * @param value
52  * @param decimals
53  * @return
54  */
55 uint32_t fltFrac(f32_t value, int decimals);
56 
57 /**
58  * Returns the integer part of the floating point value.
59  *
60  * @param value
61  * @return
62  */
63 int32_t fltInt(f32_t value);
64 
65 #define FLT2DU(VAL, DEC) fltInt(VAL), fltFrac(VAL, DEC)
66 
67 
68 /**
69  * Takes an integer value and converts it to a float.
70  *
71  * @param value The value
72  * @param scaling The number of fractional bits
73  * @return A float
74  */
75 f32_t fltFromI16(int16_t val, int fBits);
76 
77 
78 
79 /*
80 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
81 */
82 ///**
83 // * Cast a U32 to a float, without converting it.
84 // *
85 // * @param f Input value
86 // * @return Output value
87 // */
88 //static inline float castU32ToFloat(uint32_t f) {
89 // void * v = &f;
90 // return *((float *)v);
91 //}
92 //
93 //static inline uint32_t castFloatToU32(float f) {
94 // void * v = &f;
95 // return *((uint32_t *)v);
96 //}
97 //
98 //
99 
100 #endif /* FLOAT_H_ */
int32_t fltInt(f32_t value)
Returns the integer part of the floating point value.
Definition: float.c:102
uint32_t fltFrac(f32_t value, int decimals)
Returns the fractional part of the floating point with the specified number of decimals.
Definition: float.c:96
uint32_t f32_t
32 bit representation for float.
Definition: float.h:30
uint64_t f64_t
642 bit representation for float
Definition: float.h:33
f32_t fltFromI16(int16_t val, int fBits)
Takes an integer value and converts it to a float.
Definition: float.c:122
int32_t fltToI32(f32_t value, uint32_t multiplier)
This takes a f32_t IEEE 754 single precision floating point, and converts it to a multiplied integer...
Definition: float.c:90