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

atan2 (x,y)


Function


Atan2(num:number)

    {

        var a = 6;

        var span = document.createElement("span");

        span.innerText ="The arctangent of " +num+"/"+a+ " is -> "+ Math.atan2(num,a)+"\n";

        document.body.appendChild(span); 

    }

 

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

exp (number)


Function


Exp(num:number)

    {

        var span = document.createElement("span");

        span.innerText ="The E of " +num+ " is -> "+ Math.exp(num)+"\n"; // E is the Euler's Number

        document.body.appendChild(span); 

    }

 

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

ceil(number)

Function

Ceil(num:number)

    {

        var span = document.createElement("span");

        span.innerText ="The Ceil value of " +num+ " is -> "+ Math.ceil(num);

        document.body.appendChild(span); 

    }

 

Complete Program

ATAN_Exp_Ceil.ts

class Math_Object

{

    Atan2(num:number)

    {

        var a = 6;

        var span = document.createElement("span");

        span.innerText ="The arctangent of " +num+"/"+a+ " is -> "+ Math.atan2(num,a)+"\n";

        document.body.appendChild(span); 

    }

    Exp(num:number)

    {

        var span = document.createElement("span");

        span.innerText ="The E of " +num+ " is -> "+ Math.exp(num)+"\n"; // E is the Euler's Number

        document.body.appendChild(span); 

    }

    Ceil(num:number)

    {

        var span = document.createElement("span");

        span.innerText ="The Ceil value of " +num+ " is -> "+ Math.ceil(num);

        document.body.appendChild(span); 

    }

}

window.onload = () =>

{

    var obj = new Math_Object();

    var num = parseFloat(prompt("Enter a number for calculate Atan2,Exp and Ceil"));

    obj.Atan2(num);

    obj.Exp(num);

    obj.Ceil(num);   

};

Atan2_Exp_Ceil.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="ATAN_ciel_exp.js"></script>

</head>

<body>

    <h3>Atan2,Exp and Ceil Math Function in TypeScript</h3>

    <div id="content"/>

</body>

</html>

ATAN_ciel_exp.js

var Math_Object = (function () {

    function Math_Object() { }

    Math_Object.prototype.Atan2 = function (num) {

        var a = 6;

        var span = document.createElement("span");

        span.innerText = "The arctangent of " + num + "/" + a + " is -> " + Math.atan2(num, a) + "\n";

        document.body.appendChild(span);

    };

    Math_Object.prototype.Exp = function (num) {

        var span = document.createElement("span");

        span.innerText = "The E of " + num + " is -> " + Math.exp(num) + "\n";

        document.body.appendChild(span);

    };

    Math_Object.prototype.Ceil = function (num) {

        var span = document.createElement("span");

        span.innerText = "The Ceil value of " + num + " is -> " + Math.ceil(num);

        document.body.appendChild(span);

    };

    return Math_Object;

})();

window.onload = function () {

    var obj = new Math_Object();

    var num = parseFloat(prompt("Enter a number for calculate Atan2,Exp and Ceil"));

    obj.Atan2(num);

    obj.Exp(num);

    obj.Ceil(num);

};

//@ sourceMappingURL=ATAN_ciel_exp.js.map

 

Output 1


enter-num.gif


Output 2


result.gif

Up Next
    Ebook Download
    View all

    Test

    Read by 16 people
    Download Now!
    Learn
    View all