Math.cosh() (Simulated functionality)

The cosh() function is not available in JavaScript but can be simulated to aid in the porting of existing code.

The example demonstrates how to add the cosh() method to the Math object.

Example code:

   <HTML>

   <HEAD>

   </HEAD>

   <BODY>

   <SCRIPT>

   // Add the cosh function to the Math object

   function cosh(aValue)

   {

   var myTerm1 = Math.pow(Math.E, aValue);

   var myTerm2 = Math.pow(Math.E, -aValue);

   

   return (myTerm1+myTerm2)/2;

   }

   // Register the new function

   Math.constructor.prototype.cosh = cosh;

   // Test the Math.cosh() method

   document.write(Math.cosh(2))

   document.write("<BR>")

   </SCRIPT>

   </BODY>

   </HTML>