Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why return -1.#IND00 for pow(x, 1.0/3.0) when x is negative?

I try to pow(x, 1.0/3.0) and get -1.#IND00, why does it happens?

I tried to do pow(x, 1./3), pow(x, (1.0/3.0)), but nothing positive.

It doesn’t works only when x less than 0. And x is float.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Example:

   x = -3.12;
   y = pow(x, 1.0 / 3.0);
   printf("%f", y);

The code above prints y as -1.#IND00

>Solution :

The pow function doesn’t compute roots of negative numbers.

Section 7.12.7.4p1-2 of the C standard regarding the pow functions states:

1. double pow(double x, double y);

2. The pow functions compute x raised to the power y. A domain error occurs if x is finite and negative and y is finite and
not an integer value

So the values you’re giving constitute a domain error, which is described in section 7.12.1p2:

For all functions, a domain error occurs if an input argument is outside the domain over
which the mathematical function is defined. … On a
domain error, the function returns an implementation-defined value

If you want to compute the cube root of a number, you should instead use cbrt which accepts negative values.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading