Before reading this article, please go through the following articles:
- asin(), acos() and atan() method in typescript
- atan2(), exp() and ceil() method in typescript
- floor(), log() and round() method in typescript
- sin(), cos() and tan() method in typescript
- 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
max(value1,value2,value3,value4........) |
Function
Max()
{
var span = document.createElement("span");
span.style.color = "Blue";
span.innerText = "Maximum number in given values is -> "+ Math.max(5,8,12,2,15) + "\n";
document.body.appendChild(span);
}
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
min(value1,value2,value3,value4........) |
Function
Min()
{
var span = document.createElement("span");
span.style.color = "green";
span.innerText = "Manimum number in given values is -> " + Math.min(5, 8, 12, 2, 15) + "\n";
document.body.appendChild(span);
}
Complete Program
Min_Max.ts
class Min_Max_function
{
Max()
{
var span = document.createElement("span");
span.style.color = "Blue";
span.innerText = "Maximum number in given values is -> "+ Math.max(5,8,12,2,15) + "\n";
document.body.appendChild(span);
}
Min()
{
var span = document.createElement("span");
span.style.color = "green";
span.innerText = "Manimum number in given values is -> " + Math.min(5, 8, 12, 2, 15) + "\n";
document.body.appendChild(span);
}
}
window.onload = () =>
{
var obj = new Min_Max_function();
obj.Max();
obj.Min();
};
Min_Max.htm
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>TypeScript HTML App</title>
<link rel="stylesheet" href="app.css" type="text/css" />
<script src="Min_Max.js"></script>
</head>
<body>
<h3>Min and Max Math Function in TypeScript</h3>
<div id="content"/>
</body>
</html>
Min_Max.js
var Min_Max_function = (function () {
function Min_Max_function() { }
Min_Max_function.prototype.Max = function () {
var span = document.createElement("span");
span.style.color = "Blue";
span.innerText = "Maximum number in given values is -> " + Math.max(5, 8, 12, 2, 15) + "\n";
document.body.appendChild(span);
};
Min_Max_function.prototype.Min = function () {
var span = document.createElement("span");
span.style.color = "green";
span.innerText = "Manimum number in given values is -> " + Math.min(5, 8, 12, 2, 15) + "\n";
document.body.appendChild(span);
};
return Min_Max_function;
})();
window.onload = function () {
var obj = new Min_Max_function();
obj.Max();
obj.Min();
};
//@ sourceMappingURL=Min_Max.js.map
Output