forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsfloat.h
71 lines (57 loc) · 1.41 KB
/
sfloat.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#ifndef SFLOAT_H_
#define SFLOAT_H_
#include <stdint.h>
#include <zephyr/types.h>
/**
* @file
* @defgroup sfloat Short float (SFLOAT) type.
* @{
*
* @brief API for short float (SFLOAT) type from the IEEE 11073-20601-2008
* specification.
*/
#ifdef __cplusplus
extern "C" {
#endif
/** @brief SFLOAT special values. */
enum sfloat_special {
/** Not a number. */
SFLOAT_NAN = 0x07FF,
/** Not at this resolution. */
SFLOAT_NRES = 0x0800,
/** Positive infinity. */
SFLOAT_POS_INFINITY = 0x07FE,
/** Negative infinity. */
SFLOAT_NEG_INFINITY = 0x0802,
/** Reserved for future use. */
SFLOAT_RESERVED = 0x0801,
};
/** @brief SFLOAT type. */
struct sfloat {
/* SFLOAT type encoded as 16-bit word that consists of the following fields:
* 1. Exponent, encoded as 4-bit integer in two's-complement form.
* 2. Mantissa, encoded as 12-bit integer in two's-complement form.
*/
uint16_t val;
};
/**
* @brief Convert the standard float type into SFLOAT type.
*
* @param[in] float_num Number encoded as a standard float type
* (binary32 notation from the IEEE 754-2008 specification).
*
* @return SFLOAT type (from the IEEE 11073-20601-2008 specification).
*/
struct sfloat sfloat_from_float(float float_num);
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* SFLOAT_H_ */