카테고리 없음

루트 값과 제곱값 구하는 방법

taehyon 2025. 5. 1. 10:04

 

Math.sqrt( ) 와 Math.pow( )에 대해서 알아보자

 

먼저 Math.sqrt( )로 루트값을 구할 수 있다.

 

Math.sqrt(9);		// 3
Math.sqrt(25);		// 5
Math.sqrt(100);		// 10
Math.sqrt(2); 		// 1.414213562373095
Math.sqrt(-1); 		// NaN

 

제곱값 구하는 방법 Math.pow( )

 

Math.pow(base, exponent)

 

base 에는 제곱하고 싶은 숫자를

 

exponent 에는 base를 몇번 제곱할지 적으면 된다.

 

// simple
Math.pow(7, 2);    	// 49
Math.pow(7, 3);    	// 343
Math.pow(2, 10);   	// 1024

// fractional exponents
Math.pow(4, 0.5);  	// 2 (square root of 4)
Math.pow(8, 1/3);  	// 2 (cube root of 8)

// signed exponents
Math.pow(7, -2);   	// 0.02040816326530612 (1/49)
Math.pow(8, -1/3); 	// 0.5

// signed bases
Math.pow(-6, 2);   	// 36 (squares are positive)
Math.pow(-6, 3);   	// -216 (cubes can be negative)
Math.pow(-6, 1/3); 	// NaN