[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Missing math functions
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sat, 19 Jan 2013 09:42:44 +0200
2013/1/18 martinwguy <firstname.lastname@example.org>:
> On 18 January 2013 14:38, Dirk Laurie <email@example.com> wrote:
>> There's no math.asinh, math.acosh, math.atanh.
>> The reason presumably being that ANSI C does not provide
>> But if your C compiler provides it, you may find the included
>> file useful.
> math.asinh = function (x) return math.log(x + math.sqrt(x * x + 1)); end
> math.acosh = function (x) return math.log(x + math.sqrt(x * x - 1)); end
> math.atanh = function(x) return (math.log(1 + x) - math.log(1 - x)) / 2; end
That's not good enough.
The asinh and atanh formulas are known to be inaccurate near the
origin because of smearing. When x*x+1 is formed, digits get thrown
away. When x is added to the sqrt of that, more digits get thrown away.
When log of something close to 1 is calculated, 1 is subtracted in the
process. This cancellation does not by itself introduce a new error,
but exposes the fact that the digits are already irretrievably gone.
E.g. using the above, and compare with asin which is supplied,
> return x-math.asin(math.sin(x))
The error is always at or about 1e-16, which is crude when
the correct value is << 1.
Using the invhyp module,