1 /* 2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef _PICO_DOUBLE_H 8 #define _PICO_DOUBLE_H 9 10 #include <math.h> 11 #include "pico.h" 12 #include "pico/bootrom/sf_table.h" 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 /** \file double.h 19 * \defgroup pico_double pico_double 20 * 21 * \brief Optimized double-precision floating point functions 22 * 23 * (Replacement) optimized implementations are provided of the following compiler built-ins 24 * and math library functions: 25 * 26 * - __aeabi_dadd, __aeabi_ddiv, __aeabi_dmul, __aeabi_drsub, __aeabi_dsub, __aeabi_cdcmpeq, __aeabi_cdrcmple, __aeabi_cdcmple, __aeabi_dcmpeq, __aeabi_dcmplt, __aeabi_dcmple, __aeabi_dcmpge, __aeabi_dcmpgt, __aeabi_dcmpun, __aeabi_i2d, __aeabi_l2d, __aeabi_ui2d, __aeabi_ul2d, __aeabi_d2iz, __aeabi_d2lz, __aeabi_d2uiz, __aeabi_d2ulz, __aeabi_d2f 27 * - sqrt, cos, sin, tan, atan2, exp, log, ldexp, copysign, trunc, floor, ceil, round, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, exp2, log2, exp10, log10, pow,, hypot, cbrt, fmod, drem, remainder, remquo, expm1, log1p, fma 28 * - powint, sincos (GNU extensions) 29 * 30 * The following additional optimized functions are also provided: 31 * 32 * - int2double, uint2double, int642double, uint642double, fix2double, ufix2double, fix642double, ufix642double 33 * - double2fix, double2ufix, double2fix64, double2ufix64, double2int, double2uint, double2int64, double2uint64, double2int_z, double2int64_z, 34 * - exp10, sincos, powint 35 * 36 * On RP2350 the following additional functions are available; the _fast methods are faster but do not round correctly" 37 * 38 * - ddiv_fast, sqrt_fast 39 */ 40 41 double int2double(int32_t i); 42 double uint2double(uint32_t u); 43 double int642double(int64_t i); 44 double uint642double(uint64_t u); 45 double fix2double(int32_t m, int e); 46 double ufix2double(uint32_t m, int e); 47 double fix642double(int64_t m, int e); 48 double ufix642double(uint64_t m, int e); 49 50 // These methods round towards -Infinity. 51 int32_t double2fix(double d, int e); 52 uint32_t double2ufix(double d, int e); 53 int64_t double2fix64(double d, int e); 54 uint64_t double2ufix64(double d, int e); 55 int32_t double2int(double d); 56 uint32_t double2uint(double d); 57 int64_t double2int64(double d); 58 uint64_t double2uint64(double d); 59 60 // These methods round towards 0. 61 int32_t double2int_z(double d); 62 int64_t double2int64_z(double d); 63 64 double exp10(double x); 65 void sincos(double x, double *sinx, double *cosx); 66 double powint(double x, int y); 67 68 #if !PICO_RP2040 69 double ddiv_fast(double n, double d); 70 double sqrt_fast(double d); 71 double mla(double x, double y, double z); // note this is not fused 72 #endif 73 74 #ifdef __cplusplus 75 } 76 #endif 77 78 #endif 79 80