Re: Undefined reference to 'fmod'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/11/06, James Colannino <james@xxxxxxxxxxxxx> wrote:
Glynn Clements wrote:

> No, fmod() is in libm, so you have to add -lm to the link command.
>
> As a general rule, anything which uses <math.h> has to link against
> libm.

Interesting.  Compiling with the argument -lm fixed my problem.  That
leads me to another question: why are the functions found in math.h in a
separate library?  I would have thought that all functions found in the
standard C library would be in glibc (The K&R book I'm reading said that
math.h is a part of the standard library.)

The functions in libm allow to create portable programs with
well-defined and standard-compliant behavior, e.g. when numerical
errors occur, and provide the application with a means to control
their behavior in abnormal cases via the matherr callback.
Additionally, they almost never rely on the features specific to
processor architectures and are thus slower and sometimes slightly
less accurate than the functions from libc.

libc functions OTOH are written for speed and exploitation of
CPU-specific features; they do not call matherr, and are therefore
much faster and, due to the extended 80-bit precision with which the
Intel FPUs carry their calculations, sometimes more accurate.

	\Steve
-
: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux