0

I just encountered a strange thing. While testing math.h I tried to use pow() and compile it. I did not have to link math.h . But when I try the same with something like fmod() I have to link math.h while compiling the programm. Why do I have to link the library in the second case but not in the first?

Lofter
  • 5
  • 1
  • 4

1 Answers1

2

Your compiler may be replacing some usages of pow with a constant. For example, it could replace pow(2.0, 3.0) with 8.0. This is a good optimisation and means you no longer need the pow in math.h.

But your compiler probably can't replace fmod, or all usages of math functions, so it still needs to link to the math library.

congusbongus
  • 13,359
  • 7
  • 71
  • 99