|
OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
|
IEEE 754 half-precision (float16) conversion utilities. More...
Go to the source code of this file.
Macros | |
| #define | FLOAT16_POSITIVE_ZERO 0x0000 |
| float16 value representing positive zero (forward, stopped). | |
| #define | FLOAT16_NEGATIVE_ZERO 0x8000 |
| float16 value representing negative zero (reverse, stopped). | |
| #define | FLOAT16_NAN 0x7E00 |
| float16 NaN value (speed not available). | |
| #define | FLOAT16_SIGN_MASK 0x8000 |
| Bit mask for the sign/direction bit (bit 15). | |
| #define | FLOAT16_EXPONENT_MASK 0x7C00 |
| Bit mask for the 5-bit exponent field (bits 14-10). | |
| #define | FLOAT16_MANTISSA_MASK 0x03FF |
| Bit mask for the 10-bit mantissa field (bits 9-0). | |
Functions | |
| uint16_t | OpenLcbFloat16_from_float (float value) |
| Converts a 32-bit float to a float16 bit pattern. | |
| float | OpenLcbFloat16_to_float (uint16_t half) |
| Converts a float16 bit pattern to a 32-bit float. | |
| uint16_t | OpenLcbFloat16_negate (uint16_t half) |
| Flips the sign/direction bit of a float16 value and returns the result. | |
| bool | OpenLcbFloat16_is_nan (uint16_t half) |
| Returns true if the float16 bit pattern represents NaN (speed not available). | |
| bool | OpenLcbFloat16_is_zero (uint16_t half) |
| Returns true if the float16 bit pattern represents positive or negative zero. | |
| uint16_t | OpenLcbFloat16_speed_with_direction (float speed, bool reverse) |
| Encodes a speed magnitude and direction into a float16 bit pattern. | |
| float | OpenLcbFloat16_get_speed (uint16_t half) |
| Returns the speed magnitude from a float16 bit pattern (ignores direction). | |
| bool | OpenLcbFloat16_get_direction (uint16_t half) |
| Returns true if the direction bit is set (reverse). | |
IEEE 754 half-precision (float16) conversion utilities.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Encodes/decodes OpenLCB train speed as binary16. Sign bit = direction (0 forward, 1 reverse). All conversions use integer-only bit manipulation for embedded targets.
| #define FLOAT16_POSITIVE_ZERO 0x0000 |
float16 value representing positive zero (forward, stopped).
| #define FLOAT16_NEGATIVE_ZERO 0x8000 |
float16 value representing negative zero (reverse, stopped).
| #define FLOAT16_NAN 0x7E00 |
float16 NaN value (speed not available).
| #define FLOAT16_SIGN_MASK 0x8000 |
Bit mask for the sign/direction bit (bit 15).
| #define FLOAT16_EXPONENT_MASK 0x7C00 |
Bit mask for the 5-bit exponent field (bits 14-10).
| #define FLOAT16_MANTISSA_MASK 0x03FF |
Bit mask for the 10-bit mantissa field (bits 9-0).
|
extern |
Converts a 32-bit float to a float16 bit pattern.
Rounds toward zero. Overflow is clamped. NaN produces FLOAT16_NAN.
| value | 32-bit float to convert. |
Algorithm:
* @param value 32-bit float to convert *
|
extern |
Converts a float16 bit pattern to a 32-bit float.
| half | 16-bit float16 bit pattern to convert. |
Algorithm:
* @param half 16-bit float16 bit pattern *
|
extern |
Flips the sign/direction bit of a float16 value and returns the result.
| half | 16-bit float16 bit pattern to negate. |
Flips the sign/direction bit of a float16 value and returns the result.
|
extern |
Returns true if the float16 bit pattern represents NaN (speed not available).
| half | 16-bit float16 bit pattern to test. |
Returns true if the float16 bit pattern represents NaN (speed not available).
|
extern |
Returns true if the float16 bit pattern represents positive or negative zero.
| half | 16-bit float16 bit pattern to test. |
|
extern |
Encodes a speed magnitude and direction into a float16 bit pattern.
| speed | Speed magnitude as a 32-bit float. |
| reverse | true for reverse direction, false for forward. |
|
extern |
Returns the speed magnitude from a float16 bit pattern (ignores direction).
| half | 16-bit float16 bit pattern to decode. |
|
extern |
Returns true if the direction bit is set (reverse).
| half | 16-bit float16 bit pattern to test. |
Copyright (c) 2026 Jim Kueneman all rights reserved. See the License