Questions tagged [math.h]

For questions relating to functions declared by the math.h header file of C programming language.

Most of the mathematical functions are placed in math.h header (cmath header in C++).
math.h header file has following functions:

int abs (int x);                    
long labs (long x);

double fabs (double x);
double sin (double x);
double cos (double x);
double tan (double x);
double asin (double x);
double acos (double x);
double atan (double x);
double sinh (double x);
double cosh (double x);
double tanh (double x);

double exp (double x);              ex
double log (double x);              ln x
double log10 (double x);            log x

double pow (double x,double y);     xy
double sqrt(double x);              square root of x
double fmod(double x, double y);    x mod y

double ceil (double x);
double floor(double x);
310 questions
0
votes
2 answers

GCC error : undefined reference

I am trying to compile some C code on a beagleboard xm. I try to compile, but I get the error: undefined reference to 'isfinite' which is in the math.h library. This code compiles perfectly in all my other computers, and I do include -lm in my…
Ann
  • 693
  • 3
  • 12
  • 17
0
votes
1 answer

Dev C, math.h problems

I just installed devcpp, and am attempting to make sure it is working. When I ran into compile errors surrounding math.h. I am using a couple of simple programs that have been compiled and run before, so there shouldn't be any problems there. I…
user2207973
  • 1
  • 1
  • 3
0
votes
1 answer

Math functions undefined although present in the Borland C++ Builder 6 help under Math unit

I want to use the function Sign() in a Borland C++ Builder 6 application. I cannot however find the correct header file. When I use this function I get a compiler error saying undefined symbol, Sign. You would think this function would be in math.h…
Arnaud
  • 109
  • 3
  • 15
0
votes
1 answer

What to do if tgamma() function is not defined?

I am trying to use tgamma() from the standard library. When I try to compile, I get the error message: Call to undefined function tgamma I have the directive #include . I use Embarcadero C++ Builder XE3, which claims to support C++11…
0
votes
5 answers

Is there a way to speed up the evaluation of the following expression?

I have profiled my program and it spends 20% of the CPU time basically evaluating the following expression: abs(x) > abs(y) where x,y are double-precision floating point variables. Is there a way to refactor the expression to a faster variant? The…
Boyko Perfanov
  • 3,007
  • 18
  • 34
0
votes
2 answers

Compiler says pow is undefined even when I'm linking with -lm, but compiles when

value *= pow(10, 3); // this one compiles value *= pow(10, aVar); // this one produces this error: //Number.c:(.text+0x469): undefined reference to `pow' aVar is an int variable. What could it be? I'm using a makefile. I'm…
Lay González
  • 2,901
  • 21
  • 41
0
votes
2 answers

long type max equaling int max error + math.h pow() compile warning: overflow in implicit constant conversion

I'm using the math.h library, and when I run the code below I get g++ compile errors telling me "warning: overflow in implicit constant conversion" for multiple lines. However, if I run the executable anyway, it provides me reasonable numbers…
LazerSharks
  • 3,089
  • 4
  • 42
  • 67
0
votes
1 answer

modf() returns non-zero for negative infinity input

Tried on gcc and MSVC, both on Linux and Windows, remarkably the same result: modf(+INFINITY) returns exact zero (0x0000000000000000 in binary representation of resulting double, 0x00000000 for float) but modf(-INFINITY) returns 6.3e-322…
0
votes
2 answers

undefined reference to a c built in function 'pow'

Possible Duplicate: pow() isn’t defined void octal2decimal(char *octal, char *decimal) { int oct = atoi(octal); int dec = 0; int p = 0; while (oct!=0) { dec = dec + (oct%10) * pow(8,p++); //since oct is base 8 oct/=10; } *decimal =…
Nabmeister
  • 755
  • 1
  • 11
  • 20
0
votes
1 answer

precision of argument in pow() of C

Here's a C code; #include #include int main() { double n=10.0; double automatic = pow(10.0,log10(n)-log10(5.0)); printf("%.9lf\n",log10(n)-log10(5.0)); printf("%.9lf\n",pow(10.0,0.30102996)); double manual =…
Bharat Kul Ratan
  • 985
  • 2
  • 12
  • 24
0
votes
4 answers

math.h linkage with file

I have a small problem, and I have tried everything to test this function, could you please help me? I need to write a C file that is called "mutual_info.c", and it needs a mathematical function. I have included the library and linked it in the…
PL-RL
  • 427
  • 2
  • 7
  • 13
0
votes
1 answer

Undefined symbols for architecture x86_64 "_min"

I'm having a problem using min() and max() function in my C project. I've imported math.h, but when I compile the file I keep getting the following error (a similar error is displayed even using gcc instead of llvm): Undefined symbols for…
Luca Torella
  • 7,974
  • 4
  • 38
  • 48
0
votes
0 answers

Subclassing QDoubleSpinBox with NaN value

I subclassed QDoubleSpinBox in order to make a QDoubleSpinBox that allows the user to enter NaN as valid input. Right now if a user enters "nan" into the spinbox the control is automatically changing the text to the value of DBL_MAX instead of…
MBU
  • 4,998
  • 12
  • 59
  • 98
0
votes
2 answers

expected initializer before 'extern' when using math.h

The error points me to line 36 of the math.h file, which I haven't messed with. SRK.cpp is the only file that needs the header, but it won't be, so it seemed logical to include it in the header file. Clearly something is messed up (personally I…
tjtoml
  • 331
  • 2
  • 5
  • 13
0
votes
2 answers

Some questions about linking the math library

I am programming a c project which must use the pow function defined in math.h. And when I tried to make the project, gcc gave the following link error: undefined reference to `pow'. I know the -lm option must be added into my link instruction, but…
fumin
  • 33
  • 1
  • 1
  • 3