I use the math.h library and in it to find the cubic root there is a function cbrt(); Only here when compiling Visual Studio says: error C3861: cbrt: ID not found.

My code is:

 #include <stdio.h> #include <cmath> int main() { double PI = 3.1415926535897932384626433832795, x=0.25, y=1.31, a=3.5, b=0.9, P; printf("Вы запустили программу для решения задачи 1 из лабораторной 1! \n"); printf("Программа начинает расчет, ожидайте... \n"); P=fabs((pow(sin(a*pow(x,3)+b*pow(y,2)-a*b),3))/(cbrt(pow((a*x*3+b*pow(y,2)-a),2)+PI)))+tan(a*pow(x,3)+b*pow(y,2)-a*b); printf("Ответ для Задачи 1: %d \n", P); return 0; } 

How to solve the problem?

    2 answers 2

    That's right, he stumbled. Because this function is in another header file - amp_math.h ( proof ).

    • But in ubuntu everything works (but c `#include <math.h>), and gcc and g ++. gcc version 4.6.3 (Ubuntu / Linaro 4.6.3-1ubuntu5) Even it turns out to connect libm (here I was surprised!) it is not necessary. - avp
    • This is all very nice, of course, but the developers do not have the honor - remember that you need to connect amp_math.h and not math.h, do not forget about the namespace Concurrency :: precise_math, plus the function itself is declared with __GPU_ONLY, it’s the same restrict (amp) I don’t know if the standard requires declaring functions in specific header files, but this confusion itself is somewhat surprising. - DreamChild
    • >> Well, to blame vc ++ for the good support of this standard is still quite difficult, and according to the standard they should be in cmath (standard 26.8.9). Microsoft has always interpreted the standard as they needed. - KoVadim
    • After all, I still took exactly the program TC and g ++. Everything compiles, except for an error in printf () ... (there% d must be replaced with% f). - @MDev, drop the works of B. Gates! - avp

    I don’t know what the lack of this function is connected with, but try this:

     #define cbrt(x) pow((x), 1.0/3) 

    In general, cbrt is in C99 and in C ++ TR1, which seems to have just entered C ++ 11. Well, it’s still rather difficult to blame vc ++ for good support of this standard.

    • the absence is probably due to the fact that this function is from c ++ 11. - KoVadim
    • I do not know how the studio, but gcc if you do not explicitly ask for it, then it will not use the new standard. Perhaps the studio too. - KoVadim
    • I do not think. In any case, my vc ++ has now devoured this without any problems: auto fn = [] () {return 4; }; cout << fn () << endl; but about cbrt stumbled - DreamChild