CoffeeScript Math - CoffeeScript

What is CoffeeScript Math?

The math object of JavaScript gives you homes and techniques for mathematical constants and functions. in contrast to other global items, Math is not a constructor. all the homes and strategies of Math are static and can be called by using Math as an item without creating it.

Hence, you refer to the regular pi as Math. PI and you name the sine function as Math.sin(x), wherein x is the approach's argument. We can use the JavaScript's Math item in our CoffeeScript code to carry out math operations.

Mathematical constants

If we want to apply any common mathematical constants like pi or e we will use them the use of the JavaScript's Math object.
Following is the listing of the maths constants furnished through the maths item of JavaScript

S.No.

Property & Description

1

E

Euler's constant and the base of natural logarithms, approximately 2.718.

2

LN2

Natural logarithm of 2, approximately 0.693.

3

LN10

Natural logarithm of 10, approximately 2.302.

4

LOG2E

Base 2 logarithm of E, approximately 1.442.

5

LOG10E

Base 10 logarithm of E, approximately 0.434.

6

PI

Ratio of the circumference of a circle to its diameter, approximately 3.14159.

7

SQRT1_2

Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707.

8

SQRT2

Square root of 2, approximately 1.414.

Example

The following example demonstrates the usage of the mathematical constants provided by JavaScript in CoffeeScript. Save this code in a file with name math_example.coffee

Open the command prompt and compile the .coffee file as shown below.

On compiling, it gives you the following JavaScript.

Now, open the command prompt again and run the CoffeeScript file as shown below.

On executing, the CoffeeScript file produces the following output.

Math strategies

In addition to houses, the mathematics object additionally gives techniques. Following is the listing of techniques of the math item of JavaScript. Click on the name of those strategies to get an example demonstrating their utilization in CoffeeScript.

On executing, the CoffeeScript file produces the following output.

Math strategies

In addition to houses, the mathematics object additionally gives techniques. Following is the listing of techniques of the math item of JavaScript. Click on the name of those strategies to get an example demonstrating their utilization in CoffeeScript.

S.No.

Method & Description

1

abs()

Returns the absolute value of a number.

2

acos()

Returns the arccosine (in radians) of a number.

3

asin()

Returns the arcsine (in radians) of a number.

4

atan()

Returns the arctangent (in radians) of a number.

5

atan2()

Returns the arctangent of the quotient of its arguments.

6

ceil()

Returns the smallest integer greater than or equal to a number.

7

cos()

Returns the cosine of a number.

8

exp()

Returns EN, where N is the argument, and E is Euler's constant, the base of the natural logarithm.

9

floor()

Returns the largest integer less than or equal to a number.

10

log()

Returns the natural logarithm (base E) of a number.

11

max()

Returns the largest of zero or more numbers.

12

min()

Returns the smallest of zero or more numbers.

13

pow()

Returns base to the exponent power, that is, base exponent.

14

random()

Returns a pseudo-random number between 0 and 1.

15

round()

Returns the value of a number rounded to the nearest integer.

16

sin()

Returns the sine of a number.

17

sqrt()

Returns the square root of a number.

18

tan()

Returns the tangent of a number.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

CoffeeScript Topics