1 /* 2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef _PICO_FLOAT_H 8 #define _PICO_FLOAT_H 9 10 #include <math.h> 11 #include <float.h> 12 #include "pico.h" 13 #include "pico/bootrom/sf_table.h" 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 /** \file float.h 20 * \defgroup pico_float pico_float 21 * 22 * \brief Optimized single-precision floating point functions 23 * 24 * (Replacement) optimized implementations are provided for the following compiler built-ins 25 * and math library functions on Arm: 26 * 27 * - __aeabi_fadd, __aeabi_fdiv, __aeabi_fmul, __aeabi_frsub, __aeabi_fsub, __aeabi_cfcmpeq, __aeabi_cfrcmple, __aeabi_cfcmple, __aeabi_fcmpeq, __aeabi_fcmplt, __aeabi_fcmple, __aeabi_fcmpge, __aeabi_fcmpgt, __aeabi_fcmpun, __aeabi_i2f, __aeabi_l2f, __aeabi_ui2f, __aeabi_ul2f, __aeabi_f2iz, __aeabi_f2lz, __aeabi_f2uiz, __aeabi_f2ulz, __aeabi_f2d, sqrtf, cosf, sinf, tanf, atan2f, expf, logf 28 * - ldexpf, copysignf, truncf, floorf, ceilf, roundf, asinf, acosf, atanf, sinhf, coshf, tanhf, asinhf, acoshf, atanhf, exp2f, log2f, exp10f, log10f, powf, hypotf, cbrtf, fmodf, dremf, remainderf, remquof, expm1f, log1pf, fmaf 29 * - powintf, sincosf (GNU extensions) 30 * 31 * The following additional optimized functions are also provided: 32 * 33 * - int2float, uint2float, int642float, uint642float, fix2float, ufix2float, fix642float, ufix642float 34 * - float2fix, float2ufix, float2fix64, float2ufix64, float2int, float2uint, float2int64, float2uint64, float2int_z, float2int64_z, float2uint_z, float2uint64_z 35 * - exp10f, sincosf, powintf 36 * 37 * On RP2350 (Arm) the following additional functions are available; the _fast methods are faster but do not round correctly 38 * 39 * - float2fix64_z, fdiv_fast, fsqrt_fast, 40 * 41 * On RP2350 RISC-V, only a small number of compiler runtime functions are overridden with faster implementations: 42 * 43 * - __addsf3, __subsf3, __mulsf3 44 */ 45 46 // None of these functions are available on RISC-V: 47 #if !defined(__riscv) || PICO_COMBINED_DOCS 48 49 float int2float(int32_t f); 50 float uint2float(uint32_t f); 51 float int642float(int64_t f); 52 float uint642float(uint64_t f); 53 float fix2float(int32_t m, int e); 54 float ufix2float(uint32_t m, int e); 55 float fix642float(int64_t m, int e); 56 float ufix642float(uint64_t m, int e); 57 58 // These methods round towards -Infinity. 59 int32_t float2fix(float f, int e); 60 uint32_t float2ufix(float f, int e); 61 int64_t float2fix64(float f, int e); 62 uint64_t float2ufix64(float f, int e); 63 int32_t float2int(float f); 64 uint32_t float2uint(float f); 65 int64_t float2int64(float f); 66 uint64_t float2uint64(float f); 67 68 // These methods round towards 0. 69 int32_t float2int_z(float f); 70 int64_t float2int64_z(float f); 71 int32_t float2uint_z(float f); 72 int64_t float2uint64_z(float f); 73 74 float exp10f(float x); 75 void sincosf(float x, float *sinx, float *cosx); 76 float powintf(float x, int y); 77 78 #if !PICO_RP2040 || PICO_COMBINED_DOCS 79 int64_t float2fix64_z(float f, int e); 80 float fdiv_fast(float n, float d); 81 float fsqrt_fast(float f); 82 #endif 83 84 #endif 85 86 #ifdef __cplusplus 87 } 88 #endif 89 90 #endif 91