From 226ad1461c42b6b7b4430ee490ad64abacb8b039 Mon Sep 17 00:00:00 2001 From: Lamdonn Date: Wed, 12 Mar 2025 23:48:18 +0800 Subject: [PATCH] Fix some floatl issues, add init version flmath --- source/07_math/flmath.c | 333 +++++++++++++++++++++++++++++++++++ source/07_math/flmath.h | 48 +++++ source/07_math/floatl.c | 161 +++++++++++++++++ source/07_math/floatl.h | 22 +++ source/07_math/floatl_cfg.h | 318 +++++++++++++++++++++++++-------- test/test.mk | 1 + test/test_flmath.c | 190 ++++++++++++++++++++ test/test_floatl.c | 338 ++++++++++++++++++++++++++++-------- 8 files changed, 1275 insertions(+), 136 deletions(-) create mode 100644 source/07_math/flmath.c create mode 100644 source/07_math/flmath.h create mode 100644 test/test_flmath.c diff --git a/source/07_math/flmath.c b/source/07_math/flmath.c new file mode 100644 index 0000000..4eb8d64 --- /dev/null +++ b/source/07_math/flmath.c @@ -0,0 +1,333 @@ +/********************************************************************************************************* + * ------------------------------------------------------------------------------------------------------ + * file description + * ------------------------------------------------------------------------------------------------------ + * \file flmath.c + * \unit flmath + * \brief This is a simple large float number math calculate module for C language + * \author Lamdonn + * \version v1.0.1 + * \license GPL-2.0 + * \copyright Copyright (C) 2023 Lamdonn. + ********************************************************************************************************/ +#include "flmath.h" + +// Number of terms in the Taylor series for trigonometric functions +static const int trig_terms = 15 * sizeof(floatl) / 8; +// Number of terms in the Taylor series for the exponential function +static const int exp_terms = 15 * sizeof(floatl) / 8; +// Number of terms in the Taylor series for the natural logarithm function +static const int ln_terms = 15 * sizeof(floatl) / 8; + +/** + * \brief Calculates the factorial of an integer. + * \param n: The integer for which the factorial is to be calculated. + * \return A 'floatl' number representing the factorial of 'n'. + */ +static floatl floatl_int_fact(int n) +{ + floatl result = FLOATL_CONST_1; + for (int i = 1; i <= n; i++) + { + result = floatl_mul(result, floatl(i)); + } + return result; +} + +/** + * \brief Calculates the power of a 'floatl' number with an integer exponent. + * \param base: The base 'floatl' number. + * \param exponent: The integer exponent. + * \return A 'floatl' number representing 'base' raised to the power of 'exponent'. + */ +static floatl floatl_int_power(floatl base, int exponent) +{ + floatl result = FLOATL_CONST_1; + for (int i = 0; i < exponent; i++) + { + result = floatl_mul(result, base); + } + return result; +} + +/** + * \brief Calculates the sine of a 'floatl' number using the Taylor series expansion. + * \param x: The 'floatl' number for which the sine is to be calculated. + * \return A 'floatl' number representing the sine of 'x'. + */ +floatl floatl_sin(floatl x) +{ + floatl result = FLOATL_CONST_0; + // Normalize x to the range [-π, π] + while (floatl_gt(x, FLOATL_PI)) + { + x = floatl_sub(x, FLOATL_PI); + x = floatl_sub(x, FLOATL_PI); + } + while (floatl_lt(x, floatl_neg(FLOATL_PI))) + { + x = floatl_add(x, FLOATL_PI); + x = floatl_add(x, FLOATL_PI); + } + for (int n = 0; n < trig_terms; n++) + { + floatl term = floatl_int_power(floatl_neg(FLOATL_CONST_1), n); + term = floatl_mul(term, floatl_int_power(x, 2 * n + 1)); + term = floatl_div(term, floatl_int_fact(2 * n + 1)); + result = floatl_add(result, term); + } + return result; +} + +/** + * \brief Calculates the cosine of a 'floatl' number using the sine function. + * \param x: The 'floatl' number for which the cosine is to be calculated. + * \return A 'floatl' number representing the cosine of 'x'. + */ +floatl floatl_cos(floatl x) +{ + x = floatl_add(x, floatl_mul(floatl(0.5), FLOATL_PI)); + return floatl_sin(x); +} + +/** + * \brief Calculates the secant of a 'floatl' number. + * \param x: The 'floatl' number for which the secant is to be calculated. + * \return A 'floatl' number representing the secant of 'x'. + */ +floatl floatl_sec(floatl x) +{ + return floatl_div(FLOATL_CONST_1, floatl_cos(x)); +} + +/** + * \brief Calculates the cosecant of a 'floatl' number. + * \param x: The 'floatl' number for which the cosecant is to be calculated. + * \return A 'floatl' number representing the cosecant of 'x'. + */ +floatl floatl_csc(floatl x) +{ + return floatl_div(FLOATL_CONST_1, floatl_sin(x)); +} + +/** + * \brief Calculates the tangent of a 'floatl' number. + * \param x: The 'floatl' number for which the tangent is to be calculated. + * \return A 'floatl' number representing the tangent of 'x'. Returns infinity or negative infinity + * if the cosine of 'x' is zero. + */ +floatl floatl_tan(floatl x) +{ + floatl s = floatl_sin(x); + floatl c = floatl_cos(x); + if (floatl_eq(c, FLOATL_CONST_0)) + { + return (floatl_gt(s, FLOATL_CONST_0)) ? FLOATL_INF : floatl_neg(FLOATL_INF); + } + return floatl_div(s, c); +} + +/** + * \brief Calculates the cotangent of a 'floatl' number. + * \param x: The 'floatl' number for which the cotangent is to be calculated. + * \return A 'floatl' number representing the cotangent of 'x'. + */ +floatl floatl_cot(floatl x) +{ + x = floatl_sub(floatl_mul(floatl(0.5), FLOATL_PI), x); + return floatl_tan(x); +} + +/** + * \brief Calculates the exponential function of a 'floatl' number using the Taylor series expansion. + * \param x: The 'floatl' number for which the exponential is to be calculated. + * \return A 'floatl' number representing e raised to the power of 'x'. + */ +floatl floatl_exp(floatl x) +{ + floatl result = FLOATL_CONST_0; + for (int n = 0; n < exp_terms; n++) + { + floatl term = floatl_int_power(x, n); + term = floatl_div(term, floatl_int_fact(n)); + result = floatl_add(result, term); + } + return result; +} + +/** + * \brief Calculates the natural logarithm of a 'floatl' number using the Taylor series expansion. + * \param x: The 'floatl' number for which the natural logarithm is to be calculated. + * \return A 'floatl' number representing the natural logarithm of 'x'. Returns -1 if 'x' is less than or equal to 0. + */ +floatl floatl_ln(floatl x) +{ + if (floatl_le(x, FLOATL_CONST_0)) return floatl_neg(FLOATL_CONST_1); + floatl result = FLOATL_CONST_0; + // Transform x to the range (0, 2] + floatl y = floatl_sub(x, FLOATL_CONST_1); + y = floatl_div(y, floatl_add(x, FLOATL_CONST_1)); + for (int n = 0; n < ln_terms; n++) + { + floatl term = floatl_int_power(y, 2 * n + 1); + term = floatl_div(term, floatl(2 * n + 1)); + result = floatl_add(result, term); + } + result = floatl_mul(result, floatl(2.0)); + return result; +} + +/** + * \brief Calculates the logarithm of a 'floatl' number with a given base. + * \param x: The base 'floatl' number. + * \param y: The 'floatl' number for which the logarithm is to be calculated. + * \return A 'floatl' number representing the logarithm of 'y' with base 'x'. Returns negative infinity + * if 'x' is zero or 'y' is less than or equal to 0. + */ +floatl floatl_log(floatl x, floatl y) +{ + if ((floatl_eq(x, FLOATL_CONST_0)) || (floatl_le(y, FLOATL_CONST_0))) return floatl_neg(FLOATL_INF); + return floatl_div(floatl_ln(y), floatl_ln(x)); +} + +/** + * \brief Calculates the logarithm of a 'floatl' number with base 2. + * \param x: The 'floatl' number for which the logarithm is to be calculated. + * \return A 'floatl' number representing the logarithm of 'x' with base 2. Returns negative infinity + * if 'x' is zero. + */ +floatl floatl_log2(floatl x) +{ + if (floatl_eq(x, FLOATL_CONST_0)) return floatl_neg(FLOATL_INF); + return floatl_div(floatl_ln(x), floatl_ln(floatl(2.0))); +} + +/** + * \brief Calculates the logarithm of a 'floatl' number with base 10. + * \param x: The 'floatl' number for which the logarithm is to be calculated. + * \return A 'floatl' number representing the logarithm of 'x' with base 10. Returns negative infinity + * if 'x' is zero. + */ +floatl floatl_log10(floatl x) +{ + if (floatl_eq(x, FLOATL_CONST_0)) return floatl_neg(FLOATL_INF); + return floatl_div(floatl_ln(x), floatl_ln(floatl(10.0))); +} + +/** + * \brief Calculates the sigmoid function of a 'floatl' number. + * \param x: The 'floatl' number for which the sigmoid is to be calculated. + * \return A 'floatl' number representing the sigmoid of 'x'. + */ +floatl floatl_sigmoid(floatl x) +{ + return floatl_div(FLOATL_CONST_1, floatl_add(FLOATL_CONST_1, floatl_exp(floatl_neg(x)))); +} + +/** + * \brief Calculates the derivative of the sigmoid function of a 'floatl' number. + * \param x: The 'floatl' number for which the derivative of the sigmoid is to be calculated. + * \return A 'floatl' number representing the derivative of the sigmoid of 'x'. + */ +floatl floatl_dsigmoid(floatl x) +{ + floatl s = floatl_sigmoid(x); + return floatl_mul(s, floatl_sub(FLOATL_CONST_1, s)); +} + +/** + * \brief Calculates the hyperbolic sine of a 'floatl' number. + * \param x: The 'floatl' number for which the hyperbolic sine is to be calculated. + * \return A 'floatl' number representing the hyperbolic sine of 'x'. + */ +floatl floatl_sinh(floatl x) +{ + floatl a = floatl_exp(x); + return floatl_div(floatl_sub(a, floatl_div(FLOATL_CONST_1, a)), floatl(2.0)); +} + +/** + * \brief Calculates the hyperbolic cosine of a 'floatl' number. + * \param x: The 'floatl' number for which the hyperbolic cosine is to be calculated. + * \return A 'floatl' number representing the hyperbolic cosine of 'x'. + */ +floatl floatl_cosh(floatl x) +{ + floatl a = floatl_exp(x); + return floatl_div(floatl_add(a, floatl_div(FLOATL_CONST_1, a)), floatl(2.0)); +} + +/** + * \brief Calculates the hyperbolic tangent of a 'floatl' number. + * \param x: The 'floatl' number for which the hyperbolic tangent is to be calculated. + * \return A 'floatl' number representing the hyperbolic tangent of 'x'. + */ +floatl floatl_tanh(floatl x) +{ + floatl a = floatl_exp(x); + floatl b = floatl_div(FLOATL_CONST_1, a); + return floatl_div(floatl_sub(a, b), floatl_add(a, b)); +} + +/** + * \brief Calculates the hyperbolic cotangent of a 'floatl' number. + * \param x: The 'floatl' number for which the hyperbolic cotangent is to be calculated. + * \return A 'floatl' number representing the hyperbolic cotangent of 'x'. + */ +floatl floatl_coth(floatl x) +{ + floatl a = floatl_exp(x); + floatl b = floatl_div(FLOATL_CONST_1, a); + return floatl_div(floatl_add(a, b), floatl_sub(a, b)); +} + +/** + * \brief Calculates the hyperbolic secant of a 'floatl' number. + * \param x: The 'floatl' number for which the hyperbolic secant is to be calculated. + * \return A 'floatl' number representing the hyperbolic secant of 'x'. + */ +floatl floatl_sech(floatl x) +{ + floatl a = floatl_exp(x); + return floatl_div(floatl(2.0), floatl_add(a, floatl_div(FLOATL_CONST_1, a))); +} + +/** + * \brief Calculates the hyperbolic cosecant of a 'floatl' number. + * \param x: The 'floatl' number for which the hyperbolic cosecant is to be calculated. + * \return A 'floatl' number representing the hyperbolic cosecant of 'x'. + */ +floatl floatl_csch(floatl x) +{ + floatl a = floatl_exp(x); + return floatl_div(floatl(2.0), floatl_sub(a, floatl_div(FLOATL_CONST_1, a))); +} + +/** + * \brief Calculates the square root of a 'floatl' number using the Newton - Raphson method. + * \param x: The 'floatl' number for which the square root is to be calculated. + * \return A 'floatl' number representing the square root of 'x'. Returns -1 if 'x' is less than 0. + */ +floatl floatl_sqrt(floatl x) +{ + if (floatl_lt(x, FLOATL_CONST_0)) return floatl_neg(FLOATL_CONST_1); + floatl a = x; // Initial guess + floatl epsilon = floatl(1e-7); // Precision + while (floatl_gt(floatl_sub(floatl_mul(a, a), x), epsilon)) + { + a = floatl_add(a, floatl_div(x, a)); + a = floatl_div(a, floatl(2.0)); + } + return a; +} + +/** + * \brief Calculates the power of a 'floatl' number with another 'floatl' exponent. + * \param x: The base 'floatl' number. + * \param y: The exponent 'floatl' number. + * \return A 'floatl' number representing 'x' raised to the power of 'y'. + */ +floatl floatl_pow(floatl x, floatl y) +{ + return floatl_exp(floatl_mul(y, floatl_ln(x))); +} diff --git a/source/07_math/flmath.h b/source/07_math/flmath.h new file mode 100644 index 0000000..f774ca1 --- /dev/null +++ b/source/07_math/flmath.h @@ -0,0 +1,48 @@ + +/********************************************************************************************************* + * ------------------------------------------------------------------------------------------------------ + * file description + * ------------------------------------------------------------------------------------------------------ + * \file flmath.h + * \unit flmath + * \brief This is a simple large float number math calculate module for C language + * \author Lamdonn + * \version v1.0.1 + * \license GPL-2.0 + * \copyright Copyright (C) 2023 Lamdonn. + ********************************************************************************************************/ +#ifndef __flmath_H +#define __flmath_H + +#include "floatl.h" + +/* Version infomation */ + +#define FLMATH_V_MAJOR 1 +#define FLMATH_V_MINOR 0 +#define FLMATH_V_PATCH 0 + +floatl floatl_sin(floatl x); +floatl floatl_cos(floatl x); +floatl floatl_sec(floatl x); +floatl floatl_csc(floatl x); +floatl floatl_tan(floatl x); +floatl floatl_exp(floatl x); +floatl floatl_ln(floatl x); +floatl floatl_log(floatl x, floatl y); +floatl floatl_log2(floatl x); +floatl floatl_log10(floatl x); +floatl floatl_sigmoid(floatl x); +floatl floatl_dsigmoid(floatl x); +floatl floatl_sinh(floatl x); +floatl floatl_cosh(floatl x); +floatl floatl_tanh(floatl x); +floatl floatl_coth(floatl x); +floatl floatl_sech(floatl x); +floatl floatl_csch(floatl x); +floatl floatl_sqrt(floatl x); +floatl floatl_pow(floatl x, floatl y); + + +#endif + diff --git a/source/07_math/floatl.c b/source/07_math/floatl.c index a3a4d16..eb72bde 100644 --- a/source/07_math/floatl.c +++ b/source/07_math/floatl.c @@ -2029,6 +2029,167 @@ floatl floatl_neg(floatl a) return a; } +/** + * \brief Computes the ceiling of a 'floatl' number. + * \param[in] a: The 'floatl' number for which the ceiling value is to be computed. + * \return A 'floatl' number representing the ceiling of the input number. + * + * This function calculates the ceiling of a 'floatl' number. The ceiling of a number is the smallest + * integer that is greater than or equal to the given number. + */ +floatl floatl_ceil(floatl a) +{ + // Calculate the actual exponent value by subtracting the mid - point of the exponent range + int32_t exponent = a.exponent - __FLOATL_EXP_MID_VALUE__; + + // If the exponent is negative, the number lies between - 1 and 1 + if (exponent < 0) + { + // If the number is greater than 0, the ceiling is 1 + if (floatl_gt(a, FLOATL_CONST_0)) + { + return FLOATL_CONST_1; + } + // If the number is equal to 0, the ceiling is 0 + else if (floatl_eq(a, FLOATL_CONST_0)) + { + return FLOATL_CONST_0; + } + // If the number is less than 0, the ceiling is 0 (in the context of floating - point representation) + else + { + return floatl_neg(FLOATL_CONST_0); + } + } + + // Calculate the number of bits to shift to isolate the integer part + int32_t shift = __FLOATL_MANT_BITS__ - exponent; + + // If the shift is less than or equal to 0, the number is already an integer + if (shift <= 0) return a; + + // Create a floatl number with the least significant bit set to 1 + floatl int1 = FLOATL_CONST_0; + int1.u32[0] = 1; + // Create a mask to isolate the fractional part + floatl mask = floatl_int_sub(floatl_int_shl(int1, shift), int1); + // Clear the fractional part of the number + floatl result = floatl_int_and(a, floatl_int_not(mask)); + + // If the result is less than the original number, increment the result + if (floatl_lt(result, a)) + { + result = floatl_add(result, FLOATL_CONST_1); + } + + return result; +} + +/** + * \brief Computes the floor of a 'floatl' number. + * \param[in] a: The 'floatl' number for which the floor value is to be computed. + * \return A 'floatl' number representing the floor of the input number. + * + * This function calculates the floor of a 'floatl' number. The floor of a number is the largest + * integer that is less than or equal to the given number. + */ +floatl floatl_floor(floatl a) +{ + // Calculate the actual exponent value by subtracting the mid - point of the exponent range + int32_t exponent = a.exponent - __FLOATL_EXP_MID_VALUE__; + + // If the exponent is negative, the number lies between - 1 and 1 + if (exponent < 0) + { + // If the number is greater than or equal to 0, the floor is 0 + if (floatl_ge(a, FLOATL_CONST_0)) + { + return FLOATL_CONST_0; + } + // If the number is less than 0, the floor is - 1 + else + { + return floatl_neg(FLOATL_CONST_1); + } + } + + // Calculate the number of bits to shift to isolate the integer part + int32_t shift = __FLOATL_MANT_BITS__ - exponent; + + // If the shift is less than or equal to 0, the number is already an integer + if (shift <= 0) return a; + + // Create a floatl number with the least significant bit set to 1 + floatl int1 = FLOATL_CONST_0; + int1.u32[0] = 1; + // Create a mask to isolate the fractional part + floatl mask = floatl_int_sub(floatl_int_shl(int1, shift), int1); + // Clear the fractional part of the number + floatl result = floatl_int_and(a, floatl_int_not(mask)); + + // If the result is greater than the original number, decrement the result + if (floatl_gt(result, a)) + { + result = floatl_sub(result, FLOATL_CONST_1); + } + + return result; +} + +/** + * \brief Rounds a 'floatl' number to the nearest integer. + * \param[in] a: The 'floatl' number to be rounded. + * \return A 'floatl' number representing the rounded value of the input number. + * + * This function rounds a 'floatl' number to the nearest integer. If the fractional part + * is 0.5 or greater, the number is rounded up; otherwise, it is rounded down. + */ +floatl floatl_round(floatl a) +{ + // Calculate the actual exponent value by subtracting the mid - point of the exponent range + int32_t exponent = a.exponent - __FLOATL_EXP_MID_VALUE__; + + // If the exponent is negative, the number lies between - 1 and 1 + if (exponent < 0) + { + if (floatl_gt(a, FLOATL_CONST_0)) + { + // If the number is greater than 0, round up if it is greater than or equal to 0.5 + return (floatl_ge(a, floatl(0.5))) ? FLOATL_CONST_1 : FLOATL_CONST_0; + } + else + { + // If the number is less than 0, round down if it is less than or equal to - 0.5 + return (floatl_le(a, floatl(-0.5))) ? floatl_neg(FLOATL_CONST_1) : floatl_neg(FLOATL_CONST_0); + } + } + + // Calculate the number of bits to shift to isolate the integer part + int32_t shift = __FLOATL_MANT_BITS__ - exponent; + + // If the shift is less than or equal to 0, the number is already an integer + if (shift <= 0) return a; + + // Create a floatl number with the least significant bit set to 1 + floatl int1 = FLOATL_CONST_0; + int1.u32[0] = 1; + // Create a mask to isolate the fractional part + floatl mask = floatl_int_sub(floatl_int_shl(int1, shift), int1); + // Clear the fractional part of the number to get the integer part + floatl result = floatl_int_and(a, floatl_int_not(mask)); + // Extract the fractional part of the number + floatl fractional = floatl_int_and(a, mask); + + // Check if the fractional part is greater than or equal to 0.5 + if (floatl_int_ucmp(fractional, floatl_int_shl(int1, shift - 1)) >= 0) + { + // If so, round up the result + result = floatl_add(result, FLOATL_CONST_1); + } + + return result; +} + /** * \brief Perform a right shift operation on a 'floatl' value while preserving the sticky bit. * \param[in] mant: The 'floatl' value to be shifted. diff --git a/source/07_math/floatl.h b/source/07_math/floatl.h index 71b1459..c642e76 100644 --- a/source/07_math/floatl.h +++ b/source/07_math/floatl.h @@ -32,7 +32,15 @@ */ #define FLOATL_INF __FLOATL_INF__ +#define FLOATL_INF_N floatl_neg(__FLOATL_INF__) #define FLOATL_NAN __FLOATL_NAN__ +#define FLOATL_PI __FLOATL_CONST_PI__ +#define FLOATL_E __FLOATL_CONST_E__ +#define FLOATL_MIN __FLOATL_MIN__ +#define FLOATL_MAX __FLOATL_MAX__ +#define FLOATL_EPSILON __FLOATL_EPSILON__ +#define FLOATL_CONST_PI __FLOATL_CONST_PI__ +#define FLOATL_CONST_E __FLOATL_CONST_E__ #define FLOATL_CONST_0 __FLOATL_CONST_0__ #define FLOATL_CONST_1 __FLOATL_CONST_1__ #define FLOATL_CONST_10 __FLOATL_CONST_1e1__ @@ -55,6 +63,14 @@ #define FLOATL_CONST_1e14 __FLOATL_CONST_1e14__ #define FLOATL_CONST_1e15 __FLOATL_CONST_1e15__ +#define FLOATL_MANT_DIG __FLOATL_MANT_DIG__ +#define FLOATL_MIN_EXP __FLOATL_MIN_EXP__ +#define FLOATL_MAX_EXP __FLOATL_MAX_EXP__ +#define FLOATL_DIG __FLOATL_DIG__ +#define FLOATL_DECIMAL_DIG __FLOATL_DECIMAL_DIG__ +#define FLOATL_MIN_10_EXP __FLOATL_MIN_10_EXP__ +#define FLOATL_MAX_10_EXP __FLOATL_MAX_10_EXP__ + /** * \brief A structure to represent a long bits integer. * @@ -122,9 +138,15 @@ int floatl_isnormal(floatl a); // Value modification functions // floatl_abs: Computes the absolute value of a floatl number // floatl_neg: Computes the negation of a floatl number, equivalent to the unary '-' operator +// floatl_ceil: Computes the ceiling value of a floatl number +// floatl_floor: Computes the floor value of a floatl number +// floatl_round: Computes the round value of a floatl number floatl floatl_abs(floatl a); floatl floatl_neg(floatl a); +floatl floatl_ceil(floatl a); +floatl floatl_floor(floatl a); +floatl floatl_round(floatl a); // Conversion functions // floatl_from: Converts a string to a floatl number diff --git a/source/07_math/floatl_cfg.h b/source/07_math/floatl_cfg.h index 325df22..735054c 100644 --- a/source/07_math/floatl_cfg.h +++ b/source/07_math/floatl_cfg.h @@ -19,6 +19,11 @@ * This is a flexible definition that can be extended to larger numbers in addition to the given few size definitions */ +// #define FLOATL_CFG_MANT_PI "100100100001111110110101010001000100001011010001100001000110100110001001100011001100010100010111000000011011100000111001101000100101001000000100100111000001000100010100110011111001100011101000000001000001011101111101010011000111011000100111001101100100010010100010100101000001000011110011000111000110100000001001101110111101111100101010001100110110011110011010011101001000011000110110011000000101011000010100110110111110010010111110001010000110111010011111110000100110101011011010110110101010001110000100100010111100100100001011011010101110110011000100101111001111110110001101111010001001100010000101110100110100110001101111110110101101011000010111111111101011100101101101111010000000110101101111110110111101110001110000110101111111011010110101000100110011111101001011010111010011111001001000001000101111100010010110001111111100110010010010010100001100110010100011110110011100100010110110011110111000010000000000111110010111000101000010110001110111111000001011001100011011010010010000011011000011100010101011101001110011010011010010001011000111111101010010001111101111110001010000001110111100110011010010111011010001001100011011001000111011110000001000111010011101100000001110001100111000101100000110001011111110100111111110110000110101011000000001010111000010111001011101101011110010010100010100110010000111000011110111000001110110010000111001101010110010000001100101011101000111011110011100001010001000100001110101000110110010111011001100110000010000011111110100011011101001110100001011010101010001110000000001100011100111001100101100101110011111011111001001001000000000111001001010101001111001111011000111000110011111110000001011111010010110101010111111110100101001101100110011111000110111010000110110100010011000101110111110110111010111100110100001001111000000101001000010101011001101111001000010010011010000111110001001101111101010011111110111101001011111101011100111001010110111011111001010001001110010110011101010110110011111100101011000110110110000001010101101011111000101100000110011101110110100010010100001001111110100100111101011111011011100011000110100010110010100000001100010001010100111111101000010000101100110110011001110101010000000111110001101101110111010101111001110010010100010100100011010111000001000001110001111011110100101111110010001001001100011110001000010101111111111000011100010001000111101010011010111001011110010001000000101011101101100101101010111101011100011101110010110111110011000100100111001010110100000101000111000111011100000001101111011111011100010100101011011000100100100011111100001110111010101001001010000111110000010010110110010001100011111010001010011111100000110000101011001011110001111010101110111110000000101100111111011000011011011110011000000000110001000111110100111001001001011101010101101111000011000111011001110110100000010001000100111011000100010010111100100011011001000011000001100010000100111011110001111010111101010101100010111111101100100001001001000001110011111101101111010001111100000010011110010100001101101111111011100111001011111011111011010010011101100001100110011010111111101101111111110101100001101101100001110110011101100101110100011111010010011111100110000010010001111000010111000101100010100101111010110101010001010000100101001010110101110101001001110100110110001011100000100111010010101111001101110110110110101011101001100101000010010110011111100111100101001001111001011110101000100000110101110001010101010000111001000100101110110000001000001110001111100100001000101110100001001111110011010100010010001101001011111101111111011001000010110001000111110001011000110101011100100000011111010001001101101101000101010110100100001001011111001110000000000011111100001100111101111101011011011111011100100000000101001111001111011011100111000010010001011000001010111101110011001010010111010110100001110110101001101110110000111000111100100010101011000111010100111001100110010100000000110011011001101101111001101000001101101101001110110100111000011010110101011001101100100101011001110000110010110111001111100111011010001110101110000011000011001110000110011111011101001111000001111110010100000100111010000010011100010111011011011001110111101101010010100101001001010101000000100101011111100110101000110001010110010111100101011111100001000100001111000000111111000010010001011000110000100000010100001101101100110000000100010010100101011001110100111110110100110110111101001010000110110110101111001000100110000001001010001011111001001011010000000111111011100101011001111101101000000101001001010111110000000110011010010010011111101101110101110111111011001000000110110111101101100001110101000001011011111001100000001100101111011001001010011001110010101001001000011010001000000000010100010010100111110101101101111011100110100011001010100011101001000001011010011000011010110001110100101100110100000000101111101100101101010000001111000111001100001110001010111000100001000100100010001111100000111001001101001011011011001011000001100101001011101111100010100110011010010010111001101011001110110011001010010011011011001110101011001110110101001000101000101001100111110110110011110110001011010110011101001110001100000111100111111011010010101101010001101001110100110101111111010000010111110110000110010100001011100011101101100110110001001011000110011101110111001100011001001110111001100010010110111101100100011100101101100101000101001101111001101001000111010101011000010010101100111101100100111110001111111110100100010110101110000010110110010111111011101101010100110100011010100101111010001110100101011001101010000010011101101010100000000010110011001111010000000000101010011101100101101111000111111111000110010111000100100000111110110001101010111110101011101101110100001111011100100101111011110000100111111010110100011001101011100000001001111000010110011100011111101100111001111001110110111110111100010011010001010101110011101101011101000101111111100100000011011111010100111010001111101110011100100011110011100111000111111010010111000001001011101010111010111111110101110110100110110001101001111110101100110011111111111111100011011001110111011001111000100000100010100101111000011011001010111000110010011110110011001011101011000110101001100011010001001001000101000000001110111001111111011010010011110001011111011110011100110101011100010100100001110111100101010100001011000101100111000011110010110111001110010100001010011110100101110111100110111101111010010000110100110100100010111001001100111100111010011110000101110001010010011110100110010100110010011110110100001110111110000011110100011011000110010101101100011100001010111100011110101101000011000110010011101110000101101101110011110111110000010000100011100011001101110000101000101100101110111000001101101111100011110000000100010001100010100000011100110111100110000011110101100001110101101010001101110111110100000100000100001011111001001011110110110100111100110100100011010000000011111100010110001110011100011110000001100010010101010111000111010110011001111111011010011100001110100100110111111101001001101100111110011011011100000101100010011111110110110001010110111100001000001001111000001110110010101100000100000101101100000010001111001100010100101010100100001111111110111111111100010010010110100111110110101010101101111000101110010101011111101011100101101010001000110010101110001011111111000100101100010001111010000011000100100001111111100000010011011010100001111001011100111010110010100000011101010111010100010100011101000110110000010001001101010011111000110001110010000111110011111111010000010111011000110101001011000110110110101001010010001000100001110101100001100000010101101111100100100100110011010100111101101111010111110101010010001000101000101001111010000100111110111111111100010101001100101001101010110110000111111010111100000001100010000010001100000111111000001100101000110101101100000111011010110100111111011100011111111101001101011001001010111101001110101010011111001000110000111100100111110010101111110101001000010010010011000010100000111000110101101010101011001100110010101110001111111000110000011111000100101000111110111010001001111100111011111000010111011000001011100100010101010111110000110010000110001001001100011011010110111000001011001001100001001101111011001010100011101011000101101101111010100000001101001001001001001110011111010011100001011001101000110101110" +// #define FLOATL_CFG_MANT_E "010110111111000010101000101100010100010101110110100101010011010101011111101110001010110001000000010011100111101001111001111000111011000101110011100010110000011110011100010110100110110100101011010100111100001001101100100000100010100011001000011001111111011110011001001001110011101110011100010010010011011001111101111100101111101001011111110001101100011011000110000110001110101110110001111011010000001101100100000001010101110110001000110000101111010110100111101111100011110110101011101010111111101011001010110000100100100001100111111010100011111010111110000011001101110110100001000010101100011011001010101010100111101111011010001101011110011101101010101011100010011010111100111111101010111110010010011010110011000010011110000110001110000111000001110011010001011011101111110001010100110100010011101101011110011111011111110100001110010000111011111000101011000101000010011011010101101111001110011010100110000101011001100101001001111010010000011101001111001011110101011110000001010101100011000001010110011001001001111101101100001110100010000100010101001010010111011001011000101011100101111101011000010010110010101000100110110010111010100001101011010000011001110000101001001001000111111111101110000001101011011011111011000111101010100011111100010010100110010101111110000011110110100011011101111011010000001001010100000101000111110000001110010001110100000110111110111110100110001110101111110110101111100000101011010000001100110100110000010000101100001011010001001010101101110110010101011111101000100111111001111010101010000100010100100110110000110011101000101101000110111101010100101001000010010010110000000010111110111101101011011111010010000100111110111100000010100100000001100011100100011000010000110011110001000000000100001111001000011110001111001110101100000110010011001110000000100111011000101010001011101000100110010100101000101010111101100101110001011100001100110110010100011001101010000101001111011110011010110000001101000000111011010111110010011010101101000100101101110001111010101000011000011011100111011000110001111000111100110000001100001010011101010010100001111110001101001110100010011010011110100111001111110100101100110011011100101111010110111011101111101101000101111000010010010100110110001000101101101100100011101000001111010111000001011100010111100010111110001100001101110011011010111101000111010011101100010010000010001011011101101110001110110111001001001001110000001111111010010110111111010000010110100011010101101000000000101000110111101001000111001011110000000101100011001110001111000010011110110110100001111010011110111000110000111010111011001011111001010110110111110100110101110110110010001010010100010001111101100111001001110100100111010001000000110010011010011000001100101000111110101011101101100011101001000001001110111000011110101010100000101100000000100001111100001110111011011001001110100000110011110001111100001010111001111000110111011100101101001101001010101110110011101101010101111011010001110011101000100110100110011100000100111110001110000111110001100010101000111001101001010100010000111010101011100100100011010000011010010011111100011000110100000000101110010101000100100011010010101110100111100101111011011000001011111100101001010110010111101101001000010010010011110100110000100100001111111110111100011010000100010011001100011111110101011011111111100110100001010110010011101011100100010011001111101101100100110111111111111000101111110100110100100011111000101010101000100010011000010000010101111111011000001000000010100011000110111100101010001001010111100010100111111100010001110011111101101111110111100111101000100111101000010101101111010111000111001100000010000010111110010100000011010101011001111001100000001000110000100011000011110011001011000000110001101011000010110000000100001110101111110001100010101110011101100001110010000001100111001111110011000100101101000111111001100001111000000110010000101011000110110001110110001110101100101111100111110001010100101011011011011110111100110001111000001001111000011001110000100111111111001111101110010000111110110100111011011101100101110111111000101100010111100001100100010000100001111100100101011110001100100010010101111001100001110011010001110000110111101001110111110000011100011001010001011111100110101011101100111111101001111010101000101100111011011101110001000111111001101100111000000100000000100100111001011001001111011101101000101010000110011010100011001011001100100011100001010001111000100111101111110010001110010100100111101000110111001010110000001010110011100000100011101011101011001000111100000010110011011110011001000111101000100100000010000001010101101000100101000101001001001101110011110010111001110010010111110011010111111011101110010100110011011010111110101100100010001001111000011100011110011110100011001001101100110100000100001001111010101101010000110100000100100011011101101101100000010100011011100011111111011100000000011111101110111110011111000001101001010100010000010000111001101010000100110100111101010000011111111110000001000011011100001110111100100101100010000010010010111111111010011010001110001010100011010011111101110111100110101101000001110011011001111001010111000001000111111110001100000101010001111011101100011010010100000000010011100011010010100000110000010001010100100101000000111110110011010111001001000001110000010010111111000101001010000001000010010000001111001010110011100101111000010101001011100101011100010000100011011101011011011100000010000010101000000101101001000100100110011010110101111001101000001110010001111100101101110011110101010111100011010101011110110011001001101010011001011001101000110000111001111100110101001101100011111011011110100001100111010101001110101010000100110110100101111100010010011010011000101110011000000011110010001111111111000010101110001010100100011011010000001100010100101011101000101011001101001001001110101011101001101100001101011111101101011010100001010000110101010100000010001011000010111001010101100011011110011001010001100011111001110011001010001111010001010101010001011000011000111010110011110011011101110111110000101110111011010001100010110101001011100110111111110011011100010110111101110001001111101000111110111111001111010100111001001111100011001010100000100101011100011101001011010110001100010000111111100000111110110000101101100001000110011101101100110101111111101000101011010001001101111100110000110110111111001111111100101110011001001110010011010100010001000010110010110110011100100001010001010100011101011111010000101010011101010110101000011010010000101010011000011001110000010110111100010100100110100100000010010111100101011011110100011110101011100100100110010110011000001011100000001110100001011011010111001100110001100111011111001010100100101010010011111001001101010001000100110111010101011101101011110001100000010000101111110100110101101010001010100111110101100101100010010001001100100100000010110110000100001011111011101000101000010111101110101010011110010111101000010010001101011010111011010000101010111100111100110111000111011010101100101110011010010010001010101001001001111000101101001010000010000001111100011001111101010110010111101111101000101100111110000011010100000001110100011000111011000110011111011110000111100000000000010101010101010100011111010000101110010010001100100101010011100101110011001001111111111011101100001000101010100011100110110001001011101100010011000011010011011111001110011000100000011001000100101000110101000110000110011110001110000000001110011011001000110111011101110010011000101111101011001011110111010010000010110111000110011111100001110100001001111010011011101110001100111001011100110000111001110101001000010100011010110110011101101100000010100001100100111000110101111010110101100100100010011110010011011101010110011000101000010011101111011110001111001100100101100010111011000110101000111100110101010011010101110001001010100111111101101011100100100000110110110000000101000101101100111010100011000111001100011010101101111100110100000000001110111001111100111011011001110100111010101000011010101110010011011101001000011100100010000101111000110000010011001111011010100101001110110010000011011100000111110000011110010010010000100000001010110110011011011110010111110101100110001001101101000111110000001010100100110011111111010101111001110110100011111010101011011000101010101111" +#define FLOATL_CFG_MANT_PI NULL +#define FLOATL_CFG_MANT_E NULL + /*****************************************************************/ /* Config start */ /*****************************************************************/ @@ -44,6 +49,13 @@ #define __FLOATL2_BIT_PARTS__ 128 #define __FLOATL2_U32_PARTS__ 4 #define __FLOATL2_U16_PARTS__ 8 +#define __FLOATL_MANT_DIG__ 53 +#define __FLOATL_MIN_EXP__ -1021 +#define __FLOATL_MAX_EXP__ 1024 +#define __FLOATL_DIG__ 15 +#define __FLOATL_DECIMAL_DIG__ 17 +#define __FLOATL_MIN_10_EXP__ -307 +#define __FLOATL_MAX_10_EXP__ 308 #define __FLOATL_CONST_0__ (floatl){.u32={0,0,}} #define __FLOATL_CONST_1__ (floatl){.u32={0,0x3FF00000,}} #define __FLOATL_CONST_1e0__ (floatl){.u32={0,0x3FF00000,}} @@ -62,6 +74,8 @@ #define __FLOATL_CONST_1e13__ (floatl){.u32={0xE5400000,0x42A2309C,}} #define __FLOATL_CONST_1e14__ (floatl){.u32={0x1E900000,0x42D6BCC4,}} #define __FLOATL_CONST_1e15__ (floatl){.u32={0x26340000,0x430C6BF5,}} +#define __FLOATL_CONST_PI__ (floatl){.u32={0x54442D18,0x400921FB,}} +#define __FLOATL_CONST_E__ (floatl){.u32={0x8B145769,0x4005BF0A,}} #define __FLOATL_INT_ZERO__ (floatl){.u32={0,0,}} #define __FLOATL_INF__ (floatl){.u32={0,0x7FF00000,}} #define __FLOATL_NAN__ (floatl){.u32={0,0xFFF00000,}} @@ -72,6 +86,9 @@ #define __FLOATL_HIDE_MANT_BIT__ (floatl){.u32={0,0x00100000,}} #define __FLOATL_MANT_PLUS_MAX__ (floatl){.u32={0,0x00800000,}} #define __FLOATL_MANT_WHL__ (floatl){.u32={-1,0x001FFFFF,}} +#define __FLOATL_MIN__ (floatl){.u32={0,0x00100000,}} +#define __FLOATL_MAX__ (floatl){.u32={-1,0x7FEFFFFF,}} +#define __FLOATL_EPSILON__ (floatl){.u32={0x00000001,0,}} #elif defined(FLOATL_USE_128BITS) #define __FLOATL_BIT_PARTS__ 128 #define __FLOATL_U32_PARTS__ 4 @@ -85,6 +102,13 @@ #define __FLOATL2_BIT_PARTS__ 256 #define __FLOATL2_U32_PARTS__ 8 #define __FLOATL2_U16_PARTS__ 16 +#define __FLOATL_MANT_DIG__ 115 +#define __FLOATL_MIN_EXP__ -4093 +#define __FLOATL_MAX_EXP__ 4096 +#define __FLOATL_DIG__ 34 +#define __FLOATL_DECIMAL_DIG__ 36 +#define __FLOATL_MIN_10_EXP__ -1232 +#define __FLOATL_MAX_10_EXP__ 1233 #define __FLOATL_CONST_0__ (floatl){.u32={0,0,0,0,}} #define __FLOATL_CONST_1__ (floatl){.u32={0,0,0,0x3FFC0000,}} #define __FLOATL_CONST_1e0__ (floatl){.u32={0,0,0,0x3FFC0000,}} @@ -103,6 +127,8 @@ #define __FLOATL_CONST_1e13__ (floatl){.u32={0,0,0x39500000,0x40A88C27,}} #define __FLOATL_CONST_1e14__ (floatl){.u32={0,0,0x07A40000,0x40B5AF31,}} #define __FLOATL_CONST_1e15__ (floatl){.u32={0,0,0x498D0000,0x40C31AFD,}} +#define __FLOATL_CONST_PI__ (floatl){.u32={0x145C06E0,0x11A62633,0xD5110B46,0x4002487E,}} +#define __FLOATL_CONST_E__ (floatl){.u32={0xB10139E9,0x54D57EE2,0xA2C515DA,0x40016FC2,}} #define __FLOATL_INT_ZERO__ (floatl){.u32={0,0,0,0,}} #define __FLOATL_INF__ (floatl){.u32={0,0,0,0x7FFC0000,}} #define __FLOATL_NAN__ (floatl){.u32={0,0,0,0xFFFC0000,}} @@ -113,6 +139,9 @@ #define __FLOATL_HIDE_MANT_BIT__ (floatl){.u32={0,0,0,0x00040000,}} #define __FLOATL_MANT_PLUS_MAX__ (floatl){.u32={0,0,0,0x00200000,}} #define __FLOATL_MANT_WHL__ (floatl){.u32={-1,-1,-1,0x0007FFFF,}} +#define __FLOATL_MIN__ (floatl){.u32={0,0,0,0x00040000,}} +#define __FLOATL_MAX__ (floatl){.u32={-1,-1,-1,0x7FFBFFFF,}} +#define __FLOATL_EPSILON__ (floatl){.u32={0x00000001,0,0,0,}} #elif defined(FLOATL_USE_256BITS) #define __FLOATL_BIT_PARTS__ 256 #define __FLOATL_U32_PARTS__ 8 @@ -126,6 +155,13 @@ #define __FLOATL2_BIT_PARTS__ 512 #define __FLOATL2_U32_PARTS__ 16 #define __FLOATL2_U16_PARTS__ 32 +#define __FLOATL_MANT_DIG__ 241 +#define __FLOATL_MIN_EXP__ -16381 +#define __FLOATL_MAX_EXP__ 16384 +#define __FLOATL_DIG__ 72 +#define __FLOATL_DECIMAL_DIG__ 74 +#define __FLOATL_MIN_10_EXP__ -4931 +#define __FLOATL_MAX_10_EXP__ 4932 #define __FLOATL_CONST_0__ (floatl){.u32={0,0,0,0,0,0,0,0,}} #define __FLOATL_CONST_1__ (floatl){.u32={0,0,0,0,0,0,0,0x3FFF0000,}} #define __FLOATL_CONST_1e0__ (floatl){.u32={0,0,0,0,0,0,0,0x3FFF0000,}} @@ -144,6 +180,8 @@ #define __FLOATL_CONST_1e13__ (floatl){.u32={0,0,0,0,0,0,0xCE540000,0x402A2309,}} #define __FLOATL_CONST_1e14__ (floatl){.u32={0,0,0,0,0,0,0x41E90000,0x402D6BCC,}} #define __FLOATL_CONST_1e15__ (floatl){.u32={0,0,0,0,0,0,0x52634000,0x4030C6BF,}} +#define __FLOATL_CONST_PI__ (floatl){.u32={0x7D4C7627,0x98E80417,0x9C1114CF,0x39A25204,0xC51701B8,0x8469898C,0xB54442D1,0x4000921F,}} +#define __FLOATL_CONST_E__ (floatl){.u32={0x6C8228C8,0x6D2B53C2,0x8B079C5A,0x79E3B173,0xAC404E7A,0x95355FB8,0xA8B14576,0x40005BF0,}} #define __FLOATL_INT_ZERO__ (floatl){.u32={0,0,0,0,0,0,0,0,}} #define __FLOATL_INF__ (floatl){.u32={0,0,0,0,0,0,0,0x7FFF0000,}} #define __FLOATL_NAN__ (floatl){.u32={0,0,0,0,0,0,0,0xFFFF0000,}} @@ -154,6 +192,9 @@ #define __FLOATL_HIDE_MANT_BIT__ (floatl){.u32={0,0,0,0,0,0,0,0x00010000,}} #define __FLOATL_MANT_PLUS_MAX__ (floatl){.u32={0,0,0,0,0,0,0,0x00080000,}} #define __FLOATL_MANT_WHL__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,0x0001FFFF,}} +#define __FLOATL_MIN__ (floatl){.u32={0,0,0,0,0,0,0,0x00010000,}} +#define __FLOATL_MAX__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,0x7FFEFFFF,}} +#define __FLOATL_EPSILON__ (floatl){.u32={0x00000001,0,0,0,0,0,0,0,}} #elif defined(FLOATL_USE_512BITS) #define __FLOATL_BIT_PARTS__ 512 #define __FLOATL_U32_PARTS__ 16 @@ -167,6 +208,13 @@ #define __FLOATL2_BIT_PARTS__ 1024 #define __FLOATL2_U32_PARTS__ 32 #define __FLOATL2_U16_PARTS__ 64 +#define __FLOATL_MANT_DIG__ 495 +#define __FLOATL_MIN_EXP__ -65533 +#define __FLOATL_MAX_EXP__ 65536 +#define __FLOATL_DIG__ 149 +#define __FLOATL_DECIMAL_DIG__ 151 +#define __FLOATL_MIN_10_EXP__ -19727 +#define __FLOATL_MAX_10_EXP__ 19728 #define __FLOATL_CONST_0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}} #define __FLOATL_CONST_1__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3FFFC000,}} #define __FLOATL_CONST_1e0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3FFFC000,}} @@ -185,6 +233,8 @@ #define __FLOATL_CONST_1e13__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x73950000,0x400A88C2,}} #define __FLOATL_CONST_1e14__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x107A4000,0x400B5AF3,}} #define __FLOATL_CONST_1e15__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xD498D000,0x400C31AF,}} +#define __FLOATL_CONST_PI__ (floatl){.u32={0x9AB6B6A8,0x8A1BA7F0,0x8536F92F,0x218D9815,0x8CD9E69D,0x026EF7CA,0x043CC71A,0xCD9128A5,0xDF531D89,0xE63A0105,0x27044533,0x0E689481,0x3145C06E,0x611A6263,0xED5110B4,0x40002487,}} +#define __FLOATL_CONST_E__ (floatl){.u32={0x8F6AEAFE,0x30BD69EF,0xD9015762,0x3AEC7B40,0xF1B1B186,0x9F7CBE97,0xCEE7124D,0x19FDE649,0x9B208A32,0x9B4AD4F0,0xE2C1E716,0x9E78EC5C,0x2B10139E,0xA54D57EE,0x2A2C515D,0x400016FC,}} #define __FLOATL_INT_ZERO__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}} #define __FLOATL_INF__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x7FFFC000,}} #define __FLOATL_NAN__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xFFFFC000,}} @@ -195,6 +245,9 @@ #define __FLOATL_HIDE_MANT_BIT__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00004000,}} #define __FLOATL_MANT_PLUS_MAX__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00020000,}} #define __FLOATL_MANT_WHL__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x00007FFF,}} +#define __FLOATL_MIN__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00004000,}} +#define __FLOATL_MAX__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFBFFF,}} +#define __FLOATL_EPSILON__ (floatl){.u32={0x00000001,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}} #elif defined(FLOATL_USE_1024BITS) #define __FLOATL_BIT_PARTS__ 1024 #define __FLOATL_U32_PARTS__ 32 @@ -208,6 +261,13 @@ #define __FLOATL2_BIT_PARTS__ 2048 #define __FLOATL2_U32_PARTS__ 64 #define __FLOATL2_U16_PARTS__ 128 +#define __FLOATL_MANT_DIG__ 1005 +#define __FLOATL_MIN_EXP__ -262141 +#define __FLOATL_MAX_EXP__ 262144 +#define __FLOATL_DIG__ 302 +#define __FLOATL_DECIMAL_DIG__ 304 +#define __FLOATL_MIN_10_EXP__ -78912 +#define __FLOATL_MAX_10_EXP__ 78913 #define __FLOATL_CONST_0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}} #define __FLOATL_CONST_1__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3FFFF000,}} #define __FLOATL_CONST_1e0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3FFFF000,}} @@ -226,6 +286,8 @@ #define __FLOATL_CONST_1e13__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x9CE54000,0x4002A230,}} #define __FLOATL_CONST_1e14__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xC41E9000,0x4002D6BC,}} #define __FLOATL_CONST_1e15__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xF5263400,0x40030C6B,}} +#define __FLOATL_CONST_PI__ (floatl){.u32={0x4906C38A,0x77E0B31B,0x0F97142C,0x8B67B840,0x0CCA3D9C,0x63FCC925,0xE4822F89,0x33F4B5D3,0x0D7F6B51,0xD6FDBDC7,0xEB96DE80,0xFDAD617F,0x885D34C6,0xCFD8DE89,0xB6AECC4B,0x3848BC90,0x26ADADAA,0xE286E9FC,0x614DBE4B,0x48636605,0xA33679A7,0x809BBDF2,0x410F31C6,0x73644A29,0x77D4C762,0xF98E8041,0x49C1114C,0x839A2520,0xCC51701B,0x18469898,0xFB54442D,0x40000921,}} +#define __FLOATL_CONST_E__ (floatl){.u32={0x56305664,0x4F2F5781,0x9949E907,0xBCE6A615,0x2B1426D5,0xFD0E43BE,0xD13B5E7D,0xD16EFC54,0xE18E1C1C,0xF926B309,0xE26BCFEA,0xA35E76AA,0x6CAAA7BD,0xCDDA10AC,0x7EA3EBE0,0xACAC2486,0xE3DABABF,0x8C2F5A7B,0x364055D8,0x8EBB1ED0,0xFC6C6C61,0x67DF2FA5,0x73B9C493,0x867F7992,0x26C8228C,0xA6D2B53C,0x38B079C5,0xA79E3B17,0x8AC404E7,0x695355FB,0x0A8B1457,0x400005BF,}} #define __FLOATL_INT_ZERO__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}} #define __FLOATL_INF__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x7FFFF000,}} #define __FLOATL_NAN__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xFFFFF000,}} @@ -236,6 +298,9 @@ #define __FLOATL_HIDE_MANT_BIT__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00001000,}} #define __FLOATL_MANT_PLUS_MAX__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00008000,}} #define __FLOATL_MANT_WHL__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x00001FFF,}} +#define __FLOATL_MIN__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00001000,}} +#define __FLOATL_MAX__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFEFFF,}} +#define __FLOATL_EPSILON__ (floatl){.u32={0x00000001,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}} #elif defined(FLOATL_USE_2048BITS) #define __FLOATL_BIT_PARTS__ 2048 #define __FLOATL_U32_PARTS__ 64 @@ -249,6 +314,13 @@ #define __FLOATL2_BIT_PARTS__ 4096 #define __FLOATL2_U32_PARTS__ 128 #define __FLOATL2_U16_PARTS__ 256 +#define __FLOATL_MANT_DIG__ 2027 +#define __FLOATL_MIN_EXP__ -1048573 +#define __FLOATL_MAX_EXP__ 1048576 +#define __FLOATL_DIG__ 610 +#define __FLOATL_DECIMAL_DIG__ 612 +#define __FLOATL_MIN_10_EXP__ -315652 +#define __FLOATL_MAX_10_EXP__ 315653 #define __FLOATL_CONST_0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}} #define __FLOATL_CONST_1__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3FFFFC00,}} #define __FLOATL_CONST_1e0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3FFFFC00,}} @@ -267,6 +339,8 @@ #define __FLOATL_CONST_1e13__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x27395000,0x4000A88C,}} #define __FLOATL_CONST_1e14__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3107A400,0x4000B5AF,}} #define __FLOATL_CONST_1e15__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xFD498D00,0x4000C31A,}} +#define __FLOATL_CONST_PI__ (floatl){.u32={0xED1284FD,0xB5F160CE,0xE5636C0A,0x9CB3AB67,0x9CADDF28,0x9FDE97EB,0x343E26FA,0x0AB37909,0xE684F029,0x262EFB75,0xCF8DD0DA,0xAAFF4A6C,0x67F02FA5,0x2A9E7B1C,0xDF248039,0x39CCB2E7,0x2D547006,0x1FD1BA74,0x6CBB3304,0x70A221D4,0x8195D1DE,0x1D90E6AC,0x5321C3DC,0xB976BC94,0x0D580570,0x18BFA7FB,0x6038CE2C,0x8EF023A7,0x4BB44C6C,0xF140EF33,0xB1FD48FB,0xAE9CD348,0xD241B0E2,0x1DF82CC6,0x03E5C50B,0x22D9EE10,0x43328F67,0x58FF3249,0xF9208BE2,0x4CFD2D74,0xC35FDAD4,0x35BF6F71,0xFAE5B7A0,0xBF6B585F,0x62174D31,0xF3F637A2,0x2DABB312,0x8E122F24,0x09AB6B6A,0xF8A1BA7F,0x58536F92,0xD218D981,0xA8CD9E69,0xA026EF7C,0x5043CC71,0x9CD9128A,0x5DF531D8,0x3E63A010,0x12704453,0xE0E68948,0x33145C06,0x4611A626,0x7ED5110B,0x40000248,}} +#define __FLOATL_CONST_E__ (floatl){.u32={0xB9D8C78F,0xB71EA861,0xD7C9AB44,0xE6B0340E,0x519A853D,0x65C5C336,0x8994A2AF,0x02762A2E,0xCEB064CE,0x010F21E3,0x918433C4,0xBC0A4063,0xDADF484F,0x092C02FB,0x2D1BD529,0x4526C33A,0xA27E7AA8,0x4AB7655F,0x4C10B0B4,0xBE0AD033,0xBE98EBF6,0x0391D06F,0x4095051F,0x83DA377B,0x3F12995F,0xADBEC7AA,0x491FFB81,0x1AD0670A,0xCA89B2EA,0x2B97D612,0x454A5D96,0x27DB0E88,0x558C1599,0xD3CBD5E0,0x66527A41,0x6F39A985,0x8AC509B5,0x7F4390EF,0x344ED79F,0x345BBF15,0x78638707,0xBE49ACC2,0xB89AF3FA,0x68D79DAA,0x1B2AA9EF,0x3376842B,0x9FA8FAF8,0xEB2B0921,0xF8F6AEAF,0x230BD69E,0x0D901576,0x63AEC7B4,0x7F1B1B18,0xD9F7CBE9,0x9CEE7124,0x219FDE64,0x09B208A3,0x69B4AD4F,0xCE2C1E71,0xE9E78EC5,0xE2B10139,0xDA54D57E,0xC2A2C515,0x4000016F,}} #define __FLOATL_INT_ZERO__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}} #define __FLOATL_INF__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x7FFFFC00,}} #define __FLOATL_NAN__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xFFFFFC00,}} @@ -277,6 +351,9 @@ #define __FLOATL_HIDE_MANT_BIT__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00000400,}} #define __FLOATL_MANT_PLUS_MAX__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00002000,}} #define __FLOATL_MANT_WHL__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x000007FF,}} +#define __FLOATL_MIN__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00000400,}} +#define __FLOATL_MAX__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFFBFF,}} +#define __FLOATL_EPSILON__ (floatl){.u32={0x00000001,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}} #elif defined(FLOATL_USE_4096BITS) #define __FLOATL_BIT_PARTS__ 4096 #define __FLOATL_U32_PARTS__ 128 @@ -290,6 +367,13 @@ #define __FLOATL2_BIT_PARTS__ 8192 #define __FLOATL2_U32_PARTS__ 256 #define __FLOATL2_U16_PARTS__ 512 +#define __FLOATL_MANT_DIG__ 4073 +#define __FLOATL_MIN_EXP__ -4194301 +#define __FLOATL_MAX_EXP__ 4194304 +#define __FLOATL_DIG__ 1226 +#define __FLOATL_DECIMAL_DIG__ 1228 +#define __FLOATL_MIN_10_EXP__ -1262610 +#define __FLOATL_MAX_10_EXP__ 1262611 #define __FLOATL_CONST_0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xCC41E900,0x40002D6B,}} #define __FLOATL_CONST_1e15__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xBF526340,0x400030C6,}} +#define __FLOATL_CONST_PI__ (floatl){.u32={0x09D04E2E,0xEE9E0FCA,0x70619C33,0x6E7CED1D,0x364ACE19,0x769C35AB,0xDBCD06DA,0x3328066C,0xE4558EA7,0xED4DD871,0xB994BAD0,0x3848B057,0x4029E7B7,0x9EFADBEE,0xF9C007E1,0xDA2AD212,0xAE40FA26,0x1623E2C6,0x1A5FBFB2,0xD09F9A89,0x41C7C845,0xA1C89760,0xD441AE2A,0xFCF293CB,0x574CA12C,0xE95E6EDB,0x4E9B1704,0xA1295AEA,0xB14BD6A8,0x3048F0B8,0xCBA3E93F,0xB0DB0ECE,0x335FDBFE,0xF7DA4EC3,0x86DFDCE5,0x7A3E04F2,0x424839FB,0x5EAB17F6,0x0C42778F,0x25E46C86,0xD0222762,0xADE18ECE,0x8FA724BA,0x0DBCC018,0x77C059FB,0x615978F5,0x31F453F0,0x50F825B2,0x47E1DD52,0xEE295B12,0x38EE037B,0x89395A0A,0xAE3B96F9,0x0576CB57,0xD4D72F22,0xBFF0E223,0x91263C42,0x838F7A5F,0x4A291AE0,0x8DBBABCE,0x6CCEA80F,0x2A7F4216,0x34594062,0x49EBEDC6,0xBB44A13F,0xAD7C5833,0xF958DB02,0x272CEAD9,0xE72B77CA,0xA7F7A5FA,0x4D0F89BE,0x42ACDE42,0x79A13C0A,0x898BBEDD,0x33E37436,0x6ABFD29B,0x19FC0BE9,0x4AA79EC7,0xF7C9200E,0x8E732CB9,0x0B551C01,0x07F46E9D,0x1B2ECCC1,0x9C288875,0x20657477,0x076439AB,0x14C870F7,0x2E5DAF25,0xC356015C,0x062FE9FE,0xD80E338B,0x23BC08E9,0xD2ED131B,0xFC503BCC,0x2C7F523E,0xABA734D2,0xB4906C38,0xC77E0B31,0x00F97142,0xC8B67B84,0x50CCA3D9,0x963FCC92,0x3E4822F8,0x133F4B5D,0x70D7F6B5,0x0D6FDBDC,0xFEB96DE8,0x6FDAD617,0x9885D34C,0xBCFD8DE8,0x0B6AECC4,0xA3848BC9,0xC26ADADA,0xBE286E9F,0x5614DBE4,0x74863660,0x2A33679A,0x6809BBDF,0x9410F31C,0x273644A2,0x177D4C76,0xCF98E804,0x049C1114,0xB839A252,0x8CC51701,0xD1846989,0x1FB54442,0x40000092,}} +#define __FLOATL_CONST_E__ (floatl){.u32={0x4421F257,0xDF8B1786,0x3ED3B765,0x09FF3EE4,0xC7827867,0x54ADB7BC,0x63ACBE7C,0x190AC6C7,0x2D1F9878,0x20673F31,0xC62B9D87,0xC2C043AF,0x3CCB031A,0xE602308C,0xBE503559,0xF5C73020,0x9E89E856,0x11CFDBF7,0xA2578A7F,0x2028C6F2,0x98415FD8,0x48F8AA88,0xDFFE2FD3,0xE44CFB64,0xF9A1593A,0x4CC7F56F,0x0FFBC684,0x8493D309,0xF29597B4,0xA797B60B,0xE5448D2B,0x4FC63402,0xAB92341A,0x8E69510E,0xF8E1F18A,0xE89A6704,0x3B55ED1C,0x72D34ABB,0x7C2B9E37,0xB64E833C,0xB0087C3B,0x4EE1EAA0,0xEAED8E90,0xC9A60CA3,0xC9D27440,0x229447D9,0x5B7D35DB,0x30EBB2F9,0xEDA1E9EE,0x16338F09,0x37A472F0,0x68D5A00A,0x3FA5BF41,0x8EDC9270,0xC4822DDB,0xCDAF474E,0x178BE30D,0x3A0F5C17,0x53622DB2,0xEFB45E12,0xCCDCBD6E,0x69E9CFD2,0xA1F8D3A2,0xCC0C29D4,0x6E7631E3,0x2DC7AA18,0xB5F26AD1,0x79AC0D03,0x9466A14F,0xD97170CD,0xA26528AB,0x809D8A8B,0xF3AC1933,0x0043C878,0xE4610CF1,0xEF029018,0xF6B7D213,0x424B00BE,0x8B46F54A,0x1149B0CE,0xE89F9EAA,0x12ADD957,0xD3042C2D,0xAF82B40C,0xEFA63AFD,0xC0E4741B,0xD0254147,0xE0F68DDE,0x8FC4A657,0x6B6FB1EA,0x9247FEE0,0x86B419C2,0xB2A26CBA,0x8AE5F584,0x11529765,0x49F6C3A2,0x15630566,0x74F2F578,0x59949E90,0x5BCE6A61,0xE2B1426D,0xDFD0E43B,0x4D13B5E7,0xCD16EFC5,0x9E18E1C1,0xAF926B30,0xAE26BCFE,0xDA35E76A,0xC6CAAA7B,0x0CDDA10A,0x67EA3EBE,0xFACAC248,0xBE3DABAB,0x88C2F5A7,0x0364055D,0x18EBB1ED,0x5FC6C6C6,0x367DF2FA,0x273B9C49,0xC867F799,0xC26C8228,0x5A6D2B53,0x738B079C,0x7A79E3B1,0xB8AC404E,0x7695355F,0xF0A8B145,0x4000005B,}} #define __FLOATL_INT_ZERO__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFFEFF,}} +#define __FLOATL_EPSILON__ (floatl){.u32={0x00000001,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}} #elif defined(FLOATL_USE_8192BITS) #define __FLOATL_BIT_PARTS__ 8192 #define __FLOATL_U32_PARTS__ 256 @@ -331,6 +420,13 @@ #define __FLOATL2_BIT_PARTS__ 16384 #define __FLOATL2_U32_PARTS__ 512 #define __FLOATL2_U16_PARTS__ 1024 +#define __FLOATL_MANT_DIG__ 8167 +#define __FLOATL_MIN_EXP__ -16777213 +#define __FLOATL_MAX_EXP__ 16777216 +#define __FLOATL_DIG__ 2458 +#define __FLOATL_DECIMAL_DIG__ 2460 +#define __FLOATL_MIN_10_EXP__ -5050444 +#define __FLOATL_MAX_10_EXP__ 5050445 #define __FLOATL_CONST_0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xAFD498D0,0x40000C31,}} +#define __FLOATL_CONST_PI__ (floatl){.u32={0x9C2CD1AE,0x1A49273E,0x758B6F50,0x4C26F654,0x98DADC16,0xABE190C4,0xC2EC1722,0x7DD13E77,0xFC60F894,0x55666571,0x26141C6B,0xF95FA909,0x53E461E4,0x9AC95E9D,0x5A7EE3FE,0x651AD83B,0xC41183F0,0x5B0FD780,0xFF8A994D,0x514F427D,0xB7AFAA44,0x7C9266A7,0x43AC302B,0x636D4A44,0xFA0BB1A9,0xF18E43E7,0xA36089A9,0x03ABA8A3,0x43CB9D65,0x90FF026D,0x2588F418,0x1195C5FE,0xCABF5CB5,0x3ED55BC5,0xFDFF892D,0xE6295487,0x6082D811,0x104F0765,0x4FED8ADE,0x67CDB82C,0x1D26FE93,0xEB33FB4E,0xF0312AB8,0x07E2C738,0xDA79A468,0x2085F25E,0xEB51BBE8,0x9BCC1EB0,0x8088C503,0x5DC1B7C7,0x719B8516,0x6E7BE084,0x8632770B,0x8E15E3D6,0x1E8D8CAD,0x64F6877C,0xB8A4F4CA,0xC99E74F0,0xF4869A45,0x4F4BBCDE,0x1E5B9CA1,0xCAA162CE,0x9AB8A43B,0xD278BEF3,0x8A01DCFE,0x63531A24,0xC64F665D,0x452F0D95,0x6CEECF10,0xF599FFFC,0xEBB4D8D3,0xE097575F,0x1E738FD2,0xA9D1F739,0xA2FF206F,0x9A2AE76B,0x73CEDF78,0x3C2CE3F6,0xD68CD701,0xB92F784F,0x5F576E87,0xB8907D8D,0xCB78FF8C,0x67A0054E,0x13B54016,0xF474ACD4,0x76A9A352,0xB5C16CBF,0xC9F1FF48,0xEAB0959E,0x28A6F348,0x2DEC8E5B,0xE6327731,0x36258CEE,0x0CA171DB,0x9AFE82FB,0xDA56A34E,0x3A7183CF,0xFB67B16B,0x76A4514C,0x949B6756,0x497359D9,0x2977C533,0x9A5B6583,0x22447C1C,0x398715C4,0x5F65A81E,0x58E96680,0x1D20B4C3,0xDBDCD195,0x002894FA,0xCE5490D1,0xC065EC94,0xB0EA0B7C,0xBF640DBD,0x3493F6EB,0x0292BE03,0x3F72B3ED,0x945F25A0,0xDB5E44C0,0xF69B7A50,0x0894ACE9,0x10286D98,0x07E122C6,0xCAFC221E,0xF3518ACB,0x292A812B,0xB6CEF6A5,0x8274138B,0xFBA783F2,0x5C18670C,0x5B9F3B47,0xCD92B386,0x9DA70D6A,0x36F341B6,0xCCCA019B,0x791563A9,0x3B53761C,0xEE652EB4,0xCE122C15,0x900A79ED,0x67BEB6FB,0xBE7001F8,0xB68AB484,0xAB903E89,0x8588F8B1,0x4697EFEC,0x7427E6A2,0x1071F211,0xA87225D8,0xF5106B8A,0x3F3CA4F2,0xD5D3284B,0x3A579BB6,0x93A6C5C1,0x284A56BA,0x2C52F5AA,0xCC123C2E,0xB2E8FA4F,0xAC36C3B3,0xCCD7F6FF,0x7DF693B0,0xA1B7F739,0xDE8F813C,0x90920E7E,0xD7AAC5FD,0x83109DE3,0x89791B21,0xB40889D8,0xAB7863B3,0x23E9C92E,0xC36F3006,0x5DF0167E,0x18565E3D,0x8C7D14FC,0x943E096C,0x91F87754,0xFB8A56C4,0x8E3B80DE,0x624E5682,0xEB8EE5BE,0x815DB2D5,0xF535CBC8,0xAFFC3888,0xE4498F10,0x20E3DE97,0x928A46B8,0xE36EEAF3,0x9B33AA03,0x8A9FD085,0x8D165018,0xD27AFB71,0xEED1284F,0xAB5F160C,0x7E5636C0,0x89CB3AB6,0xB9CADDF2,0xA9FDE97E,0x9343E26F,0x90AB3790,0x5E684F02,0xA262EFB7,0xCCF8DD0D,0x5AAFF4A6,0xC67F02FA,0x92A9E7B1,0x7DF24803,0x639CCB2E,0x42D54700,0x41FD1BA7,0x46CBB330,0xE70A221D,0xC8195D1D,0xC1D90E6A,0x45321C3D,0x0B976BC9,0xB0D58057,0xC18BFA7F,0x76038CE2,0xC8EF023A,0x34BB44C6,0xBF140EF3,0x8B1FD48F,0x2AE9CD34,0x6D241B0E,0xB1DF82CC,0x003E5C50,0x722D9EE1,0x943328F6,0x258FF324,0x4F9208BE,0x44CFD2D7,0x1C35FDAD,0x035BF6F7,0xFFAE5B7A,0x1BF6B585,0x262174D3,0x2F3F637A,0x42DABB31,0xA8E122F2,0xF09AB6B6,0x2F8A1BA7,0x158536F9,0x9D218D98,0xCA8CD9E6,0x1A026EF7,0xA5043CC7,0x89CD9128,0x05DF531D,0x33E63A01,0x81270445,0x6E0E6894,0x633145C0,0xB4611A62,0x87ED5110,0x40000024,}} +#define __FLOATL_CONST_E__ (floatl){.u32={0xFAAD8AAF,0x3FD5E768,0xB47C0A93,0xDE5F5989,0x24202B66,0x0DC1F079,0xCF6A53B2,0xC885E304,0x6AE4DD21,0x3B674EA8,0xCD003B9F,0x8C731AB7,0xB0145B3A,0x7F6B920D,0xD535712A,0x62EC6A3C,0x3BDE3CC9,0x4DD598A1,0x7AD6489E,0xC0A1938D,0x2146B676,0x39730E75,0x427A6EE3,0x0B719F87,0x2FACBDD2,0xB2377726,0x19E38039,0x19128D46,0x34DF3988,0x9B12EC4C,0xFBB08AA3,0x54E5CC9F,0x7D0B9232,0xE0015554,0x8EC67DE1,0xF83501D1,0x565EFA2C,0xA081F19F,0x2A9278B4,0xDAB2E692,0x0ABCF371,0xA1235AED,0x17BAA797,0x610BEE8A,0x8913240B,0x6A2A7D65,0x1810BF4D,0x13755DAF,0x2A4F9351,0xCC677CA9,0x80E85B5C,0xE499660B,0x795BD1EA,0xF149A409,0x2A619C16,0xA756A1A4,0x45475F42,0x42CB6721,0xE64E4D44,0xC36FCFF2,0xE8AD137C,0x119DB35F,0xFE0FB0B6,0x1D2D6310,0xF8CA8257,0xFBF3D4E4,0x16F713E8,0x52E6FF37,0xC2EED18B,0x3ACF3777,0xF4554586,0x463E7328,0xB9563799,0x0D5408B0,0x35FB5A85,0x493ABA6C,0xC52BA2B3,0xB8A91B40,0x03C8FFC2,0xC49A62E6,0x3AA13697,0xFB7A19D5,0x0E7CD4D8,0x26A659A3,0x578D57B3,0xE47CB73D,0x99AD79A0,0x82A05A44,0x08DD6DC0,0xE152E571,0x903CACE5,0x2FC52810,0xCD7241C1,0x1152503E,0x04E34A0C,0x47BB1A50,0xC11FE305,0xD0736795,0x8D3F779A,0xBFE9A38A,0xEF258824,0x7FE04370,0x6A134F50,0x1A54410E,0x01FBBE7C,0x146E3FDC,0x412376D8,0x109EAD43,0x9E8C9B34,0xC889E1C7,0xB94CDAFA,0x725F35FB,0x524DCF2E,0x08156894,0xDE647A24,0xBAC8F02C,0xC0ACE08E,0x949E8DCA,0x1E27BF23,0x8CB32385,0xDDA2A19A,0x4024E593,0xC47E6CE0,0x7AA2CEDD,0xF9ABB3FA,0xDF071945,0x73470DE9,0xE3225798,0x91087C95,0x77E2C5E1,0x0FB4EDD9,0xC27FCFB9,0x31E09E19,0x152B6DEF,0xD8EB2F9F,0x0642B1B1,0x4B47E61E,0xC819CFCC,0xF18AE761,0xB0B010EB,0x0F32C0C6,0x79808C23,0x2F940D56,0xBD71CC08,0xE7A27A15,0xC473F6FD,0xA895E29F,0x080A31BC,0x261057F6,0xD23E2AA2,0x37FF8BF4,0xB9133ED9,0xFE68564E,0x1331FD5B,0x43FEF1A1,0x2124F4C2,0xFCA565ED,0xE9E5ED82,0xB951234A,0x93F18D00,0xAAE48D06,0xA39A5443,0x3E387C62,0x3A2699C1,0xCED57B47,0xDCB4D2AE,0x1F0AE78D,0xED93A0CF,0x2C021F0E,0x13B87AA8,0xFABB63A4,0x32698328,0x72749D10,0xC8A511F6,0x56DF4D76,0x8C3AECBE,0x7B687A7B,0x058CE3C2,0x8DE91CBC,0x5A356802,0x0FE96FD0,0xE3B7249C,0xB1208B76,0x736BD1D3,0xC5E2F8C3,0x8E83D705,0x94D88B6C,0xBBED1784,0xB3372F5B,0x9A7A73F4,0x287E34E8,0xF3030A75,0x1B9D8C78,0x4B71EA86,0xED7C9AB4,0xDE6B0340,0x6519A853,0xF65C5C33,0xE8994A2A,0xE02762A2,0x3CEB064C,0x4010F21E,0x3918433C,0xFBC0A406,0xBDADF484,0x9092C02F,0xA2D1BD52,0x84526C33,0xFA27E7AA,0x44AB7655,0x34C10B0B,0x6BE0AD03,0xFBE98EBF,0xF0391D06,0xB4095051,0xF83DA377,0xA3F12995,0x1ADBEC7A,0xA491FFB8,0xA1AD0670,0x2CA89B2E,0x62B97D61,0x8454A5D9,0x927DB0E8,0x0558C159,0x1D3CBD5E,0x566527A4,0x56F39A98,0xF8AC509B,0xF7F4390E,0x5344ED79,0x7345BBF1,0x27863870,0xABE49ACC,0xAB89AF3F,0xF68D79DA,0xB1B2AA9E,0x83376842,0x19FA8FAF,0xFEB2B092,0xEF8F6AEA,0x6230BD69,0x40D90157,0x863AEC7B,0x97F1B1B1,0x4D9F7CBE,0x49CEE712,0x3219FDE6,0xF09B208A,0x169B4AD4,0x5CE2C1E7,0x9E9E78EC,0xEE2B1013,0x5DA54D57,0xFC2A2C51,0x40000016,}} #define __FLOATL_INT_ZERO__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFFFBF,}} +#define __FLOATL_EPSILON__ (floatl){.u32={0x00000001,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}} #endif /*****************************************************************/ /* Config end */ @@ -373,19 +474,27 @@ typedef struct { uint32_t buffer[256]; - uint32_t FLOATL_BIT_PARTS; // bits - uint32_t FLOATL_U32_PARTS; // FLOATL_BIT_PARTS / 32 ---- FLOATL_BIT_PARTS >> 5 - uint32_t FLOATL_U16_PARTS; // FLOATL_BIT_PARTS / 16 ---- FLOATL_BIT_PARTS >> 4 - uint32_t FLOATL_EXP_BITS; // floatl_cfg_gen_exp(FLOATL_BIT_PARTS) - uint32_t FLOATL_MANT_BITS; // FLOATL_BIT_PARTS - FLOATL_EXP_BITS - 1 - uint32_t FLOATL_MANT_PARTS; // FLOATL_MANT_BITS / 32 ---- FLOATL_MANT_BITS >> 5 - uint32_t FLOATL_MANT_HIGH_BITS; // FLOATL_MANT_BITS % 32 ---- FLOATL_MANT_BITS & 0x1F - uint32_t FLOATL_EXP_MID_VALUE; // 2^(FLOATL_EXP_BITS-1) - 1 - uint32_t FLOATL_EXP_WHL_VALUE; // 2^(FLOATL_EXP_BITS) - 1 + uint32_t FLOATL_BIT_PARTS__; // bits + uint32_t FLOATL_U32_PARTS__; // FLOATL_BIT_PARTS__ / 32 ---- FLOATL_BIT_PARTS__ >> 5 + uint32_t FLOATL_U16_PARTS__; // FLOATL_BIT_PARTS__ / 16 ---- FLOATL_BIT_PARTS__ >> 4 + uint32_t FLOATL_EXP_BITS__; // floatl_cfg_gen_exp(FLOATL_BIT_PARTS__) + uint32_t FLOATL_MANT_BITS__; // FLOATL_BIT_PARTS__ - FLOATL_EXP_BITS__ - 1 + uint32_t FLOATL_MANT_PARTS__; // FLOATL_MANT_BITS__ / 32 ---- FLOATL_MANT_BITS__ >> 5 + uint32_t FLOATL_MANT_HIGH_BITS__; // FLOATL_MANT_BITS__ % 32 ---- FLOATL_MANT_BITS__ & 0x1F + uint32_t FLOATL_EXP_MID_VALUE__; // 2^(FLOATL_EXP_BITS__-1) - 1 + uint32_t FLOATL_EXP_WHL_VALUE__; // 2^(FLOATL_EXP_BITS__) - 1 - uint32_t FLOATL2_BIT_PARTS; // FLOATL_BIT_PARTS * 2 - uint32_t FLOATL2_U32_PARTS; // FLOATL2_BIT_PARTS / 32 ---- FLOATL2_BIT_PARTS >> 5 - uint32_t FLOATL2_U16_PARTS; // FLOATL2_BIT_PARTS / 16 ---- FLOATL2_BIT_PARTS >> 4 + uint32_t FLOATL2_BIT_PARTS__; // FLOATL_BIT_PARTS__ * 2 + uint32_t FLOATL2_U32_PARTS__; // FLOATL2_BIT_PARTS__ / 32 ---- FLOATL2_BIT_PARTS__ >> 5 + uint32_t FLOATL2_U16_PARTS__; // FLOATL2_BIT_PARTS__ / 16 ---- FLOATL2_BIT_PARTS__ >> 4 + + uint32_t FLOATL_MANT_DIG__; // FLOATL_MANT_BITS__ + 1 + int32_t FLOATL_MIN_EXP__; // - FLOATL_EXP_MID_VALUE__ + 2 + uint32_t FLOATL_MAX_EXP__; // FLOATL_EXP_MID_VALUE__ + 1 + uint32_t FLOATL_DIG__; // floor(log10(2) * FLOATL_MANT_DIG__) + uint32_t FLOATL_DECIMAL_DIG__; // ceil(log10(2) * FLOATL_MANT_DIG__) + 1 + int32_t FLOATL_MIN_10_EXP__; // ceil(log10(2) * (1 - FLOATL_EXP_MID_VALUE__)) + uint32_t FLOATL_MAX_10_EXP__; // - FLOATL_MIN_10_EXP__ + 1 } FLINFO; typedef struct @@ -449,7 +558,7 @@ void floatl_cfg_const_out(FILE* file, FLINFO *info) if (!file || !info) return; fprintf(file, "(floatl){.u32={"); - for (int i = 0; i < info->FLOATL_U32_PARTS; i++) + for (int i = 0; i < info->FLOATL_U32_PARTS__; i++) { uint32_t value = info->buffer[i]; if (value == 0) fprintf(file, "0,"); @@ -463,28 +572,35 @@ int floatl_cfg_info_init(FLINFO *info, unsigned int bits) { if ((bits & (bits - 1)) != 0) return 0; - info->FLOATL_BIT_PARTS = bits; - info->FLOATL_U32_PARTS = info->FLOATL_BIT_PARTS >> (5); - info->FLOATL_U16_PARTS = info->FLOATL_BIT_PARTS >> (4); - info->FLOATL_EXP_BITS = floatl_cfg_gen_exp(info->FLOATL_BIT_PARTS); - info->FLOATL_MANT_BITS = info->FLOATL_BIT_PARTS - info->FLOATL_EXP_BITS - 1; - info->FLOATL_MANT_PARTS = info->FLOATL_MANT_BITS >> 5; - info->FLOATL_MANT_HIGH_BITS = info->FLOATL_MANT_BITS & 0x1F; - info->FLOATL_EXP_MID_VALUE = (uint32_t)pow(2, info->FLOATL_EXP_BITS - 1) - 1; - info->FLOATL_EXP_WHL_VALUE = (uint32_t)pow(2, info->FLOATL_EXP_BITS) - 1; - info->FLOATL2_BIT_PARTS = info->FLOATL_BIT_PARTS * 2; - info->FLOATL2_U32_PARTS = info->FLOATL2_BIT_PARTS >> (5); - info->FLOATL2_U16_PARTS = info->FLOATL2_BIT_PARTS >> (4); + info->FLOATL_BIT_PARTS__ = bits; + info->FLOATL_U32_PARTS__ = info->FLOATL_BIT_PARTS__ >> (5); + info->FLOATL_U16_PARTS__ = info->FLOATL_BIT_PARTS__ >> (4); + info->FLOATL_EXP_BITS__ = floatl_cfg_gen_exp(info->FLOATL_BIT_PARTS__); + info->FLOATL_MANT_BITS__ = info->FLOATL_BIT_PARTS__ - info->FLOATL_EXP_BITS__ - 1; + info->FLOATL_MANT_PARTS__ = info->FLOATL_MANT_BITS__ >> 5; + info->FLOATL_MANT_HIGH_BITS__ = info->FLOATL_MANT_BITS__ & 0x1F; + info->FLOATL_EXP_MID_VALUE__ = (uint32_t)pow(2, info->FLOATL_EXP_BITS__ - 1) - 1; + info->FLOATL_EXP_WHL_VALUE__ = (uint32_t)pow(2, info->FLOATL_EXP_BITS__) - 1; + info->FLOATL2_BIT_PARTS__ = info->FLOATL_BIT_PARTS__ * 2; + info->FLOATL2_U32_PARTS__ = info->FLOATL2_BIT_PARTS__ >> (5); + info->FLOATL2_U16_PARTS__ = info->FLOATL2_BIT_PARTS__ >> (4); + info->FLOATL_MANT_DIG__ = info->FLOATL_MANT_BITS__ + 1; + info->FLOATL_MIN_EXP__ = - info->FLOATL_EXP_MID_VALUE__ + 2; + info->FLOATL_MAX_EXP__ = info->FLOATL_EXP_MID_VALUE__ + 1; + info->FLOATL_DIG__ = floor(log10(2) * info->FLOATL_MANT_DIG__); + info->FLOATL_DECIMAL_DIG__ = ceil(log10(2) * info->FLOATL_MANT_DIG__) + 1; + info->FLOATL_MIN_10_EXP__ = ceil(log10(2) * (int32_t)(1 - info->FLOATL_EXP_MID_VALUE__)); + info->FLOATL_MAX_10_EXP__ = - info->FLOATL_MIN_10_EXP__ + 1; - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); return 1; } FLINFO *floatl_cfg_set_sign(FLINFO *info, int sign) { - if (sign) info->buffer[info->FLOATL_U32_PARTS - 1] |= (1 << 31); - else info->buffer[info->FLOATL_U32_PARTS - 1] &= ~(1 << 31); + if (sign) info->buffer[info->FLOATL_U32_PARTS__ - 1] |= (1 << 31); + else info->buffer[info->FLOATL_U32_PARTS__ - 1] &= ~(1 << 31); return info; } @@ -492,25 +608,25 @@ FLINFO *floatl_cfg_set_exp_real(FLINFO *info, uint32_t t) { uint32_t temp = 1; - temp <<= info->FLOATL_EXP_BITS; + temp <<= info->FLOATL_EXP_BITS__; temp -= 1; t &= temp; - t <<= (32 - info->FLOATL_EXP_BITS - 1); + t <<= (32 - info->FLOATL_EXP_BITS__ - 1); - temp <<= (32 - info->FLOATL_EXP_BITS - 1); + temp <<= (32 - info->FLOATL_EXP_BITS__ - 1); - info->buffer[info->FLOATL_U32_PARTS - 1] &= (~temp); // clear + info->buffer[info->FLOATL_U32_PARTS__ - 1] &= (~temp); // clear - info->buffer[info->FLOATL_U32_PARTS - 1] |= t; + info->buffer[info->FLOATL_U32_PARTS__ - 1] |= t; return info; } FLINFO *floatl_cfg_set_exp(FLINFO *info, int32_t e) { - return floatl_cfg_set_exp_real(info, e + info->FLOATL_EXP_MID_VALUE); + return floatl_cfg_set_exp_real(info, e + info->FLOATL_EXP_MID_VALUE__); } FLINFO *floatl_cfg_set_mant(FLINFO *info, char *bin) @@ -519,7 +635,7 @@ FLINFO *floatl_cfg_set_mant(FLINFO *info, char *bin) while (*s) { - int index = info->FLOATL_MANT_BITS - (s - bin) - 1; + int index = info->FLOATL_MANT_BITS__ - (s - bin) - 1; if (index < 0) break; if (index >= 0 && *s == '1') { @@ -536,24 +652,24 @@ FLINFO *floatl_cfg_set_mant(FLINFO *info, char *bin) FLINFO *floatl_cfg_int_zero(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); return info; } FLINFO *floatl_cfg_const_0(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); return info; } FLINFO *floatl_cfg_const_1(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 0xFFFFFFFF); - info->buffer[info->FLOATL_U32_PARTS - 1] &= 0xBFFFFFFF; + info->buffer[info->FLOATL_U32_PARTS__ - 1] &= 0xBFFFFFFF; return info; } @@ -562,7 +678,7 @@ FLINFO *floatl_cfg_const_1eX(FLINFO *info, uint32_t e) { if (e >= sizeof(fle_list) / sizeof(fle_list[0])) return NULL; - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp(info, fle_list[e].exp); floatl_cfg_set_mant(info, fle_list[e].mantBin); @@ -570,9 +686,29 @@ FLINFO *floatl_cfg_const_1eX(FLINFO *info, uint32_t e) return info; } +FLINFO *floatl_cfg_const_pi(FLINFO *info) +{ + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); + + floatl_cfg_set_exp(info, 1); + floatl_cfg_set_mant(info, FLOATL_CFG_MANT_PI); + + return info; +} + +FLINFO *floatl_cfg_const_e(FLINFO *info) +{ + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); + + floatl_cfg_set_exp(info, 1); + floatl_cfg_set_mant(info, FLOATL_CFG_MANT_E); + + return info; +} + FLINFO *floatl_cfg_inf(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 0xFFFFFFFF); @@ -581,26 +717,26 @@ FLINFO *floatl_cfg_inf(FLINFO *info) FLINFO *floatl_cfg_nan(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 0xFFFFFFFF); - info->buffer[info->FLOATL_U32_PARTS - 1] |= 0x80000000; + info->buffer[info->FLOATL_U32_PARTS__ - 1] |= 0x80000000; return info; } FLINFO *floatl_cfg_all_sign(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); - info->buffer[info->FLOATL_U32_PARTS - 1] |= 0x80000000; + info->buffer[info->FLOATL_U32_PARTS__ - 1] |= 0x80000000; return info; } FLINFO *floatl_cfg_all_exp(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 0xFFFFFFFF); @@ -609,26 +745,26 @@ FLINFO *floatl_cfg_all_exp(FLINFO *info) FLINFO *floatl_cfg_all_mant(FLINFO *info) { - memset(info->buffer, -1, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, -1, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 0); - info->buffer[info->FLOATL_U32_PARTS - 1] &= (~0x80000000); + info->buffer[info->FLOATL_U32_PARTS__ - 1] &= (~0x80000000); return info; } FLINFO *floatl_cfg_all_exp_mant(FLINFO *info) { - memset(info->buffer, -1, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, -1, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); - info->buffer[info->FLOATL_U32_PARTS - 1] &= (~0x80000000); + info->buffer[info->FLOATL_U32_PARTS__ - 1] &= (~0x80000000); return info; } FLINFO *floatl_cfg_hide_mant_bit(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 1); @@ -637,7 +773,7 @@ FLINFO *floatl_cfg_hide_mant_bit(FLINFO *info) FLINFO *floatl_cfg_mant_plus_max(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 8); @@ -646,10 +782,38 @@ FLINFO *floatl_cfg_mant_plus_max(FLINFO *info) FLINFO *floatl_cfg_mant_whole(FLINFO *info) { - memset(info->buffer, -1, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, -1, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 1); - info->buffer[info->FLOATL_U32_PARTS - 1] &= (~0x80000000); + info->buffer[info->FLOATL_U32_PARTS__ - 1] &= (~0x80000000); + + return info; +} + +FLINFO *floatl_cfg_min(FLINFO *info) +{ + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); + + floatl_cfg_set_exp_real(info, 1); + + return info; +} + +FLINFO *floatl_cfg_max(FLINFO *info) +{ + memset(info->buffer, -1, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); + + floatl_cfg_set_sign(info, 0); + floatl_cfg_set_exp_real(info, 0xFFFFFFFE); + + return info; +} + +FLINFO *floatl_cfg_epsilon(FLINFO *info) +{ + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); + + info->buffer[0] |= 1; return info; } @@ -677,6 +841,13 @@ void floatl_cfg_generate(uint32_t bits, const char *filename) return; } + /* Enable PI and E mant configurations */ + if (!FLOATL_CFG_MANT_PI || !FLOATL_CFG_MANT_E) + { + fprintf(stdout, "[ERROR] Enable `FLOATL_CFG_MANT_PI` and `FLOATL_CFG_MANT_E` in `floatl_cfg.h` file"NEWLINE); + return; + } + /* Limiting the minimum bit */ if (bits < MINBITS) { @@ -717,19 +888,27 @@ void floatl_cfg_generate(uint32_t bits, const char *filename) FLINFO info; floatl_cfg_info_init(&info, tb); - fprintf(output, "#define __FLOATL_BIT_PARTS__ %u"NEWLINE, info.FLOATL_BIT_PARTS ); - fprintf(output, "#define __FLOATL_U32_PARTS__ %u"NEWLINE, info.FLOATL_U32_PARTS ); - fprintf(output, "#define __FLOATL_U16_PARTS__ %u"NEWLINE, info.FLOATL_U16_PARTS ); - fprintf(output, "#define __FLOATL_EXP_BITS__ %u"NEWLINE, info.FLOATL_EXP_BITS ); - fprintf(output, "#define __FLOATL_MANT_BITS__ %u"NEWLINE, info.FLOATL_MANT_BITS ); - fprintf(output, "#define __FLOATL_MANT_PARTS__ %u"NEWLINE, info.FLOATL_MANT_PARTS ); - fprintf(output, "#define __FLOATL_MANT_HIGH_BITS__ %u"NEWLINE, info.FLOATL_MANT_HIGH_BITS ); - fprintf(output, "#define __FLOATL_EXP_MID_VALUE__ %u"NEWLINE, info.FLOATL_EXP_MID_VALUE ); - fprintf(output, "#define __FLOATL_EXP_WHL_VALUE__ %u"NEWLINE, info.FLOATL_EXP_WHL_VALUE ); + fprintf(output, "#define __FLOATL_BIT_PARTS__ %u"NEWLINE, info.FLOATL_BIT_PARTS__ ); + fprintf(output, "#define __FLOATL_U32_PARTS__ %u"NEWLINE, info.FLOATL_U32_PARTS__ ); + fprintf(output, "#define __FLOATL_U16_PARTS__ %u"NEWLINE, info.FLOATL_U16_PARTS__ ); + fprintf(output, "#define __FLOATL_EXP_BITS__ %u"NEWLINE, info.FLOATL_EXP_BITS__ ); + fprintf(output, "#define __FLOATL_MANT_BITS__ %u"NEWLINE, info.FLOATL_MANT_BITS__ ); + fprintf(output, "#define __FLOATL_MANT_PARTS__ %u"NEWLINE, info.FLOATL_MANT_PARTS__ ); + fprintf(output, "#define __FLOATL_MANT_HIGH_BITS__ %u"NEWLINE, info.FLOATL_MANT_HIGH_BITS__ ); + fprintf(output, "#define __FLOATL_EXP_MID_VALUE__ %u"NEWLINE, info.FLOATL_EXP_MID_VALUE__ ); + fprintf(output, "#define __FLOATL_EXP_WHL_VALUE__ %u"NEWLINE, info.FLOATL_EXP_WHL_VALUE__ ); - fprintf(output, "#define __FLOATL2_BIT_PARTS__ %u"NEWLINE, info.FLOATL2_BIT_PARTS ); - fprintf(output, "#define __FLOATL2_U32_PARTS__ %u"NEWLINE, info.FLOATL2_U32_PARTS ); - fprintf(output, "#define __FLOATL2_U16_PARTS__ %u"NEWLINE, info.FLOATL2_U16_PARTS ); + fprintf(output, "#define __FLOATL2_BIT_PARTS__ %u"NEWLINE, info.FLOATL2_BIT_PARTS__ ); + fprintf(output, "#define __FLOATL2_U32_PARTS__ %u"NEWLINE, info.FLOATL2_U32_PARTS__ ); + fprintf(output, "#define __FLOATL2_U16_PARTS__ %u"NEWLINE, info.FLOATL2_U16_PARTS__ ); + + fprintf(output, "#define __FLOATL_MANT_DIG__ %u"NEWLINE, info.FLOATL_MANT_DIG__ ); + fprintf(output, "#define __FLOATL_MIN_EXP__ %d"NEWLINE, info.FLOATL_MIN_EXP__ ); + fprintf(output, "#define __FLOATL_MAX_EXP__ %u"NEWLINE, info.FLOATL_MAX_EXP__ ); + fprintf(output, "#define __FLOATL_DIG__ %u"NEWLINE, info.FLOATL_DIG__ ); + fprintf(output, "#define __FLOATL_DECIMAL_DIG__ %u"NEWLINE, info.FLOATL_DECIMAL_DIG__ ); + fprintf(output, "#define __FLOATL_MIN_10_EXP__ %d"NEWLINE, info.FLOATL_MIN_10_EXP__ ); + fprintf(output, "#define __FLOATL_MAX_10_EXP__ %u"NEWLINE, info.FLOATL_MAX_10_EXP__ ); fprintf(output, "#define __FLOATL_CONST_0__ "); floatl_cfg_const_out(output, floatl_cfg_const_0(&info) ); fprintf(output, "#define __FLOATL_CONST_1__ "); floatl_cfg_const_out(output, floatl_cfg_const_1(&info) ); @@ -749,6 +928,8 @@ void floatl_cfg_generate(uint32_t bits, const char *filename) fprintf(output, "#define __FLOATL_CONST_1e13__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,13) ); fprintf(output, "#define __FLOATL_CONST_1e14__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,14) ); fprintf(output, "#define __FLOATL_CONST_1e15__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,15) ); + fprintf(output, "#define __FLOATL_CONST_PI__ "); floatl_cfg_const_out(output, floatl_cfg_const_pi(&info) ); + fprintf(output, "#define __FLOATL_CONST_E__ "); floatl_cfg_const_out(output, floatl_cfg_const_e(&info) ); fprintf(output, "#define __FLOATL_INT_ZERO__ "); floatl_cfg_const_out(output, floatl_cfg_int_zero(&info) ); fprintf(output, "#define __FLOATL_INF__ "); floatl_cfg_const_out(output, floatl_cfg_inf(&info) ); fprintf(output, "#define __FLOATL_NAN__ "); floatl_cfg_const_out(output, floatl_cfg_nan(&info) ); @@ -759,6 +940,9 @@ void floatl_cfg_generate(uint32_t bits, const char *filename) fprintf(output, "#define __FLOATL_HIDE_MANT_BIT__ "); floatl_cfg_const_out(output, floatl_cfg_hide_mant_bit(&info) ); fprintf(output, "#define __FLOATL_MANT_PLUS_MAX__ "); floatl_cfg_const_out(output, floatl_cfg_mant_plus_max(&info) ); fprintf(output, "#define __FLOATL_MANT_WHL__ "); floatl_cfg_const_out(output, floatl_cfg_mant_whole(&info) ); + fprintf(output, "#define __FLOATL_MIN__ "); floatl_cfg_const_out(output, floatl_cfg_min(&info) ); + fprintf(output, "#define __FLOATL_MAX__ "); floatl_cfg_const_out(output, floatl_cfg_max(&info) ); + fprintf(output, "#define __FLOATL_EPSILON__ "); floatl_cfg_const_out(output, floatl_cfg_epsilon(&info) ); } fprintf(output, "#endif"NEWLINE); @@ -777,8 +961,6 @@ void floatl_cfg_generate(uint32_t bits, const char *filename) { printf("[INFO] The configuration has been generated, copy it to the `floatl_cfg.h` range specified\r\n"); } - - return 0; } /*----------------------------------------------------------------------------------*/ diff --git a/test/test.mk b/test/test.mk index 975fea2..61a6aaa 100644 --- a/test/test.mk +++ b/test/test.mk @@ -38,6 +38,7 @@ TEST_LIST += dList TEST_LIST += cQueue TEST_LIST += intl TEST_LIST += floatl +TEST_LIST += flmath TEST_LIST += ramt TEST_LIST += romt # TEST_LIST += cpul diff --git a/test/test_flmath.c b/test/test_flmath.c new file mode 100644 index 0000000..783c584 --- /dev/null +++ b/test/test_flmath.c @@ -0,0 +1,190 @@ +#include +#include +#include +#include +#include +#include +#if defined(TEST_TARGET_flmath) +#include +#include +#include +#else +#include "init.h" +#include "command.h" +#include "unitt.h" +#include "kern.h" +#include "flmath.h" +#endif + +static char buffer[1024] = {0}; + +/************************************************************************************/ +/************************************* Unit Test ************************************/ +/************************************************************************************/ + +// #define EXIT_TEST +extern uint64_t unitt_clock(void); + +static int u_test_0(void) +{ + for (int i = 0; i < 1000; i++) + { + + } + + return UNITT_E_OK; +} + +static void unitt_task(void) +{ + static UNITT_TCASE rand_tests[] = { + UNITT_TCASE(u_test_0), + }; + + static UNITT suites[] = { + { "flmath suite", rand_tests, sizeof(rand_tests) / sizeof(rand_tests[0]) , unitt_clock }, + }; + + UNITT_EXE(suites); +} + +/************************************************************************************/ +/************************************* Base Test ************************************/ +/************************************************************************************/ + +static void test_base(void) +{ + floatl p = floatl_mul(FLOATL_PI, floatl(1.0 / 2.0)); + + floatl sin = floatl_sin(p); + printf("sin %s\r\n", floatl_show(sin, buffer, sizeof(buffer), "%f")); + + floatl cos = floatl_cos(p); + printf("cos %s\r\n", floatl_show(cos, buffer, sizeof(buffer), "%f")); + + floatl tan = floatl_tan(p); + printf("tan %s\r\n", floatl_show(tan, buffer, sizeof(buffer), "%f")); + + floatl exp = floatl_exp(floatl(0.0)); + printf("exp %s\r\n", floatl_show(exp, buffer, sizeof(buffer), "%f")); + + floatl log = floatl_ln(floatl(1.0)); + printf("log %s\r\n", floatl_show(log, buffer, sizeof(buffer), "%f")); + + floatl sqrt = floatl_sqrt(floatl(3.0)); + printf("sqrt %s\r\n", floatl_show(sqrt, buffer, sizeof(buffer), "%f")); + + floatl pow = floatl_pow(floatl(2.0), floatl(3.0)); + printf("pow %s\r\n", floatl_show(pow, buffer, sizeof(buffer), "%f")); +} + +/************************************************************************************/ +/************************************* Command ************************************/ +/************************************************************************************/ + +static void usage(void) +{ + printf( +"Usage: floatl [opt] [arg] ...\n" +"\n" +"options:\n" +" -e Specifies the function to execute, the default is the test\n" +" Test base function\n" +" Unit test\n" +" Test define function\n" +" Calculate string math expression\n" +" Generate the floatl configuration file code segment, need specify -f -b\n" +" Print an floatl number\n" +" Function that tests for floatl errors\n" +" -l Format string, 10d, 08x, ...\n" +" -o Operate function, add, sub, mul, div, ...\n" +" -n floatl number expression\n" +" -f File name, temporarily store configuration code segment\n" +" -b Maximum number of configured bits\n" +" -h Print help\n" +" -v Print version\n" +" -u [] Unit test period, unit ms, the default is 1000ms\n" +"\n" + + ); +} + +static int test(int argc, char *argv[]) +{ + char *execute = NULL; + int ut_period = 1000; + + /* reset getopt */ + command_opt_init(); + + while (1) + { + int opt = command_getopt(argc, argv, "e:hvu::"); + if (opt == -1) break; + + switch (opt) + { + case 'u' : + if (command_optarg) ut_period = atoi(command_optarg); + break; + case 'e' : + execute = command_optarg; + break; + case 'v' : + printf("floatl version %d.%d.%d\r\n", FLMATH_V_MAJOR, FLMATH_V_MINOR, FLMATH_V_PATCH); + return 0; + case '?': + printf("Unknown option `%c`\r\n", command_optopt); + return -1; + case 'h' : + default: + usage(); + return 0; + } + } + + if (execute) + { + if (!strcmp(execute, "base")) + { + test_base(); + } + else if (!strcmp(execute, "ut")) + { + srand((uint32_t)time(NULL)); + #if defined(TEST_TARGET_flmath) + while (1) + { + unitt_task(); + usleep(1000 * ut_period); + } + #else + printf("create task %d\r\n", task_create(ut_period, unitt_task)); + #endif + } + } + else + { + test_base(); + } + + return 0; +} + +/************************************************************************************/ +/************************************ Test entry ************************************/ +/************************************************************************************/ + +#if defined(TEST_TARGET_flmath) +int main(int argc, char *argv[]) +{ + return test(argc, argv); +} +#else +void test_flmath(void) +{ + command_export("flmath", test); +} +init_export_app(test_flmath); +#endif + diff --git a/test/test_floatl.c b/test/test_floatl.c index 410f7e4..4610a98 100644 --- a/test/test_floatl.c +++ b/test/test_floatl.c @@ -243,6 +243,115 @@ static double double_from_uint64(uint64_t value) return v.double_; } +// 将 double 的二进制表示转换为 uint64_t +typedef unsigned long long uint64_t; +typedef long long int64_t; + +uint64_t double_to_bits(double x) { + return *((uint64_t*)&x); +} + +double bits_to_double(uint64_t bits) { + return *((double*)&bits); +} + +// double_ceil 实现 +double double_ceil(double x) { + uint64_t bits = double_to_bits(x); + int64_t exponent = ((bits >> 52) & 0x7FF) - 1023; + + if (exponent < 0) { + // 如果指数为负,说明 x 在 (-1, 1) 之间 + if (x > 0) { + return 1.0; + } else if (x == 0.0) { + return 0.0; + } else { + return -0.0; + } + } + + int shift = 52 - exponent; + if (shift <= 0) { + // 如果 x 已经是整数,直接返回 x + return x; + } + + uint64_t mask = (1ULL << shift) - 1; + uint64_t truncated = bits & ~mask; + + double result = bits_to_double(truncated); + if (result < x) { + result += 1.0; + } + + return result; +} + +// double_floor 实现 +double double_floor(double x) { + uint64_t bits = double_to_bits(x); + int64_t exponent = ((bits >> 52) & 0x7FF) - 1023; + + if (exponent < 0) { + // 如果指数为负,说明 x 在 (-1, 1) 之间 + if (x >= 0) { + return 0.0; + } else { + return -1.0; + } + } + + int shift = 52 - exponent; + if (shift <= 0) { + // 如果 x 已经是整数,直接返回 x + return x; + } + + uint64_t mask = (1ULL << shift) - 1; + uint64_t truncated = bits & ~mask; + + double result = bits_to_double(truncated); + if (result > x) { + result -= 1.0; + } + + return result; +} + +// double_round 实现 +double double_round(double x) { + uint64_t bits = double_to_bits(x); + int64_t exponent = ((bits >> 52) & 0x7FF) - 1023; + + if (exponent < 0) { + // 如果指数为负,说明 x 在 (-1, 1) 之间 + if (x > 0) { + return (x >= 0.5) ? 1.0 : 0.0; + } else { + return (x <= -0.5) ? -1.0 : -0.0; + } + } + + int shift = 52 - exponent; + if (shift <= 0) { + // 如果 x 已经是整数,直接返回 x + return x; + } + + uint64_t mask = (1ULL << shift) - 1; + uint64_t truncated = bits & ~mask; + + double result = bits_to_double(truncated); + uint64_t fractional = bits & mask; + + if (fractional >= (1ULL << (shift - 1))) { + result += 1.0; + } + + return result; +} + static const char* float_show_raw(float x) { float_u a = {.float_ = x}; @@ -754,19 +863,27 @@ typedef struct { uint32_t buffer[256]; - uint32_t FLOATL_BIT_PARTS; // bits - uint32_t FLOATL_U32_PARTS; // FLOATL_BIT_PARTS / 32 ---- FLOATL_BIT_PARTS >> 5 - uint32_t FLOATL_U16_PARTS; // FLOATL_BIT_PARTS / 16 ---- FLOATL_BIT_PARTS >> 4 - uint32_t FLOATL_EXP_BITS; // floatl_cfg_gen_exp(FLOATL_BIT_PARTS) - uint32_t FLOATL_MANT_BITS; // FLOATL_BIT_PARTS - FLOATL_EXP_BITS - 1 - uint32_t FLOATL_MANT_PARTS; // FLOATL_MANT_BITS / 32 ---- FLOATL_MANT_BITS >> 5 - uint32_t FLOATL_MANT_HIGH_BITS; // FLOATL_MANT_BITS % 32 ---- FLOATL_MANT_BITS & 0x1F - uint32_t FLOATL_EXP_MID_VALUE; // 2^(FLOATL_EXP_BITS-1) - 1 - uint32_t FLOATL_EXP_WHL_VALUE; // 2^(FLOATL_EXP_BITS) - 1 + uint32_t FLOATL_BIT_PARTS__; // bits + uint32_t FLOATL_U32_PARTS__; // FLOATL_BIT_PARTS__ / 32 ---- FLOATL_BIT_PARTS__ >> 5 + uint32_t FLOATL_U16_PARTS__; // FLOATL_BIT_PARTS__ / 16 ---- FLOATL_BIT_PARTS__ >> 4 + uint32_t FLOATL_EXP_BITS__; // floatl_cfg_gen_exp(FLOATL_BIT_PARTS__) + uint32_t FLOATL_MANT_BITS__; // FLOATL_BIT_PARTS__ - FLOATL_EXP_BITS__ - 1 + uint32_t FLOATL_MANT_PARTS__; // FLOATL_MANT_BITS__ / 32 ---- FLOATL_MANT_BITS__ >> 5 + uint32_t FLOATL_MANT_HIGH_BITS__; // FLOATL_MANT_BITS__ % 32 ---- FLOATL_MANT_BITS__ & 0x1F + uint32_t FLOATL_EXP_MID_VALUE__; // 2^(FLOATL_EXP_BITS__-1) - 1 + uint32_t FLOATL_EXP_WHL_VALUE__; // 2^(FLOATL_EXP_BITS__) - 1 - uint32_t FLOATL2_BIT_PARTS; // FLOATL_BIT_PARTS * 2 - uint32_t FLOATL2_U32_PARTS; // FLOATL2_BIT_PARTS / 32 ---- FLOATL2_BIT_PARTS >> 5 - uint32_t FLOATL2_U16_PARTS; // FLOATL2_BIT_PARTS / 16 ---- FLOATL2_BIT_PARTS >> 4 + uint32_t FLOATL2_BIT_PARTS__; // FLOATL_BIT_PARTS__ * 2 + uint32_t FLOATL2_U32_PARTS__; // FLOATL2_BIT_PARTS__ / 32 ---- FLOATL2_BIT_PARTS__ >> 5 + uint32_t FLOATL2_U16_PARTS__; // FLOATL2_BIT_PARTS__ / 16 ---- FLOATL2_BIT_PARTS__ >> 4 + + uint32_t FLOATL_MANT_DIG__; // FLOATL_MANT_BITS__ + 1 + int32_t FLOATL_MIN_EXP__; // - FLOATL_EXP_MID_VALUE__ + 2 + uint32_t FLOATL_MAX_EXP__; // FLOATL_EXP_MID_VALUE__ + 1 + uint32_t FLOATL_DIG__; // floor(log10(2) * FLOATL_MANT_DIG__) + uint32_t FLOATL_DECIMAL_DIG__; // ceil(log10(2) * FLOATL_MANT_DIG__) + 1 + int32_t FLOATL_MIN_10_EXP__; // ceil(log10(2) * (1 - FLOATL_EXP_MID_VALUE__)) + uint32_t FLOATL_MAX_10_EXP__; // - FLOATL_MIN_10_EXP__ + 1 } FLINFO; typedef struct @@ -830,7 +947,7 @@ void floatl_cfg_const_out(FILE* file, FLINFO *info) if (!file || !info) return; fprintf(file, "(floatl){.u32={"); - for (int i = 0; i < info->FLOATL_U32_PARTS; i++) + for (int i = 0; i < info->FLOATL_U32_PARTS__; i++) { uint32_t value = info->buffer[i]; if (value == 0) fprintf(file, "0,"); @@ -844,28 +961,35 @@ int floatl_cfg_info_init(FLINFO *info, unsigned int bits) { if ((bits & (bits - 1)) != 0) return 0; - info->FLOATL_BIT_PARTS = bits; - info->FLOATL_U32_PARTS = info->FLOATL_BIT_PARTS >> (5); - info->FLOATL_U16_PARTS = info->FLOATL_BIT_PARTS >> (4); - info->FLOATL_EXP_BITS = floatl_cfg_gen_exp(info->FLOATL_BIT_PARTS); - info->FLOATL_MANT_BITS = info->FLOATL_BIT_PARTS - info->FLOATL_EXP_BITS - 1; - info->FLOATL_MANT_PARTS = info->FLOATL_MANT_BITS >> 5; - info->FLOATL_MANT_HIGH_BITS = info->FLOATL_MANT_BITS & 0x1F; - info->FLOATL_EXP_MID_VALUE = (uint32_t)pow(2, info->FLOATL_EXP_BITS - 1) - 1; - info->FLOATL_EXP_WHL_VALUE = (uint32_t)pow(2, info->FLOATL_EXP_BITS) - 1; - info->FLOATL2_BIT_PARTS = info->FLOATL_BIT_PARTS * 2; - info->FLOATL2_U32_PARTS = info->FLOATL2_BIT_PARTS >> (5); - info->FLOATL2_U16_PARTS = info->FLOATL2_BIT_PARTS >> (4); + info->FLOATL_BIT_PARTS__ = bits; + info->FLOATL_U32_PARTS__ = info->FLOATL_BIT_PARTS__ >> (5); + info->FLOATL_U16_PARTS__ = info->FLOATL_BIT_PARTS__ >> (4); + info->FLOATL_EXP_BITS__ = floatl_cfg_gen_exp(info->FLOATL_BIT_PARTS__); + info->FLOATL_MANT_BITS__ = info->FLOATL_BIT_PARTS__ - info->FLOATL_EXP_BITS__ - 1; + info->FLOATL_MANT_PARTS__ = info->FLOATL_MANT_BITS__ >> 5; + info->FLOATL_MANT_HIGH_BITS__ = info->FLOATL_MANT_BITS__ & 0x1F; + info->FLOATL_EXP_MID_VALUE__ = (uint32_t)pow(2, info->FLOATL_EXP_BITS__ - 1) - 1; + info->FLOATL_EXP_WHL_VALUE__ = (uint32_t)pow(2, info->FLOATL_EXP_BITS__) - 1; + info->FLOATL2_BIT_PARTS__ = info->FLOATL_BIT_PARTS__ * 2; + info->FLOATL2_U32_PARTS__ = info->FLOATL2_BIT_PARTS__ >> (5); + info->FLOATL2_U16_PARTS__ = info->FLOATL2_BIT_PARTS__ >> (4); + info->FLOATL_MANT_DIG__ = info->FLOATL_MANT_BITS__ + 1; + info->FLOATL_MIN_EXP__ = - info->FLOATL_EXP_MID_VALUE__ + 2; + info->FLOATL_MAX_EXP__ = info->FLOATL_EXP_MID_VALUE__ + 1; + info->FLOATL_DIG__ = floor(log10(2) * info->FLOATL_MANT_DIG__); + info->FLOATL_DECIMAL_DIG__ = ceil(log10(2) * info->FLOATL_MANT_DIG__) + 1; + info->FLOATL_MIN_10_EXP__ = ceil(log10(2) * (int32_t)(1 - info->FLOATL_EXP_MID_VALUE__)); + info->FLOATL_MAX_10_EXP__ = - info->FLOATL_MIN_10_EXP__ + 1; - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); return 1; } FLINFO *floatl_cfg_set_sign(FLINFO *info, int sign) { - if (sign) info->buffer[info->FLOATL_U32_PARTS - 1] |= (1 << 31); - else info->buffer[info->FLOATL_U32_PARTS - 1] &= ~(1 << 31); + if (sign) info->buffer[info->FLOATL_U32_PARTS__ - 1] |= (1 << 31); + else info->buffer[info->FLOATL_U32_PARTS__ - 1] &= ~(1 << 31); return info; } @@ -873,25 +997,25 @@ FLINFO *floatl_cfg_set_exp_real(FLINFO *info, uint32_t t) { uint32_t temp = 1; - temp <<= info->FLOATL_EXP_BITS; + temp <<= info->FLOATL_EXP_BITS__; temp -= 1; t &= temp; - t <<= (32 - info->FLOATL_EXP_BITS - 1); + t <<= (32 - info->FLOATL_EXP_BITS__ - 1); - temp <<= (32 - info->FLOATL_EXP_BITS - 1); + temp <<= (32 - info->FLOATL_EXP_BITS__ - 1); - info->buffer[info->FLOATL_U32_PARTS - 1] &= (~temp); // clear + info->buffer[info->FLOATL_U32_PARTS__ - 1] &= (~temp); // clear - info->buffer[info->FLOATL_U32_PARTS - 1] |= t; + info->buffer[info->FLOATL_U32_PARTS__ - 1] |= t; return info; } FLINFO *floatl_cfg_set_exp(FLINFO *info, int32_t e) { - return floatl_cfg_set_exp_real(info, e + info->FLOATL_EXP_MID_VALUE); + return floatl_cfg_set_exp_real(info, e + info->FLOATL_EXP_MID_VALUE__); } FLINFO *floatl_cfg_set_mant(FLINFO *info, char *bin) @@ -900,7 +1024,7 @@ FLINFO *floatl_cfg_set_mant(FLINFO *info, char *bin) while (*s) { - int index = info->FLOATL_MANT_BITS - (s - bin) - 1; + int index = info->FLOATL_MANT_BITS__ - (s - bin) - 1; if (index < 0) break; if (index >= 0 && *s == '1') { @@ -917,24 +1041,24 @@ FLINFO *floatl_cfg_set_mant(FLINFO *info, char *bin) FLINFO *floatl_cfg_int_zero(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); return info; } FLINFO *floatl_cfg_const_0(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); return info; } FLINFO *floatl_cfg_const_1(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 0xFFFFFFFF); - info->buffer[info->FLOATL_U32_PARTS - 1] &= 0xBFFFFFFF; + info->buffer[info->FLOATL_U32_PARTS__ - 1] &= 0xBFFFFFFF; return info; } @@ -943,7 +1067,7 @@ FLINFO *floatl_cfg_const_1eX(FLINFO *info, uint32_t e) { if (e >= sizeof(fle_list) / sizeof(fle_list[0])) return NULL; - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp(info, fle_list[e].exp); floatl_cfg_set_mant(info, fle_list[e].mantBin); @@ -951,9 +1075,29 @@ FLINFO *floatl_cfg_const_1eX(FLINFO *info, uint32_t e) return info; } +FLINFO *floatl_cfg_const_pi(FLINFO *info) +{ + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); + + floatl_cfg_set_exp(info, 1); + floatl_cfg_set_mant(info, FLOATL_CFG_MANT_PI); + + return info; +} + +FLINFO *floatl_cfg_const_e(FLINFO *info) +{ + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); + + floatl_cfg_set_exp(info, 1); + floatl_cfg_set_mant(info, FLOATL_CFG_MANT_E); + + return info; +} + FLINFO *floatl_cfg_inf(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 0xFFFFFFFF); @@ -962,26 +1106,26 @@ FLINFO *floatl_cfg_inf(FLINFO *info) FLINFO *floatl_cfg_nan(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 0xFFFFFFFF); - info->buffer[info->FLOATL_U32_PARTS - 1] |= 0x80000000; + info->buffer[info->FLOATL_U32_PARTS__ - 1] |= 0x80000000; return info; } FLINFO *floatl_cfg_all_sign(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); - info->buffer[info->FLOATL_U32_PARTS - 1] |= 0x80000000; + info->buffer[info->FLOATL_U32_PARTS__ - 1] |= 0x80000000; return info; } FLINFO *floatl_cfg_all_exp(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 0xFFFFFFFF); @@ -990,26 +1134,26 @@ FLINFO *floatl_cfg_all_exp(FLINFO *info) FLINFO *floatl_cfg_all_mant(FLINFO *info) { - memset(info->buffer, -1, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, -1, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 0); - info->buffer[info->FLOATL_U32_PARTS - 1] &= (~0x80000000); + info->buffer[info->FLOATL_U32_PARTS__ - 1] &= (~0x80000000); return info; } FLINFO *floatl_cfg_all_exp_mant(FLINFO *info) { - memset(info->buffer, -1, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, -1, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); - info->buffer[info->FLOATL_U32_PARTS - 1] &= (~0x80000000); + info->buffer[info->FLOATL_U32_PARTS__ - 1] &= (~0x80000000); return info; } FLINFO *floatl_cfg_hide_mant_bit(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 1); @@ -1018,7 +1162,7 @@ FLINFO *floatl_cfg_hide_mant_bit(FLINFO *info) FLINFO *floatl_cfg_mant_plus_max(FLINFO *info) { - memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 8); @@ -1027,10 +1171,38 @@ FLINFO *floatl_cfg_mant_plus_max(FLINFO *info) FLINFO *floatl_cfg_mant_whole(FLINFO *info) { - memset(info->buffer, -1, info->FLOATL_U32_PARTS * sizeof(uint32_t)); + memset(info->buffer, -1, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); floatl_cfg_set_exp_real(info, 1); - info->buffer[info->FLOATL_U32_PARTS - 1] &= (~0x80000000); + info->buffer[info->FLOATL_U32_PARTS__ - 1] &= (~0x80000000); + + return info; +} + +FLINFO *floatl_cfg_min(FLINFO *info) +{ + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); + + floatl_cfg_set_exp_real(info, 1); + + return info; +} + +FLINFO *floatl_cfg_max(FLINFO *info) +{ + memset(info->buffer, -1, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); + + floatl_cfg_set_sign(info, 0); + floatl_cfg_set_exp_real(info, 0xFFFFFFFE); + + return info; +} + +FLINFO *floatl_cfg_epsilon(FLINFO *info) +{ + memset(info->buffer, 0, info->FLOATL_U32_PARTS__ * sizeof(uint32_t)); + + info->buffer[0] |= 1; return info; } @@ -1058,6 +1230,13 @@ void floatl_cfg_generate(uint32_t bits, const char *filename) return; } + /* Enable PI and E mant configurations */ + if (!FLOATL_CFG_MANT_PI || !FLOATL_CFG_MANT_E) + { + fprintf(stdout, "[ERROR] Enable `FLOATL_CFG_MANT_PI` and `FLOATL_CFG_MANT_E` in `floatl_cfg.h` file"NEWLINE); + return; + } + /* Limiting the minimum bit */ if (bits < MINBITS) { @@ -1098,19 +1277,27 @@ void floatl_cfg_generate(uint32_t bits, const char *filename) FLINFO info; floatl_cfg_info_init(&info, tb); - fprintf(output, "#define __FLOATL_BIT_PARTS__ %u"NEWLINE, info.FLOATL_BIT_PARTS ); - fprintf(output, "#define __FLOATL_U32_PARTS__ %u"NEWLINE, info.FLOATL_U32_PARTS ); - fprintf(output, "#define __FLOATL_U16_PARTS__ %u"NEWLINE, info.FLOATL_U16_PARTS ); - fprintf(output, "#define __FLOATL_EXP_BITS__ %u"NEWLINE, info.FLOATL_EXP_BITS ); - fprintf(output, "#define __FLOATL_MANT_BITS__ %u"NEWLINE, info.FLOATL_MANT_BITS ); - fprintf(output, "#define __FLOATL_MANT_PARTS__ %u"NEWLINE, info.FLOATL_MANT_PARTS ); - fprintf(output, "#define __FLOATL_MANT_HIGH_BITS__ %u"NEWLINE, info.FLOATL_MANT_HIGH_BITS ); - fprintf(output, "#define __FLOATL_EXP_MID_VALUE__ %u"NEWLINE, info.FLOATL_EXP_MID_VALUE ); - fprintf(output, "#define __FLOATL_EXP_WHL_VALUE__ %u"NEWLINE, info.FLOATL_EXP_WHL_VALUE ); + fprintf(output, "#define __FLOATL_BIT_PARTS__ %u"NEWLINE, info.FLOATL_BIT_PARTS__ ); + fprintf(output, "#define __FLOATL_U32_PARTS__ %u"NEWLINE, info.FLOATL_U32_PARTS__ ); + fprintf(output, "#define __FLOATL_U16_PARTS__ %u"NEWLINE, info.FLOATL_U16_PARTS__ ); + fprintf(output, "#define __FLOATL_EXP_BITS__ %u"NEWLINE, info.FLOATL_EXP_BITS__ ); + fprintf(output, "#define __FLOATL_MANT_BITS__ %u"NEWLINE, info.FLOATL_MANT_BITS__ ); + fprintf(output, "#define __FLOATL_MANT_PARTS__ %u"NEWLINE, info.FLOATL_MANT_PARTS__ ); + fprintf(output, "#define __FLOATL_MANT_HIGH_BITS__ %u"NEWLINE, info.FLOATL_MANT_HIGH_BITS__ ); + fprintf(output, "#define __FLOATL_EXP_MID_VALUE__ %u"NEWLINE, info.FLOATL_EXP_MID_VALUE__ ); + fprintf(output, "#define __FLOATL_EXP_WHL_VALUE__ %u"NEWLINE, info.FLOATL_EXP_WHL_VALUE__ ); - fprintf(output, "#define __FLOATL2_BIT_PARTS__ %u"NEWLINE, info.FLOATL2_BIT_PARTS ); - fprintf(output, "#define __FLOATL2_U32_PARTS__ %u"NEWLINE, info.FLOATL2_U32_PARTS ); - fprintf(output, "#define __FLOATL2_U16_PARTS__ %u"NEWLINE, info.FLOATL2_U16_PARTS ); + fprintf(output, "#define __FLOATL2_BIT_PARTS__ %u"NEWLINE, info.FLOATL2_BIT_PARTS__ ); + fprintf(output, "#define __FLOATL2_U32_PARTS__ %u"NEWLINE, info.FLOATL2_U32_PARTS__ ); + fprintf(output, "#define __FLOATL2_U16_PARTS__ %u"NEWLINE, info.FLOATL2_U16_PARTS__ ); + + fprintf(output, "#define __FLOATL_MANT_DIG__ %u"NEWLINE, info.FLOATL_MANT_DIG__ ); + fprintf(output, "#define __FLOATL_MIN_EXP__ %d"NEWLINE, info.FLOATL_MIN_EXP__ ); + fprintf(output, "#define __FLOATL_MAX_EXP__ %u"NEWLINE, info.FLOATL_MAX_EXP__ ); + fprintf(output, "#define __FLOATL_DIG__ %u"NEWLINE, info.FLOATL_DIG__ ); + fprintf(output, "#define __FLOATL_DECIMAL_DIG__ %u"NEWLINE, info.FLOATL_DECIMAL_DIG__ ); + fprintf(output, "#define __FLOATL_MIN_10_EXP__ %d"NEWLINE, info.FLOATL_MIN_10_EXP__ ); + fprintf(output, "#define __FLOATL_MAX_10_EXP__ %u"NEWLINE, info.FLOATL_MAX_10_EXP__ ); fprintf(output, "#define __FLOATL_CONST_0__ "); floatl_cfg_const_out(output, floatl_cfg_const_0(&info) ); fprintf(output, "#define __FLOATL_CONST_1__ "); floatl_cfg_const_out(output, floatl_cfg_const_1(&info) ); @@ -1130,6 +1317,8 @@ void floatl_cfg_generate(uint32_t bits, const char *filename) fprintf(output, "#define __FLOATL_CONST_1e13__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,13) ); fprintf(output, "#define __FLOATL_CONST_1e14__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,14) ); fprintf(output, "#define __FLOATL_CONST_1e15__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,15) ); + fprintf(output, "#define __FLOATL_CONST_PI__ "); floatl_cfg_const_out(output, floatl_cfg_const_pi(&info) ); + fprintf(output, "#define __FLOATL_CONST_E__ "); floatl_cfg_const_out(output, floatl_cfg_const_e(&info) ); fprintf(output, "#define __FLOATL_INT_ZERO__ "); floatl_cfg_const_out(output, floatl_cfg_int_zero(&info) ); fprintf(output, "#define __FLOATL_INF__ "); floatl_cfg_const_out(output, floatl_cfg_inf(&info) ); fprintf(output, "#define __FLOATL_NAN__ "); floatl_cfg_const_out(output, floatl_cfg_nan(&info) ); @@ -1140,6 +1329,9 @@ void floatl_cfg_generate(uint32_t bits, const char *filename) fprintf(output, "#define __FLOATL_HIDE_MANT_BIT__ "); floatl_cfg_const_out(output, floatl_cfg_hide_mant_bit(&info) ); fprintf(output, "#define __FLOATL_MANT_PLUS_MAX__ "); floatl_cfg_const_out(output, floatl_cfg_mant_plus_max(&info) ); fprintf(output, "#define __FLOATL_MANT_WHL__ "); floatl_cfg_const_out(output, floatl_cfg_mant_whole(&info) ); + fprintf(output, "#define __FLOATL_MIN__ "); floatl_cfg_const_out(output, floatl_cfg_min(&info) ); + fprintf(output, "#define __FLOATL_MAX__ "); floatl_cfg_const_out(output, floatl_cfg_max(&info) ); + fprintf(output, "#define __FLOATL_EPSILON__ "); floatl_cfg_const_out(output, floatl_cfg_epsilon(&info) ); } fprintf(output, "#endif"NEWLINE); @@ -1158,8 +1350,6 @@ void floatl_cfg_generate(uint32_t bits, const char *filename) { printf("[INFO] The configuration has been generated, copy it to the `floatl_cfg.h` range specified\r\n"); } - - return 0; } /*----------------------------------------------------------------------------------*/ @@ -1360,6 +1550,18 @@ static void test_base(void) // double_show_raw(y); // printf("y %f e %d\r\n", y, e); #endif + double v = -3.14; + printf("ceil %f\r\n", ceil(v)); + printf("floor %f\r\n", floor(v)); + printf("round %f\r\n", round(v)); + + printf("double_ceil %f\r\n", double_ceil(v)); + printf("double_floor %f\r\n", double_floor(v)); + printf("double_round %f\r\n", double_round(v)); + + printf("floatl_ceil %s\r\n", floatl_show(floatl_ceil(floatl(v)), buffer, sizeof(buffer), "%f")); + printf("floatl_floor %s\r\n", floatl_show(floatl_floor(floatl(v)), buffer, sizeof(buffer), "%f")); + printf("floatl_round %s\r\n", floatl_show(floatl_round(floatl(v)), buffer, sizeof(buffer), "%f")); } /************************************************************************************/