[PATCH v2 6/8] math: Consolidated common definition/data for cosh/sinh/tanh
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Thu Mar 12 14:07:50 GMT 2026
On 11/03/26 23:27, DJ Delorie wrote:
>
> Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
>> diff --git a/sysdeps/ieee754/dbl-64/e_cosh_data.c b/sysdeps/ieee754/dbl-64/e_cosh_data.c
>
>> +/* Correctly rounded hyperbolic cosine for binary64 values.
>
> This comment is not quite correct for this file. The data files should
> say they're *for* computing those, but the comment implies that these
> files *do* the computing.
Ack, I will change by:
Data definitions used by cosh implementation.
>
>> +/*
>> + The function sinh(x)/cosh(x) is approximated by a minimax polynomial
>> + cosh(x)~1+x^2*P(x^2) for |x|<0.125. For other arguments the
>> + identity cosh(x)=(exp(|x|)+exp(-|x|))/2 is used. For |x|<5 both
>> + exponents are calculated with slightly higher precision than
>> + double. For 5<|x|<36.736801 the exp(-|x|) is rather small and is
>> + calculated with double precision but exp(|x|) is calculated with
>> + higher than double precision. For 36.736801<|x|<710.47586
>> + exp(-|x|) becomes too small and only exp(|x|) is calculated.
>> + */
>
> Should this comment be here, or in the source file that uses this data?
I moved it to data definition to avoid duplicate on both cosh and sinh files
and also because it makes more sense to document how it was generated on
where it is defined.
>
>> +const double __sinhcosh_t0[][2]
>> + = { { 0x0p+0, 0x1p+0 },
>> + { -0x1.19083535b085ep-56, 0x1.02c9a3e778061p+0 },
>> + { 0x1.74853f3a5931ep-55, 0x1.fa7c1819e90d8p+0 } };
>> +
>> +const double __sinhcosh_t1[][2] = {
>> + { 0x0p+0, 0x1p+0 },
>> + { 0x1.ae8e38c59c72ap-54, 0x1.000b175effdc7p+0 },
>> + { -0x1.7b5d0d58ea8f4p-58, 0x1.00162f3904052p+0 },
>> + { 0x1.e47120223468p-54, 0x1.02be6e199c811p+0 },
>> +};
>
> Heh, the formatting inconsistency got faithfully copied ;-)
Ack.
>
>> +extern const double __sinh_data_db[49][3] attribute_hidden;
>
> I assume the 49 is correct, but is it needed? We use array_length()
> elsewhere to discover this value, and if the table length ever changes
> (I hope not ;) this is just one more place that needs to be consistent.
We do need the specify the full size otherwise array_length fails with:
error: invalid application of ‘sizeof’ to incomplete type ‘const double[][3]’
2 | (sizeof (var) / sizeof ((var)[0]) \
| ^
Because without the specifier the array size is only know at the TU.
>
>> +extern const double __tanh_data_db[12][3] attribute_hidden;
>
> Here too.
>
>> @@ -164,144 +139,6 @@ SECTION
>> double
>> __tanh (double x)
>> {
>> - /*
>> - The function tanh(x) is approximated by minimax polynomial for
>> - |x|<0.25. For other values we use this identity tanh(|x|) = 1 -
>> - 2*exp(-2*|x|)/(1 + exp(-2*|x|)). For large |x|>3.683 the term
>> - 2*exp(-2*|x|)/(1 + exp(-2*|x|)) becomes small and we can use less
>> - precise formula for exponential.
>> - */
>
> Likewise, this comment should have remained here.
>
More information about the Libc-alpha
mailing list