tanh

function tanh( x ) --> res

Description

Returns the hyperbolic tangent of x.

Paramters

x

An angle in radians.

Return Values

res

The hyperbolic tangent of x.

Code

--ZFUNC-tanh-v1
local function tanh( x ) --> res
   --ZFUNC-cosh-v1
   local function cosh( x )
      return ( math.exp( x ) + math.exp( -x ) ) / 2
   end

   --ZFUNC-sinh-v1
   local function sinh( x )
      return ( math.exp( x ) - math.exp( -x ) ) / 2
   end

   return sinh( x ) / cosh( x )
end

return tanh

Examples

local t = require( "tapered" )
local tanh = require( "tanh" )
-- util functions
local round = require( "round" )

t.is( -0.964028, round( tanh( -2 ), 6 ) )
t.is( 0, round( tanh( 0 ), 1 ) )
t.is( 0.462117, round( tanh( 0.5 ), 6 ) )

t.done()

See also