## Arsinh Function Not Working Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
1100++
Posts: 78
Joined: 10 Feb 2018, 19:05

### Arsinh Function Not Working

I'm trying to write a function that calculates the arsinh of a number. I'm using a formula found on this Wikipedia page to calculate it.

Here's my code:

Code: Select all

``````arsinh(x) {
static terms := [0, 0, 0, 0, 0, 0, 0, 0]
If x is not number
return
power := 1, s := abs(x)
While s > .0625
s := sqrt(sqrt(s * s + 1) - 1), power *= 2
terms[1] := x := (x < 0 ? -1 : 1) * s, term := 2, term_pwr := 3, xc := .5, xt := x, xf := x * x
While term <= 8
terms[term] := (term & 1 ? 1 : -1) * xc * (xt *= xf) / term_pwr, ++term, xc *= term_pwr, xc /= term_pwr + 1, term_pwr += 2
sum := 0, term := 8
While term > 0
sum += terms[term--]
return sum * power
}``````
However, this function gives erroneous results. For example, while arsinh(5) is about 2.312438, this function returns 57.776128 when given 5, which is off by more than an order of magnitude.

Can someone tell me what's wrong with this function?
Helgef
Posts: 4467
Joined: 17 Jul 2016, 01:02
Contact:

### Re: Arsinh Function Not Working

Code: Select all

``````arsinh(x) {
return ln(x+sqrt(x**2+1))
}
``````
Cheers.
Rohwedder
Posts: 3642
Joined: 04 Jun 2014, 08:33
Location: Germany

### Re: Arsinh Function Not Working

Hallo 1100++ ,
boiler
Posts: 6594
Joined: 21 Dec 2014, 02:44

### Re: Arsinh Function Not Working

It looks like 1100++ is doing the series expansion.
Rohwedder
Posts: 3642
Joined: 04 Jun 2014, 08:33
Location: Germany

### Re: Arsinh Function Not Working

But there's no arsinh(x) series for |x| > 1.
boiler
Posts: 6594
Joined: 21 Dec 2014, 02:44

### Re: Arsinh Function Not Working

Good point. Looks like you identified why it’s not working for x = 5.
1100++
Posts: 78
Joined: 10 Feb 2018, 19:05

### Re: Arsinh Function Not Working  Topic is solved

Never mind, I know what's wrong. I got the argument scaling formula wrong. Here's my corrected function:

Code: Select all

``````arsinh(x) {
static terms := [0, 0, 0, 0, 0, 0, 0, 0]
If x is not number
return
power := 1, s := abs(x)
While s > .0625
s := sqrt((sqrt(s * s + 1) - 1) / 2), power *= 2
terms[1] := x := (x < 0 ? -1 : 1) * s, term := 2, term_pwr := 3, xc := .5, xt := x, xf := x * x
While term <= 8
terms[term] := (term & 1 ? 1 : -1) * xc * (xt *= xf) / term_pwr, ++term, xc *= term_pwr, xc /= term_pwr + 1, term_pwr += 2
sum := 0, term := 8
While term > 0
sum += terms[term--]
return sum * power
}``````
(I started composing this post a few minutes after I posted the original topic, but didn't get around to posting it until now.)