Math Object In TypeScript: Part 6

Math Object In TypeScript: Part 6 

 
Before reading this article, please go through the following articles:
  1. asin(), acos() and atan() method in typescript
  2. atan2(), exp() and ceil() method in typescript
  3. floor(), log() and round() method in typescript
  4. sin(), cos() and tan() method in typescript
  5. pow(), sqrt() and random() 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.
 

max() Method

 
In TypeScript the max() method is used to get the maximum value among all the values given to it. If do not pass it anything then it will return infinity as a result.
 
Syntax
  1. max(value1, value2, value3, value4........)  
Function
  1. Max() {  
  2.  var span = document.createElement("span");  
  3.  span.style.color = "Blue";  
  4.  span.innerText = "Maximum number in given values is -> " + Math.max(5, 8, 12, 2, 15) + "\n";  
  5.  document.body.appendChild(span);  
  6. }  

min() Method

 
In TypeScript the min() method is used to get the minimum value among the values given to it. If do not pass it anything then it will return infinity as a result.
 
Syntax
  1. min(value1, value2, value3, value4........)  
Function
  1. Min() {  
  2.  var span = document.createElement("span");  
  3.  span.style.color = "green";  
  4.  span.innerText = "Manimum number in given values is -> " + Math.min(5, 8, 12, 2, 15) + "\n";  
  5.  document.body.appendChild(span);  
  6. }  

Complete Program

 
Min_Max.ts
  1. class Min_Max_function {  
  2.  Max() {  
  3.   var span = document.createElement("span");  
  4.   span.style.color = "Blue";  
  5.   span.innerText = "Maximum number in given values is -> " + Math.max(5, 8, 12, 2, 15) + "\n";  
  6.   document.body.appendChild(span);  
  7.  }  
  8.  Min() {  
  9.   var span = document.createElement("span");  
  10.   span.style.color = "green";  
  11.   span.innerText = "Manimum number in given values is -> " + Math.min(5, 8, 12, 2, 15) + "\n";  
  12.   document.body.appendChild(span);  
  13.  }  
  14. }  
  15. window.onload = () => {  
  16.  var obj = new Min_Max_function();  
  17.  obj.Max();  
  18.  obj.Min();  
  19. };  
Min_Max.htm
  1. < !DOCTYPE html >  
  2.  <  
  3.  html lang = "en"  
  4. xmlns = "http://www.w3.org/1999/xhtml" >  
  5.  <  
  6.  head >  
  7.  <  
  8.  meta charset = "utf-8" / >  
  9.  <  
  10.  title > TypeScript HTML App < /title>  
  11.  <  
  12.  link rel = "stylesheet"  
  13. href = "app.css"  
  14. type = "text/css" / >  
  15.  <  
  16.  script src = "Min_Max.js" > < /script>  
  17.  <  
  18.  /head>  
  19.  <  
  20.  body >  
  21.  <  
  22.  h3 > Min and Max Math Function in TypeScript < /h3>  
  23.  <  
  24.  div id = "content" / >  
  25.  <  
  26.  /body>  
  27.  <  
  28.  /html>  
Min_Max.js
  1. var Min_Max_function = (function() {  
  2.  function Min_Max_function() {}  
  3.  Min_Max_function.prototype.Max = function() {  
  4.   var span = document.createElement("span");  
  5.   span.style.color = "Blue";  
  6.   span.innerText = "Maximum number in given values is -> " + Math.max(5, 8, 12, 2, 15) + "\n";  
  7.   document.body.appendChild(span);  
  8.  };  
  9.  Min_Max_function.prototype.Min = function() {  
  10.   var span = document.createElement("span");  
  11.   span.style.color = "green";  
  12.   span.innerText = "Manimum number in given values is -> " + Math.min(5, 8, 12, 2, 15) + "\n";  
  13.   document.body.appendChild(span);  
  14.  };  
  15.  return Min_Max_function;  
  16. })();  
  17. window.onload = function() {  
  18.  var obj = new Min_Max_function();  
  19.  obj.Max();  
  20.  obj.Min();  
  21. };  
Output
 
final-output.gif


Similar Articles