| 1 | /* |
| 2 | * Common Float Helpers |
| 3 | * |
| 4 | * Copyright (c) 2019, 2024 Linaro |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 7 | */ |
| 8 | |
| 9 | #include <inttypes.h> |
| 10 | |
| 11 | /* Some hosts do not have support for all of these; not required by ISO C. */ |
| 12 | #ifndef FE_OVERFLOW |
| 13 | #define FE_OVERFLOW 0 |
| 14 | #endif |
| 15 | #ifndef FE_UNDERFLOW |
| 16 | #define FE_UNDERFLOW 0 |
| 17 | #endif |
| 18 | #ifndef FE_DIVBYZERO |
| 19 | #define FE_DIVBYZERO 0 |
| 20 | #endif |
| 21 | #ifndef FE_INEXACT |
| 22 | #define FE_INEXACT 0 |
| 23 | #endif |
| 24 | #ifndef FE_INVALID |
| 25 | #define FE_INVALID 0 |
| 26 | #endif |
| 27 | |
| 28 | /* Number of constants in each table */ |
| 29 | int get_num_f16(void); |
| 30 | int get_num_f32(void); |
| 31 | int get_num_f64(void); |
| 32 | |
| 33 | /* Accessor helpers, overflows will automatically wrap */ |
| 34 | uint16_t get_f16(int i); /* use _Float16 when we can */ |
| 35 | float get_f32(int i); |
| 36 | double get_f64(int i); |
| 37 | |
| 38 | /* Return format strings, free after use */ |
| 39 | char * fmt_f16(uint16_t); |
| 40 | char * fmt_f32(float); |
| 41 | char * fmt_f64(double); |
| 42 | /* exception flags */ |
| 43 | char * fmt_flags(void); |