Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Math.Tanh Method

Returns the hyperbolic tangent of the specified angle.

[Visual Basic]
Public Shared Function Tanh( _
   ByVal value As Double _
) As Double
[C#]
public static double Tanh(
 double value
);
[C++]
public: static double Tanh(
 double value
);
[JScript]
public static function Tanh(
   value : double
) : double;

Parameters

value
An angle, measured in radians.

Return Value

The hyperbolic tangent of value. If value is equal to NegativeInfinity, this method returns -1. If value is equal to PositiveInfinity, this method returns 1. If value is equal to NaN, this method returns NaN.

Remarks

The angle, value, must be in radians. Multiply by π/180 to convert degrees to radians.

Example

[Visual Basic, C#, C++] The following example uses Tanh to evaluate certain hyperbolic tangent identities for selected values.

[Visual Basic] 
' Example for the hyperbolic Math.Tanh( Double ) method.
Imports System
Imports Microsoft.VisualBasic

Module DemoTanh
   
    Sub Main()
        Console.WriteLine( _
            "This example of hyperbolic Math.Tanh( Double )" & _
            vbCrLf & "generates the following output.")
        Console.WriteLine( _
            vbCrLf & "Evaluate these hyperbolic " & _
            "identities with selected values for X:")
        Console.WriteLine("   tanh(X) = sinh(X) / cosh(X)")
        Console.WriteLine("   tanh(2 * X) = 2 * tanh(X) / (1 + tanh^2(X))")
          
        UseTanh(0.1)
        UseTanh(1.2)
        UseTanh(4.9)
          
        Console.WriteLine( _
            vbCrLf & "Evaluate [tanh(X + Y) == (tanh(X) + " & _
            "tanh(Y)) / (1 + tanh(X) * tanh(Y))]" & _
            vbCrLf & "with selected values for X and Y:")

        UseTwoArgs(0.1, 1.2)
        UseTwoArgs(1.2, 4.9)
    End Sub 'Main
       
    ' Evaluate hyperbolic identities with a given argument.
    Sub UseTanh(arg As Double)
        Dim tanhArg As Double = Math.Tanh(arg)
          
        ' Evaluate tanh(X) = sinh(X) / cosh(X).
        Console.WriteLine( _
            vbCrLf & "                       Math.Tanh({0}) = {1:E16}" & _
            vbCrLf & "      Math.Sinh({0}) / Math.Cosh({0}) = {2:E16}", _
            arg, tanhArg, Math.Sinh(arg) / Math.Cosh(arg))
          
        ' Evaluate tanh(2 * X) = 2 * tanh(X) / (1 + tanh^2(X)).
        Console.WriteLine( _
            "                   2 * Math.Tanh({0}) /", _
            arg, 2.0 * tanhArg)
        Console.WriteLine( _
            "             (1 + (Math.Tanh({0}))^2) = {1:E16}", _
            arg, 2.0 * tanhArg /(1.0 + tanhArg * tanhArg))
        Console.WriteLine( _
            "                       Math.Tanh({0}) = {1:E16}", _
            2.0 * arg, Math.Tanh((2.0 * arg)))
    End Sub 'UseTanh
       
    ' Evaluate a hyperbolic identity that is a function of two arguments.
    Sub UseTwoArgs(argX As Double, argY As Double)

        ' Evaluate tanh(X + Y) = (tanh(X) + tanh(Y)) / (1 + tanh(X) * tanh(Y)).
        Console.WriteLine( _
            vbCrLf & "    (Math.Tanh({0}) + Math.Tanh({1})) /" & _
            vbCrLf & "(1 + Math.Tanh({0}) * Math.Tanh({1})) = {2:E16}", _
            argX, argY, (Math.Tanh(argX) + Math.Tanh(argY)) / _
            (1.0 + Math.Tanh(argX) * Math.Tanh(argY)))
        Console.WriteLine( _
            "                       Math.Tanh({0}) = {1:E16}", _
            argX + argY, Math.Tanh(argX + argY))

    End Sub 'UseTwoArgs
End Module 'DemoTanh

' This example of hyperbolic Math.Tanh( Double )
' generates the following output.
' 
' Evaluate these hyperbolic identities with selected values for X:
'    tanh(X) = sinh(X) / cosh(X)
'    tanh(2 * X) = 2 * tanh(X) / (1 + tanh^2(X))
' 
'                        Math.Tanh(0.1) = 9.9667994624955819E-002
'       Math.Sinh(0.1) / Math.Cosh(0.1) = 9.9667994624955819E-002
'                    2 * Math.Tanh(0.1) /
'              (1 + (Math.Tanh(0.1))^2) = 1.9737532022490401E-001
'                        Math.Tanh(0.2) = 1.9737532022490401E-001
' 
'                        Math.Tanh(1.2) = 8.3365460701215521E-001
'       Math.Sinh(1.2) / Math.Cosh(1.2) = 8.3365460701215521E-001
'                    2 * Math.Tanh(1.2) /
'              (1 + (Math.Tanh(1.2))^2) = 9.8367485769368024E-001
'                        Math.Tanh(2.4) = 9.8367485769368024E-001
' 
'                        Math.Tanh(4.9) = 9.9988910295055444E-001
'       Math.Sinh(4.9) / Math.Cosh(4.9) = 9.9988910295055433E-001
'                    2 * Math.Tanh(4.9) /
'              (1 + (Math.Tanh(4.9))^2) = 9.9999999385024030E-001
'                        Math.Tanh(9.8) = 9.9999999385024030E-001
' 
' Evaluate [tanh(X + Y) == (tanh(X) + tanh(Y)) / (1 + tanh(X) * tanh(Y))]
' with selected values for X and Y:
' 
'     (Math.Tanh(0.1) + Math.Tanh(1.2)) /
' (1 + Math.Tanh(0.1) * Math.Tanh(1.2)) = 8.6172315931330645E-001
'                        Math.Tanh(1.3) = 8.6172315931330634E-001
' 
'     (Math.Tanh(1.2) + Math.Tanh(4.9)) /
' (1 + Math.Tanh(1.2) * Math.Tanh(4.9)) = 9.9998993913939649E-001
'                        Math.Tanh(6.1) = 9.9998993913939649E-001

[C#] 
// Example for the hyperbolic Math.Tanh( double ) method.
using System;

class DemoTanh 
{
    public static void Main() 
    {
        Console.WriteLine( 
            "This example of hyperbolic Math.Tanh( double )\n" +
            "generates the following output." );
        Console.WriteLine( 
            "\nEvaluate these hyperbolic identities " +
            "with selected values for X:" );
        Console.WriteLine( "   tanh(X) == sinh(X) / cosh(X)" );
        Console.WriteLine( 
            "   tanh(2 * X) == 2 * tanh(X) / (1 + tanh^2(X))" );

        UseTanh(0.1);
        UseTanh(1.2);
        UseTanh(4.9);

        Console.WriteLine( 
            "\nEvaluate [tanh(X + Y) == (tanh(X) + tanh(Y)) " +
            "/ (1 + tanh(X) * tanh(Y))]" +
            "\nwith selected values for X and Y:" );

        UseTwoArgs(0.1, 1.2);
        UseTwoArgs(1.2, 4.9);
    }

    // Evaluate hyperbolic identities with a given argument.
    static void UseTanh(double arg)
    {
        double tanhArg = Math.Tanh(arg);

        // Evaluate tanh(X) == sinh(X) / cosh(X).
        Console.WriteLine( 
            "\n                       Math.Tanh({0}) == {1:E16}\n" +
            "      Math.Sinh({0}) / Math.Cosh({0}) == {2:E16}",
            arg, tanhArg, (Math.Sinh(arg) / Math.Cosh(arg)) );

        // Evaluate tanh(2 * X) == 2 * tanh(X) / (1 + tanh^2(X)).
        Console.WriteLine( 
            "                   2 * Math.Tanh({0}) /", 
            arg, 2.0 * tanhArg );
        Console.WriteLine( 
            "             (1 + (Math.Tanh({0}))^2) == {1:E16}", 
            arg, 2.0 * tanhArg / (1.0 + tanhArg * tanhArg ) );
        Console.WriteLine( 
            "                       Math.Tanh({0}) == {1:E16}", 
            2.0 * arg, Math.Tanh(2.0 * arg) );
    }

    // Evaluate a hyperbolic identity that is a function of two arguments.
    static void UseTwoArgs(double argX, double argY)
    {
        // Evaluate tanh(X + Y) == (tanh(X) + tanh(Y)) / (1 + tanh(X) * tanh(Y)).
        Console.WriteLine( 
            "\n    (Math.Tanh({0}) + Math.Tanh({1})) /\n" + 
            "(1 + Math.Tanh({0}) * Math.Tanh({1})) == {2:E16}", 
            argX, argY, (Math.Tanh(argX) + Math.Tanh(argY)) /
            (1.0 + Math.Tanh(argX) * Math.Tanh(argY)) );
        Console.WriteLine( 
            "                       Math.Tanh({0}) == {1:E16}",
            argX + argY, Math.Tanh(argX + argY));
    }
}

/*
This example of hyperbolic Math.Tanh( double )
generates the following output.

Evaluate these hyperbolic identities with selected values for X:
   tanh(X) == sinh(X) / cosh(X)
   tanh(2 * X) == 2 * tanh(X) / (1 + tanh^2(X))

                       Math.Tanh(0.1) == 9.9667994624955819E-002
      Math.Sinh(0.1) / Math.Cosh(0.1) == 9.9667994624955819E-002
                   2 * Math.Tanh(0.1) /
             (1 + (Math.Tanh(0.1))^2) == 1.9737532022490401E-001
                       Math.Tanh(0.2) == 1.9737532022490401E-001

                       Math.Tanh(1.2) == 8.3365460701215521E-001
      Math.Sinh(1.2) / Math.Cosh(1.2) == 8.3365460701215521E-001
                   2 * Math.Tanh(1.2) /
             (1 + (Math.Tanh(1.2))^2) == 9.8367485769368024E-001
                       Math.Tanh(2.4) == 9.8367485769368024E-001

                       Math.Tanh(4.9) == 9.9988910295055444E-001
      Math.Sinh(4.9) / Math.Cosh(4.9) == 9.9988910295055433E-001
                   2 * Math.Tanh(4.9) /
             (1 + (Math.Tanh(4.9))^2) == 9.9999999385024030E-001
                       Math.Tanh(9.8) == 9.9999999385024030E-001

Evaluate [tanh(X + Y) == (tanh(X) + tanh(Y)) / (1 + tanh(X) * tanh(Y))]
with selected values for X and Y:

    (Math.Tanh(0.1) + Math.Tanh(1.2)) /
(1 + Math.Tanh(0.1) * Math.Tanh(1.2)) == 8.6172315931330645E-001
                       Math.Tanh(1.3) == 8.6172315931330634E-001

    (Math.Tanh(1.2) + Math.Tanh(4.9)) /
(1 + Math.Tanh(1.2) * Math.Tanh(4.9)) == 9.9998993913939649E-001
                       Math.Tanh(6.1) == 9.9998993913939649E-001
*/

[C++] 
// Example for the hyperbolic Math::Tanh( double ) method.
#using <mscorlib.dll>
using namespace System;

// Evaluate hyperbolic identities with a given argument.
void UseTanh(double arg)
{
    double tanhArg = Math::Tanh(arg);

    // Evaluate tanh(X) == sinh(X) / cosh(X).
    Console::WriteLine( 
        S"\n                        Math::Tanh({0}) == {1:E16}\n" 
        S"      Math::Sinh({0}) / Math::Cosh({0}) == {2:E16}",
        __box(arg), __box(tanhArg), 
        __box((Math::Sinh(arg) / Math::Cosh(arg))) );

    // Evaluate tanh(2 * X) == 2 * tanh(X) / (1 + tanh^2(X)).
    Console::WriteLine( 
        S"                    2 * Math::Tanh({0}) /", 
        __box(arg), __box(2.0 * tanhArg) );
    Console::WriteLine( 
        S"              (1 + (Math::Tanh({0}))^2) == {1:E16}", 
        __box(arg), __box(2.0 * tanhArg / (1.0 + tanhArg * tanhArg )) );
    Console::WriteLine( 
        S"                        Math::Tanh({0}) == {1:E16}", 
        __box(2.0 * arg), __box(Math::Tanh(2.0 * arg)) );
}

// Evaluate a hyperbolic identity that is a function of two arguments.
void UseTwoArgs(double argX, double argY)
{
    // Evaluate tanh(X + Y) == (tanh(X) + tanh(Y)) / (1 + tanh(X) * tanh(Y)).
    Console::WriteLine( 
        S"\n    (Math::Tanh({0}) + Math::Tanh({1})) /\n" 
        S"(1 + Math::Tanh({0}) * Math::Tanh({1})) == {2:E16}", 
        __box(argX), __box(argY), 
        __box((Math::Tanh(argX) + Math::Tanh(argY)) /
            (1.0 + Math::Tanh(argX) * Math::Tanh(argY))) );
    Console::WriteLine( 
        S"                        Math::Tanh({0}) == {1:E16}",
        __box(argX + argY), 
        __box(Math::Tanh(argX + argY)) );
}

void main() 
{
    Console::WriteLine( 
        S"This example of hyperbolic Math::Tanh( double )\n" 
        S"generates the following output." );
    Console::WriteLine( 
        S"\nEvaluate these hyperbolic identities "
        S"with selected values for X:" );
    Console::WriteLine( S"   tanh(X) == sinh(X) / cosh(X)" );
    Console::WriteLine( 
        S"   tanh(2 * X) == 2 * tanh(X) / (1 + tanh^2(X))" );

    UseTanh(0.1);
    UseTanh(1.2);
    UseTanh(4.9);

    Console::WriteLine( 
        S"\nEvaluate [tanh(X + Y) == "
        S"(tanh(X) + tanh(Y)) / (1 + tanh(X) * tanh(Y))]" 
        S"\nwith selected values for X and Y:" );

    UseTwoArgs(0.1, 1.2);
    UseTwoArgs(1.2, 4.9);
}

/*
This example of hyperbolic Math::Tanh( double )
generates the following output.

Evaluate these hyperbolic identities with selected values for X:
   tanh(X) == sinh(X) / cosh(X)
   tanh(2 * X) == 2 * tanh(X) / (1 + tanh^2(X))

                        Math::Tanh(0.1) == 9.9667994624955819E-002
      Math::Sinh(0.1) / Math::Cosh(0.1) == 9.9667994624955819E-002
                    2 * Math::Tanh(0.1) /
              (1 + (Math::Tanh(0.1))^2) == 1.9737532022490401E-001
                        Math::Tanh(0.2) == 1.9737532022490401E-001

                        Math::Tanh(1.2) == 8.3365460701215521E-001
      Math::Sinh(1.2) / Math::Cosh(1.2) == 8.3365460701215521E-001
                    2 * Math::Tanh(1.2) /
              (1 + (Math::Tanh(1.2))^2) == 9.8367485769368024E-001
                        Math::Tanh(2.4) == 9.8367485769368024E-001

                        Math::Tanh(4.9) == 9.9988910295055444E-001
      Math::Sinh(4.9) / Math::Cosh(4.9) == 9.9988910295055433E-001
                    2 * Math::Tanh(4.9) /
              (1 + (Math::Tanh(4.9))^2) == 9.9999999385024030E-001
                        Math::Tanh(9.8) == 9.9999999385024030E-001

Evaluate [tanh(X + Y) == (tanh(X) + tanh(Y)) / (1 + tanh(X) * tanh(Y))]
with selected values for X and Y:

    (Math::Tanh(0.1) + Math::Tanh(1.2)) /
(1 + Math::Tanh(0.1) * Math::Tanh(1.2)) == 8.6172315931330645E-001
                        Math::Tanh(1.3) == 8.6172315931330634E-001

    (Math::Tanh(1.2) + Math::Tanh(4.9)) /
(1 + Math::Tanh(1.2) * Math::Tanh(4.9)) == 9.9998993913939649E-001
                        Math::Tanh(6.1) == 9.9998993913939649E-001
*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Math Class | Math Members | System Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft