Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do most programming languages only give one answer to square root of 4?

Most programming languages give 2 as the answer to square root of 4. However, there are two answers: 2 and -2. Is there any particular reason, historical or otherwise, why only one answer is usually given?

like image 727
bugmagnet Avatar asked May 08 '09 04:05

bugmagnet


People also ask

Why are there two answers to every square root?

The square root of a number always has two answers, one is positive and one is negative. There are two answers because the square of a negative and positive number is the same.

What is the square root of 4 correct answer?

The square root of 4 is simply just 2 or in other words, 4 = 2. It is one of those numbers which we can call a perfect square number.

Is 2 a square root of 4 True or false?

Since the number of iterations is 2, therefore the square root of 4 is 2.


1 Answers

Because:

  • In mathematics, √x commonly, unless otherwise specified, refers to the principal (i.e. positive) root of x [http://mathworld.wolfram.com/SquareRoot.html].
  • Some languages don't have the ability to return more than one value.
  • Since you can just apply negation, returning both would be redundant.
like image 74
Nietzche-jou Avatar answered Sep 21 '22 19:09

Nietzche-jou