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.
Asin() function
In TypeScript the asin() method returns a numeric value between -pi/2 and pi/2 radians for x between -1 and 1. If the value of a number is outside this range then it returns NaN.
Syntax
function
Asin(num:number)
{
var span = document.createElement("span");
span.innerText ="The arcsine of " +num+ " is -> "+ Math.asin(num)+"\n";
document.body.appendChild(span);
}
Acos() function
In TypeScript the acos method returns a numeric value between 0 and pi radians for x between -1 and 1. If the value of a number is outside this range then it returns NaN.
Syntax
function
Acos(num:number)
{
var span = document.createElement("span");
span.innerText ="The arccosine of " +num+ " is -> "+ Math.acos(num)+"\n";
document.body.appendChild(span);
}
Atan() function
In TypeScript the atan() method returns a numeric value between -pi/2 and pi/2 radians.
Syntax
function
Atan(num:number)
{
var span = document.createElement("span");
span.innerText ="The arctangent of " +num+ " is -> "+ Math.atan(num);
document.body.appendChild(span);
}
Complete Program
Function.ts
class Greeter
{
Asin(num:number)
{
var span = document.createElement("span");
span.innerText ="The arcsine of " +num+ " is -> "+ Math.asin(num)+"\n";
document.body.appendChild(span);
}
Acos(num:number)
{
var span = document.createElement("span");
span.innerText ="The arccosine of " +num+ " is -> "+ Math.acos(num)+"\n";
document.body.appendChild(span);
}
Atan(num:number)
{
var span = document.createElement("span");
span.innerText ="The arctangent of " +num+ " is -> "+ Math.atan(num);
document.body.appendChild(span);
}
}
window.onload = () =>
{
var obj = new Greeter();
var num = parseFloat(prompt("Enter a number for calculate Asin,Acos and Atan"));
obj.Asin(num);
obj.Acos(num);
obj.Atan(num);
};
default.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="app.js"></script>
</head>
<body>
<h2>Asin,Acos and Atan Math Function in TypeScript</h2>
<div id="content"/>
</body>
</html>
app.js
var Greeter = (function () {
function Greeter() { }
Greeter.prototype.Asin = function (num) {
var span = document.createElement("span");
span.innerText = "The arcsine of " + num + " is -> " + Math.asin(num) + "\n";
document.body.appendChild(span);
};
Greeter.prototype.Acos = function (num) {
var span = document.createElement("span");
span.innerText = "The arccosine of " + num + " is -> " + Math.acos(num) + "\n";
document.body.appendChild(span);
};
Greeter.prototype.Atan = function (num) {
var span = document.createElement("span");
span.innerText = "The arctangent of " + num + " is -> " + Math.atan(num);
document.body.appendChild(span);
};
return Greeter;
})();
window.onload = function () {
var obj = new Greeter();
var num = parseFloat(prompt("Enter a number for calculate Asin,Acos and Atan"));
obj.Asin(num);
obj.Acos(num);
obj.Atan(num);
};
//@ sourceMappingURL=app.js.map
Output 1
Output 2