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

What are the functions for finding roots in javascript?

青灯夜游
Release: 2021-12-08 18:25:36
Original
4964 people have browsed it

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)
Copy after login

Example:

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

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template