Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Turning on ALL C extensions.

1 view
Skip to first unread message

Samantha

unread,
Sep 4, 2008, 7:05:02 PM9/4/08
to
Hi - In order to use log2l() and log2f() in C, I apparently have to
include some C99 extension for math.h..Can anyone tell me what that
is? Also - how do I turn on ALL extensions? thanks!

jacob navia

unread,
Sep 4, 2008, 7:08:20 PM9/4/08
to

Yes. Your compiler looks like a gcc derivate or even
gcc itself...

To do that just call gcc with

gcc -std=c99 myfile.c -lm

(1) Note that c99 != C99, and C99 is not recognized.
(2) Note that you have to include manually the math library
(argument -lm since gcc isn't able to do that by itself)


--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32

Richard Heathfield

unread,
Sep 4, 2008, 7:43:13 PM9/4/08
to
Samantha said:

> Hi - In order to use log2l() and log2f() in C, I apparently have to
> include some C99 extension for math.h..

If you have a C99 implementation, you need only #include <math.h> and,
perhaps, follow any special procedures your implementation may require for
linking mathematical functions (most don't need anything of the kind,
thank heaven).

If you don't have a C99 implementation, despair not, since it's easy to
implement log2 functions yourself, at least for float and double:

double my_log2d(double x)
{
return log(x) / log(2.0);
}

float my_log2f(float x)
{
return my_log2d(x); /* :-) */
}

For long double, it's a bit harder because it wasn't until C99 (which is
still not widely implemented) that C gained a logl function, but here's a
nice simple way to do it using a Taylor series:

long double my_logl(long double x)
{
double result = 0;
int lim = 6;
int lc = 0;
int sign = +1;
double xp = --x;
while(lc++ < lim)
{
result += (sign * xp) / lc;
sign = sign * -1;
xp *= x;
}
return result;
} /* corrections welcomed */

long double my_log2l(long double x)
{
return my_logl(x) / my_logl(2.0);
}

> Also - how do I turn on ALL extensions?

That depends heavily on the implementation, since not all implementations
offer the same extensions or use the same switches and flags.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

Keith Thompson

unread,
Sep 4, 2008, 8:50:53 PM9/4/08
to

The log2l() and log2f() functions, declared in <math.h>, were added in
C99; they didn't exist in the C90 standard (though I think they were
mentioned in the future library directions section).

Almost all C compilers these days fully support the C90 standard.
Many of them partially support the C99 standard. Very few fully
support the C99 standard.

The way to enable C99 features in your compiler is a question about
your compiler, not about the C language. Your best bet is to consult
the documentation for your compiler.

(I happen to know that the "-std=c99" option does this for gcc; if
you're using gcc, you should read the documentation to see exactly
what this option does.)

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

user923005

unread,
Sep 5, 2008, 3:18:35 PM9/5/08
to
On Sep 4, 5:50 pm, Keith Thompson <ks...@mib.org> wrote:

> Samantha <samantha.domvi...@gmail.com> writes:
> > Hi - In order to use log2l() and log2f() in C, I apparently have to
> > include some C99 extension for math.h..Can anyone tell me what that
> > is? Also - how do I turn on ALL extensions? thanks!
>
> The log2l() and log2f() functions, declared in <math.h>, were added in
> C99; they didn't exist in the C90 standard (though I think they were
> mentioned in the future library directions section).
>
> Almost all C compilers these days fully support the C90 standard.
> Many of them partially support the C99 standard.  Very few fully
> support the C99 standard.
>
> The way to enable C99 features in your compiler is a question about
> your compiler, not about the C language.  Your best bet is to consult
> the documentation for your compiler.
>
> (I happen to know that the "-std=c99" option does this for gcc; if
> you're using gcc, you should read the documentation to see exactly
> what this option does.)

If you have a compiler that does not support these functions, there
are implementations in the Cephes collection.
http://www.moshier.net/#Cephes

0 new messages