Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pow() function working without any math libraries

It seems on some software/compilers the pow() function works without any math libraries at all. Only with <iostream>. But in others it complains. Have math functions been added to the <iostream> library or to some other place?

like image 237
YelizavetaYR Avatar asked Apr 12 '16 14:04

YelizavetaYR


People also ask

What can I use instead of math POW?

Introduced in ES2016, the infix exponentiation operator ** is an alternative for the standard Math. pow function. Infix notation is considered to be more readable and thus more preferable than the function notation.

Which library has pow () function?

C library function - pow() The C library function double pow(double x, double y) returns x raised to the power of y i.e. xy.

Is POW a math function?

The pow() function computes the power of a number. The pow() function is defined in math.

Why do you need to #include math h when using the pow () function?

Given two numbers base and exponent, pow() function finds x raised to the power of y i.e. xy. Basically in C exponent value is calculated using the pow() function. pow() is function to get the power of a number, but we have to use #include<math.h> in c/c++ to use that pow() function. then two numbers are passed.


1 Answers

Headers can - and often do - include other headers. Standard library headers are no exception to this.

Even though you chose not to include a header (let's name it a) that you depended on, it's possible that the header happened to be included by another header (let's name it b) that you did include. In that case, your program is not guaranteed to continue working if the b header is ever modified to not include a. That is why you must always include all headers that you depend on - even when your program appears to work without including some of them.

All different versions of different implementations of standard library are different and therefore a in one version could include b while a in another version could just as well not include b. Same applies to all API that have multiple versions of implementations.

like image 160
eerorika Avatar answered Oct 23 '22 03:10

eerorika