Math Object In TypeScript: Part2

Math Object In TypeScript: Part2 

 
Before reading this article, please go through the following articles:
  1. asin(), acos() and atan() method in typescript 

Introduction

 
In TypeScript, the math object is a built-in object that provides many specialized mathematical methods and numerical values. The math object is used to handle values within the range of integer and float types. The math object also provides many trigonometric and logarithmic methods. If you have the appropriate mathematical background, you should be able to use these methods with no problem.
 
In this article, I am describing some of the TypeScript math functions.
 

Atan2() Method

 
In TypeScript, the Atan() method returns a numeric value between -pi/2 and pi/2 radians representing the angle theta of an (x,y) point. The x coordinate is passed as the second argument and the y coordinate is passed as the first argument.
  
Syntax
  1. Atan2 (x,y)  
Function
  1. Atan2(num: number) {  
  2.  var a = 6;  
  3.  var span = document.createElement("span");  
  4.  span.innerText = "The arctangent of " + num + "/" + a + " is -> " + Math.atan2(num, a) + "\n";  
  5.  document.body.appendChild(span);  
  6. }  

Exp() Method

 
In TypeScript, The exp method returns Enum, where num is the argument, and E is Euler's constant, the base of the natural logarithms. The approximate value of E is 2.7183.
 
Syntax
  1. exp (number)  
Function
  1. Exp(num: number) {  
  2.  var span = document.createElement("span");  
  3.  span.innerText = "The E of " + num + " is -> " + Math.exp(num) + "\n";  
  4.  document.body.appendChild(span);  
  5. }  

Ceil() Method

 
In TypeScript, the ceil method rounds a number UPWARDS to the nearest integer. It returns the smallest integer greater than or equal to a number. If the argument value is an integer, the value will not be rounded.
 
Syntax
  1. ceil(number)   
Function
  1. Ceil(num: number) {  
  2.  var span = document.createElement("span");  
  3.  span.innerText = "The Ceil value of " + num + " is -> " + Math.ceil(num);  
  4.  document.body.appendChild(span);  
  5. }  

Complete Program

 
ATAN_Exp_Ceil.ts
  1. class Math_Object  
  2. {  
  3.  Atan2(num: number)  
  4.  {  
  5.   var a = 6;  
  6.   var span = document.createElement("span");  
  7.   span.innerText = "The arctangent of " + num + "/" + a + " is -> " + Math.atan2(num, a) + "\n";  
  8.   document.body.appendChild(span);  
  9.  }  
  10.  Exp(num: number)  
  11.  {  
  12.   var span = document.createElement("span");  
  13.   span.innerText = "The E of " + num + " is -> " + Math.exp(num) + "\n"// E is the Euler's Number  
  14.   document.body.appendChild(span);  
  15.  }  
  16.  Ceil(num: number)  
  17.  {  
  18.   var span = document.createElement("span");  
  19.   span.innerText = "The Ceil value of " + num + " is -> " + Math.ceil(num);  
  20.   document.body.appendChild(span);  
  21.  }  
  22. }  
  23. window.onload = () =>  
  24.  {  
  25.   var obj = new Math_Object();  
  26.   var num = parseFloat(prompt("Enter a number for calculate Atan2,Exp and Ceil"));  
  27.   obj.Atan2(num);  
  28.   obj.Exp(num);  
  29.   obj.Ceil(num);  
  30.  };  
Atan2_Exp_Ceil.htm
  1. <!DOCTYPE html>  
  2. <html lang="en"  
  3.     xmlns="http://www.w3.org/1999/xhtml">  
  4.     <head>  
  5.         <meta charset="utf-8" />  
  6.         <title>TypeScript HTML App</title>  
  7.         <link rel="stylesheet" href="app.css" type="text/css" />  
  8.         <script src="ATAN_ciel_exp.js"></script>  
  9.     </head>  
  10.     <body>  
  11.         <h3>Atan2,Exp and Ceil Math Function in TypeScript</h3>  
  12.         <div id="content"/>  
  13.     </body>  
  14. </html>  
ATAN_ciel_exp.js
  1. var Math_Object = (function() {  
  2.  function Math_Object() {}  
  3.  Math_Object.prototype.Atan2 = function(num) {  
  4.   var a = 6;  
  5.   var span = document.createElement("span");  
  6.   span.innerText = "The arctangent of " + num + "/" + a + " is -> " + Math.atan2(num, a) + "\n";  
  7.   document.body.appendChild(span);  
  8.  };  
  9.  Math_Object.prototype.Exp = function(num) {  
  10.   var span = document.createElement("span");  
  11.   span.innerText = "The E of " + num + " is -> " + Math.exp(num) + "\n";  
  12.   document.body.appendChild(span);  
  13.  };  
  14.  Math_Object.prototype.Ceil = function(num) {  
  15.   var span = document.createElement("span");  
  16.   span.innerText = "The Ceil value of " + num + " is -> " + Math.ceil(num);  
  17.   document.body.appendChild(span);  
  18.  };  
  19.  return Math_Object;  
  20. })();  
  21. window.onload = function() {  
  22.  var obj = new Math_Object();  
  23.  var num = parseFloat(prompt("Enter a number for calculate Atan2,Exp and Ceil"));  
  24.  obj.Atan2(num);  
  25.  obj.Exp(num);  
  26.  obj.Ceil(num);  
  27. };  
Output 1
 
enter-num.gif
 
Output 2
 
result.gif


Similar Articles