OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
Loading...
Searching...
No Matches
openlcb_float16.h
Go to the documentation of this file.
1
38#ifndef __OPENLCB_FLOAT16__
39#define __OPENLCB_FLOAT16__
40
41#include <stdbool.h>
42#include <stdint.h>
43
44#ifdef __cplusplus
45 extern "C" {
46#endif /* __cplusplus */
47
49#define FLOAT16_POSITIVE_ZERO 0x0000
50
52#define FLOAT16_NEGATIVE_ZERO 0x8000
53
55#define FLOAT16_NAN 0x7E00
56
58#define FLOAT16_SIGN_MASK 0x8000
59
61#define FLOAT16_EXPONENT_MASK 0x7C00
62
64#define FLOAT16_MANTISSA_MASK 0x03FF
65
75 extern uint16_t OpenLcbFloat16_from_float(float value);
76
84 extern float OpenLcbFloat16_to_float(uint16_t half);
85
93 extern uint16_t OpenLcbFloat16_negate(uint16_t half);
94
102 extern bool OpenLcbFloat16_is_nan(uint16_t half);
103
111 extern bool OpenLcbFloat16_is_zero(uint16_t half);
112
121 extern uint16_t OpenLcbFloat16_speed_with_direction(float speed, bool reverse);
122
130 extern float OpenLcbFloat16_get_speed(uint16_t half);
131
139 extern bool OpenLcbFloat16_get_direction(uint16_t half);
140
141#ifdef __cplusplus
142}
143#endif /* __cplusplus */
144
145#endif /* __OPENLCB_FLOAT16__ */
bool OpenLcbFloat16_get_direction(uint16_t half)
Returns true if the direction bit is set (reverse).
Definition openlcb_float16.c:281
uint16_t OpenLcbFloat16_negate(uint16_t half)
Flips the sign/direction bit of a float16 value and returns the result.
Definition openlcb_float16.c:217
uint16_t OpenLcbFloat16_from_float(float value)
Converts a 32-bit float to a float16 bit pattern.
Definition openlcb_float16.c:83
float OpenLcbFloat16_to_float(uint16_t half)
Converts a float16 bit pattern to a 32-bit float.
Definition openlcb_float16.c:163
float OpenLcbFloat16_get_speed(uint16_t half)
Returns the speed magnitude from a float16 bit pattern (ignores direction).
Definition openlcb_float16.c:270
bool OpenLcbFloat16_is_nan(uint16_t half)
Returns true if the float16 bit pattern represents NaN (speed not available).
Definition openlcb_float16.c:225
bool OpenLcbFloat16_is_zero(uint16_t half)
Returns true if the float16 bit pattern represents positive or negative zero.
Definition openlcb_float16.c:236
uint16_t OpenLcbFloat16_speed_with_direction(float speed, bool reverse)
Encodes a speed magnitude and direction into a float16 bit pattern.
Definition openlcb_float16.c:244

Copyright (c) 2026 Jim Kueneman all rights reserved. See the License