### Arsinh Function Not Working

Posted:

**22 Mar 2020, 12:33**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:
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?

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
}
```

Can someone tell me what's wrong with this function?