atanh

function atanh( x ) --> res

Description

Returns the inverse hyperbolic tangenent of x.

Parameters

x

A number that should be between -1 and 1.

Return Values

res

The inverse hyperbolic tangenent, or NaN if x is not between -1 and 1.

Code

--ZFUNC-atanh-v1
local function atanh( x ) --> res
   if x < -1 or x > 1 then return math.sqrt( -1 ) end
   return math.log( ( 1+x ) / ( 1-x ) ) / 2
end

return atanh

Examples

local t = require( "taptest" )
local atanh = require( "atanh" )
local round = require( "round" )

t( round( atanh( 0.76159416 ), 8 ), 1.00000001 )
t( round( atanh( -0.1 ), 9 ), -0.100335348 )

t()

See also