-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloat8.h
More file actions
56 lines (48 loc) · 1.63 KB
/
float8.h
File metadata and controls
56 lines (48 loc) · 1.63 KB
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
#ifndef FLOAT8_H
#define FLOAT8_H
#include <stdint.h>
/***********************************************************
* The number of bits used to represent the float8 exponent.
***********************************************************/
#define EXPONENT_BITS 4
/*
* This is the 8-bit minifloat representation.
* The float8_t struct is used to represent a float8 number.
* Bitfields used to limit the size of the float8_t struct to 8 bits.
*
* CAUTION: Need to take care of the target system's endianness.
*/
typedef struct {
uint8_t fraction : 7 - EXPONENT_BITS;
uint8_t exponent : EXPONENT_BITS;
uint8_t sign : 1;
} float8_t;
/* Convert a number from single-precision floating point
* number to 8-bit minifloat (float8_t) number.
*
* @param f: single-precision floating point number to be converted
* @return: 8-bit minifloat (float8_t) number
*/
float8_t float_to_float8(float f);
/* Convert a number from 8-bit minifloat (float8_t) number
* to single-precision floating point number.
*
* @param f8: 8-bit minifloat (float8_t) number to be converted
* @return: single-precision floating point number
*/
float float8_to_float(float8_t f8);
/* Convert an unsigned char to a float8_t.
* WARNING: type punning violates the strict aliasing rule.
*
* @param c: unsigned char to be converted
* @return: 8-bit minifloat (float8_t) number
*/
float8_t uchar_to_float8(unsigned char c);
/* Convert a float8_t to an unsigned char.
* WARNING: type punning violates the strict aliasing rule.
*
* @param f8: 8-bit minifloat (float8_t) number to be converted
* @return: unsigned char
*/
unsigned char float8_to_uchar(float8_t f8);
#endif