Math.pow (0.0, 0.0) returns 1; should be undefined or error?

Math.pow(0.0, 0.0) in Java returns 1, which is incorrect. 0 ^ 0 - undefined. The same problem exists in the windows calculator (I use Win7). Why is this?

Mathematica declares it as an error, as well as my scientific calculator Casio, why not java or the Win calculator ... Is this an error?

+4
source share
5 answers

0 ^ 0 = 1 is considered a reasonable definition in many contexts. For a list of arguments for and against it, see http://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_power_of_zero

+8
source

Because this is exactly what Javadocs says:

public static double pow (double a, double b)

Returns the value of the first argument raised to the power of the second argument. Special Occasions:
* If the second argument is positive or negative, then the result is 1.0.

+5
source

This is mistake?

No, the error is a violation of the specification. The specification states:

Returns the value of the first argument raised to the power of the second argument. Special cases:

  • If the second argument is positive or negative, then the result is 1.0.

Finally, mathematically, some of them define 0^0 as 1 . In fact, Knuth says it should be 1 .

The number of mappings from an empty set to an empty set is 0^0 . It should be 1 .

His reasoning is this. If you have two sets, A and B , the number of functions from A to B is |B|^|A| . How many functions exist from an empty set to an empty set? Well, there is exactly one thing. By this logic, 0^0 should be 1 .

+5
source

Java defines it this way. That is all you really can say.

However, mathematically this number is undefined. One way to understand why to write

x = 0 ^ 0

where I used ^ to represent exponentiation. Taking the logarithms

log x = 0 log 0

I did this because every mathematician admits that log 0 is undefined, and therefore it follows that log x and therefore x are also undefined. (Mathematically, this is called a singularity, and the mathematician will tell you that this is one of the worst features you may encounter).

+2
source

An exact definition of the function's behavior is given in http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#pow(double,%20double)

You will see here that

 public static double pow(double a, double b) Returns the value of the first argument raised to the power of the second argument. Special cases: If the second argument is positive or negative zero, then the result is 1.0. 

Not a mistake - this is by design.

+1
source

Source: https://habr.com/ru/post/1487645/


All Articles