c++ - sqrt() pow() fabs() do not work -
i trying compile program using functions sqrt pow , fabs. have math.h included reason errors like:
error c2668: 'fabs' : ambiguous call overloaded function same rest of functions have included:
#include "stdafx.h" #include "math.h" i tried including still same errors. know why not being recognized? file .cpp not .c mfc project.
thanks
it's because functions overloaded several types: float, double , long double. thus, if pass in integer, compiler doesn't 1 choose. easy fix pass double (or multiply pass in 1.0), should fix problem.
int value = rand(); int result1 = (int)fabs(value*1.0); printf("%d, %d\n", result1, result1); otherwise:
int value = rand(); int result1 = (int)fabs((double)value); printf("%d, %d\n", result1, result1);
Comments
Post a Comment