Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260406085834.GW3520958@port70.net>
Date: Mon, 6 Apr 2026 10:58:34 +0200
From: Szabolcs Nagy <nsz@...t70.net>
To: "b.s." <newbie-02@....de>
Cc: musl@...ts.openwall.com
Subject: Re: A question about trigonomic functions

* b.s. <newbie-02@....de> [2026-04-06 02:41:18 +0000]:
> can someone tell if musl has, and if where to find, sin, cos, tan, asin,
> sinh ... functions which can cope up with or are better than hardware /
> glibc accuracy?

what is hw accuracy? x87 fsin? i think that's only accurate
on a limited range and likely slower than a modern sw
implementation (extended vs double precision overhead).

for accuracy comparison, see
https://members.loria.fr/PZimmermann/papers/accuracy.pdf

$ grep -r 'sin.*(double' musl/src
musl/src/internal/libm.h:hidden double __sin(double,double,int);
musl/src/internal/libm.h:hidden float  __sindf(double);
musl/src/math/sin.c:double sin(double x)
musl/src/math/lgamma_r.c:static double sin_pi(double x)
musl/src/math/tgamma.c:static double sinpi(double x)
musl/src/math/sincos.c:void sincos(double x, double *sin, double *cos)
musl/src/math/__sin.c:double __sin(double x, double y, int iy)
musl/src/math/__sindf.c:float __sindf(double x)
musl/src/math/sinh.c:double sinh(double x)
musl/src/math/asinh.c:double asinh(double x)
musl/src/math/asin.c:double asin(double x)
musl/src/complex/casinh.c:double complex casinh(double complex z)
musl/src/complex/csin.c:double complex csin(double complex z)
musl/src/complex/csinh.c:double complex csinh(double complex z)
musl/src/complex/casin.c:double complex casin(double complex z)

> 
> Also hints to other sources would be nice.
> 
> I'm seeking for a template to implement in _Decimalxxx datatypes, and all I
> found yet has flaws ...
> 
> I don't need the range reduction part, -pi()/4 .. +pi()/4 would be fine,

i think range reduction is the difficult part.

in -pi/4,pi/4 the usual approach is a polynomial
and optionally further split of the range using
the sin(a+b) identity and sin/cos lookup tables.
the optimal solution depends on the requirements.

(sollya tool can be used for polynomial design,
mpfr to compute tables and test results)

> and also splitting that in different algorithms for distinct ranges would be
> ok ( I'd read somewhere that glibc / IBM code uses that but is very complex
> ).
> 
> TIA for any help,
> 
> 
> b.

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.