JavaScript Tutorial.33

ansunny1170·2021년 12월 22일
0
post-thumbnail

JS MATH OBJECT

JS Math 객체를 사용하면 숫자에 대한 수학 작업을 수행할 수 있다.

The Math Object

다른 객체와 달리 Math 객체에는 생성자가 없다.
Math 개체는 정적이다.
Math 개체를 먼저 생성하지 않고도 모든 메서드와 속성을 사용할 수 있다.

Math Properties (Constants)

모든 Math 속성 구문Math.property다.
JavaScript는 Math 속성으로 액세스할 수 있는 8개의 수학 상수를 제공한다.

Math Methods

모든 Math 메서드 구문은 다음과 같다. Math.method(number)

Number to Integer(숫자를 정수로)

숫자를 정수로 반올림하는 4가지 일반적인 방법 :

Math.round(x)Returns x rounded to its nearest integer
Math.ceil(x)Returns x rounded up to its nearest integer
Math.floor(x)Returns x rounded down to its nearest integer
Math.trunc(x)Returns the integer part of x (new in ES6)

Math.round()

Math.round(x)는 가장 가까운 정수를 반환한다.

Math.ceil()

Math.ceil(x)는 가장 가까운 정수로 반올림된 x 값을 반환한다.

Math.floor()

Math.floor(x)는 가장 가까운 정수로 내림한 x 값을 반환한다.

Math.trunc()

Math.trunc(x)는 x의 정수 부분을 반한다.

Math.sign()

Math.sign(x)x음수, null 또는 양수이면 반환한다.

Math.trunc()Math.sign()은 JavaScript 2015 - ES6에 추가되었다.

Math.pow()

Math.pow(x, y)x의 값을 y의 거듭제곱으로 반환한다.

Math.sqrt()

Math.sqrt(x)x의 제곱근을 반환한다.

Math.abs()

Math.abs(x)x의 절대값을 반환한다.

Math.sin()

Math.sin(x)는 각도 x(라디안으로 지정)의 sin 값을 반환한다.
라디안 대신 각도를 사용하려면 각도라디안으로 변환해야 한다.
라디안 단위 각도 = 각도 x PI / 180

Math.cos()

Math.cos(x)는 각도 x(라디안으로 지정)의 cos 값을 반환한다.
라디안 대신 각도를 사용하려면 각도라디안으로 변환해야 한다.
라디안 단위 각도 = 각도 x PI / 180

Math.min() and Math.max()

Math.min()Math.max()는 인수 목록에서 가장 낮거나 높은 값을 찾는 데 사용할 수 있다.

Math.random()

Math.random()은 0≤ x <1 사이의 난수를 반환한다.

이 튜토리얼의 다음 장에서 Math.random()에 대해 자세히 알아보자.

The Math.log() Method

JS의 Math.log() 함수는 ln(x)와 수학적으로 같다.
밑이 e인 log함수를 자연로그라 한다.

Math.EMath.log()는 동일하다.

The Math.log2() Method

Math.log2(x)x의 밑이 2인 로그를 반환한다.

The Math.log10() Method

Math.log10(x)x의 밑이 10인 로그를 반환한다.

JavaScriptb Math Methods

MethodDescription
abs(x)Returns the absolute value of x
acos(x)Returns the arccosine of x, in radians
acosh(x)Returns the hyperbolic arccosine of x
asin(x)Returns the arcsine of x, in radians
asinh(x)Returns the hyperbolic arcsine of x
atan(x)Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians
atan2(y, x)Returns the arctangent of the quotient of its arguments
atanh(x)Returns the hyperbolic arctangent of x
cbrt(x)Returns the cubic root of x
ceil(x)Returns x, rounded upwards to the nearest integer
cos(x)Returns the cosine of x (x is in radians)
cosh(x)Returns the hyperbolic cosine of x
exp(x)Returns the value of Ex
floor(x)Returns x, rounded downwards to the nearest integer
log(x)Returns the natural logarithm (base E) of x
max(x, y, z, ..., n)Returns the number with the highest value
min(x, y, z, ..., n)Returns the number with the lowest value
pow(x, y)Returns the value of x to the power of y
random()Returns a random number between 0 and 1
round(x)Rounds x to the nearest integer
sign(x)Returns if x is negative, null or positive (-1, 0, 1)
sin(x)Returns the sine of x (x is in radians)
sinh(x)Returns the hyperbolic sine of x
sqrt(x)Returns the square root of x
tan(x)Returns the tangent of an angle
tanh(x)Returns the hyperbolic tangent of a number
trunc(x)Returns the integer part of a number (x)

Complete Math Reference

Math 객체에 대한 완벽한 내용 참고를 위해 아래 주소를 참조하자
(참조 : JavaScript Math Reference)

profile
공정 설비 개발/연구원에서 웹 서비스 개발자로 경력 이전하였습니다. Node.js 백엔드 기반 풀스택 개발자를 목표로 하고 있습니다.

0개의 댓글