Hello, Bastien Roucaries wrote:
> I need for my program to use asinh acosh and atanh. For now I used to define > > it if missing using > #define asinh(x) log(x+sqrt(x*x+1)) > #define acosh(x) log(x+sqrt(x-1.0)*sqrt(x+1.0)) > #define atanh(x) (0.5*log(x+1)-0.5*log(1-x)) > > How can I create a gnulib module in order to do that? First, look in the gnulib documentation which portability problems are already known and which of them are already handled by gnulib. In this case, you see that the problem is that mingw does not provide the functions, and that gnulib provides no workaround so far. Second, decide which include file should declare the functions. POSIX says <math.h> in this case; in gnulib the source code of this file is in lib/math.in.h. Try to write the declarations here. Add the proper autoconf tests; see e.g. how it was done for the 'trunc' function or some other functions. Third, write an implementation of these functions that is portable enough; each function it its own file. The formula you gave for asinh(x) is ok for x >= 0; for x < 0 it is unusable since it will lead to numerical instability (i.e. rounding errors that are far too big). The formula you gave for acosh(x) may be ok, but is it necessary to call sqrt twice? The formula you gave for atanh(x): similarly, it is necessary to call log twice? Furthermore, for x near 0, say abs(x) < 2^-53, your formula will return 0, which has a relative error of 100%; it's possible to do better. Fourth, write a test suite for each function. The test suite should cover particular values as well as special cases like +/- infinity and NaN. Then you can submit the patch here. Bruno
