Message-ID: <352DFE3F.36AE@pobox.oleane.com> Date: Fri, 10 Apr 1998 13:10:55 +0200 From: Francois Charton Organization: CCMSA MIME-Version: 1.0 To: Michael Phelps CC: djgpp AT delorie DOT com Subject: Re: Differences between -lm and not -lm References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk Michael Phelps wrote: > > I know that there are differences between compiling with -lm and > using the default math library, but I didn't know that it was that > significant. I wrote a little routine to extract a variable number of > digits from an int and return them. Observe: > >[example snipped] > > This is correct! I assume that it is the pow() function that differs > here. Should this be the correct behavior when it is not linked with the > math library? > When you do not link libm, the math functions in libc are linked by default. The pow() function in libc, although it is quite all right in most cases, is a little less elaborate than that of libm: when you give pow() an integer power, the libm pow knows that pow(x,4)=x*x*x*x, the libc pow() does it the hard way. This reduces the round off errors (to zero when both arguments are integers). This of course is not 100% efficient: libm pow() still doe snot know that pow(x,1.5)= sqrt(x*x*x), so you could still get errors when using pow() to get integer results. Anyway, you should avoid using pow() when you have an alternative solution (products, square roots...): it is always slower, and always less precise. Francois