Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Math Object In TypeScript: Part 1
WhatsApp
Nitin Bhardwaj
5y
20.9k
0
0
100
Article
MathMethodInTypeScript.rar
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
asin (number)
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
acos (number)
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
acos(number)
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);
};
Output 1
Output 2
acos method in TypeScript
asin method in TypeScript
atan method in typescript
math method
Math object
typescript
Up Next
Ebook Download
View all
TypeScript: Beginner To Advanced
Read by 10.3k people
Download Now!
Learn
View all
Membership not found