본 문서는 JavaScript 수학 내장 객체(Math)가 제공하는 삼각함수, 지수/로그, 최댓값/최솟값, 거듭제곱 및 난수 생성 메서드(cos, cosh, exp, floor, log, max, min, pow, random)의 동작 원리와 활용법을 분석한 내용입니다.
<!DOCTYPE html>
<html>
<head><title>Math 메소드2</title></head>
<body>
<h3>Math 객체 메소드2</h3>
<br>var x =1.00 , y = 3 ;
<br>Math.cos(1) : <b id="ca"></b>
<br>Math.cosh(1) : <b id="cca"></b>
<br>Math.exp(1) : <b id="cnct"></b>
<br>Math.floor(1) : <b id="ido"></b>
<br>Math.log(1): <b id="vlf"></b>
<br>Math.max(x,3,0.3,12): <b id="fxd"></b>
<br>Math.min(1,3,0.3,12) : <b id="prc"></b>
<br>Math.pow(1,y) : <b id="exp"></b>
<br>Math.random() : <b id="str"></b>
<script>
var x = 1.00, y = 3;
document.getElementById("ca").innerHTML = Math.cos(x);
document.getElementById("cca").innerHTML = Math.cosh(x);
document.getElementById("cnct").innerHTML = Math.exp(x);
document.getElementById("ido").innerHTML = Math.floor(x);
document.getElementById("vlf").innerHTML = Math.log(x);
document.getElementById("fxd").innerHTML = Math.max(x, 3, 0.3, 12);
document.getElementById("prc").innerHTML = Math.min(x, 3, 0.3, 12);
document.getElementById("exp").innerHTML = Math.pow(x, y);
document.getElementById("str").innerHTML = Math.random();
</script>
</body>
</html>
Math 객체 메소드2)을 정의합니다.ca, cca, exp 등의 고유 ID가 부여되어 있습니다.x = 1.00, y = 3)| 메서드명 | 사용 예시 | 동작 설명 및 의미 |
|---|---|---|
Math.cos() |
Math.cos(1) |
주어진 각도(라디안)의 코사인 값을 반환합니다. ➔ 0.5403023058681398 |
Math.cosh() |
Math.cosh(1) |
쌍곡코사인 값을 반환합니다. ➔ 1.5430806348152437 |
Math.exp() |
Math.exp(1) |
오일러 상수 $e$의 거듭제곱($e^1$) 값을 반환합니다. ➔ 2.718281828459045 |
Math.floor() |
Math.floor(1) |
인수로 전달된 숫자와 같거나 작은 정수 중 가장 큰 수(내림)를 반환합니다. ➔ 1 |
Math.log() |
Math.log(1) |
자연로그 값($\ln(1)$)을 반환합니다. ➔ 0 |
Math.max() |
Math.max(1, 3, 0.3, 12) |
전달된 인수들 중 가장 큰 값을 반환합니다. ➔ 12 |
Math.min() |
Math.min(1, 3, 0.3, 12) |
전달된 인수들 중 가장 작은 값을 반환합니다. ➔ 0.3 |
Math.pow() |
Math.pow(1, 3) |
베이스 숫자의 지정된 거듭제곱 값($1^3$)을 반환합니다. ➔ 1 |
Math.random() |
Math.random() |
0 이상 1 미만의 무작위 난수(Pseudo-random number)를 반환합니다. ➔ (실행 시마다 무작위 소수 반환, 예: 0.812...) |
Math 객체 메소드2
Math.cos(1) : 0.5403023058681398
Math.cosh(1) : 1.5430806348152437
Math.exp(1) : 2.718281828459045
Math.floor(1) : 1
Math.log(1): 0
Math.max(x,3,0.3,12): 12
Math.min(1,3,0.3,12) : 0.3
Math.pow(1,y) : 1
Math.random() : (0 이상 1 미만의 난수 출력)