Home  >  Article  >  Web Front-end  >  What are the functions for finding roots in javascript?

What are the functions for finding roots in javascript?

青灯夜游
青灯夜游Original
2021-12-08 18:25:364857browse

Function for finding roots in JavaScript: 1. sqrt() function, syntax "Math.sqrt(x)", which can calculate the square root of the number x; 2. pow() function, syntax "Math.pow( x,(1/y))", can calculate the y-th root of the number x.

What are the functions for finding roots in javascript?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

javascript root finding

1. Use the sqrt() function

sqrt() method Returns the square root of a number.

Syntax:

Math.sqrt(x)

Example:

var x=9;
console.log(Math.sqrt(x));

Output result:

What are the functions for finding roots in javascript?

2. Use the pow() function

Math.pow(x,y)can raise the y power of x. When y is a decimal (1/y), it can be used for root calculation.

function f(x,y){
	y=1/y;
	console.log(Math.pow(x,y));
}
f(4,2);
f(125,3);
f(81,4);

What are the functions for finding roots in javascript?

【Related recommendations: javascript learning tutorial

The above is the detailed content of What are the functions for finding roots in javascript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn