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

Solaris 10 isinf (libm) problem

306 views
Skip to first unread message

Bruno Bonfils

unread,
Jul 29, 2005, 5:25:57 AM7/29/05
to

Hello,

I'm trying to build a software which use the function isinf (from
libm), I think you can guess my problem, this function doesn't exist
in libm, as it should.

first strange thing :

extract from man isinf :

SYNOPSIS
#include <math.h>

int isinf(real-floating x);

% grep isinf /usr/include/math.h
zsh: exit 1 grep isinf /usr/include/math.h
% gnm /usr/lib/libm.so | grep isinf
000828c0 t isinfl
000828c0 t __isinfl

I look for some workarounds, the only one i found is to overwrite the
functin isinf as a wrapper to infinite. Though, I don't like this
workaround, especially for code of other people.

- First, why this error/problem still exist in Solaris 10 ? My search
in google saw me that this 'error' is very old

- Is there another workaround which doesn't require to modify the code
?

Thanks to you


--
\_o<

Thomas Maier-Komor

unread,
Jul 29, 2005, 6:29:09 AM7/29/05
to

the manpage also says that beside libm.so you have to link
agains libsunmath.so. And there you will find isinf...

Tom

PM

unread,
Jul 29, 2005, 6:29:59 AM7/29/05
to
Bruno Bonfils wrote:
> Hello,
>
> I'm trying to build a software which use the function isinf (from
> libm), I think you can guess my problem, this function doesn't exist
> in libm, as it should.
>
> first strange thing :
>
> extract from man isinf :
>
> SYNOPSIS
> #include <math.h>
>
> int isinf(real-floating x);
>
> % grep isinf /usr/include/math.h
> zsh: exit 1 grep isinf /usr/include/math.h

% grep ^#include /usr/include/math.h
#include <iso/math_iso.h>
#include <iso/math_c99.h>
#include <floatingpoint.h>

% grep isinf /usr/include/iso/math*
/usr/include/iso/math_c99.h:#undef isinf
/usr/include/iso/math_c99.h:#define isinf(x) __builtin_isinf(x)

PM

Casper H.S. Dik

unread,
Jul 29, 2005, 7:50:42 AM7/29/05
to
Bruno Bonfils <asyd...@asyd.net> writes:

>I'm trying to build a software which use the function isinf (from
>libm), I think you can guess my problem, this function doesn't exist
>in libm, as it should.

No it shouldn't. It should be defined when including <math.h>

>first strange thing :

>extract from man isinf :

>SYNOPSIS
> #include <math.h>

> int isinf(real-floating x);

>% grep isinf /usr/include/math.h
>zsh: exit 1 grep isinf /usr/include/math.h
>% gnm /usr/lib/libm.so | grep isinf
>000828c0 t isinfl
>000828c0 t __isinfl

It's defined in iso/math_c99.h as:

#define isinf(x) __builtin_isinf(x)

But you're probably using gcc and it's only in Solaris 11 that
gcc support is better and uses:

#if defined(__GNUC__)
#define isinf(x) __extension__( \
{ __typeof(x) __x_i = (x); \
__x_i == (__typeof(__x_i)) INFINITY || \
__x_i == (__typeof(__x_i)) (-INFINITY); })
#else
#define isinf(x) __builtin_isinf(x)
#endif

Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

Bruno Bonfils

unread,
Jul 29, 2005, 7:23:53 AM7/29/05
to
PM <p...@gmx.de> writes:

>
> % grep ^#include /usr/include/math.h
> #include <iso/math_iso.h>
> #include <iso/math_c99.h>
> #include <floatingpoint.h>
>
> % grep isinf /usr/include/iso/math*
> /usr/include/iso/math_c99.h:#undef isinf
> /usr/include/iso/math_c99.h:#define isinf(x) __builtin_isinf(x)

So, why :

% cat isinf.c
#include <stdio.h>
#include <math.h>

int main (void)
{
float myfloat = 0.000;
return isinf(myfloat);
}

% gcc -Wall isinf.c -o isinf -lm
isinf.c: In function `main':
isinf.c:7: warning: implicit declaration of function `isinf'
Undefined first referenced
symbol in file
isinf /var/tmp//cc0mv2QJ.o
ld: fatal: Symbol referencing errors. No output written to isinf


and for Thomas :

% gcc -Wall isinf.c -o isinf -lm -lsunmath
isinf.c: In function `main':
isinf.c:7: warning: implicit declaration of function `isinf'
ld: fatal: library -lsunmath: not found
ld: fatal: File processing errors. No output written to isinf
collect2: ld returned 1 exit status
zsh: exit 1 gcc -Wall isinf.c -o isinf -lm -lsunmath


--
\_o<

Thomas Maier-Komor

unread,
Jul 29, 2005, 8:44:38 AM7/29/05
to

libsunmath is part of Sun Studio 10. you can get it free
of charge if you are a participant of the OpenSolaris
program - AFAIK...
Do yourself a favor in try it - it has many advantages
compared to gcc.

Tom

Seongbae Park

unread,
Jul 29, 2005, 12:11:56 PM7/29/05
to
Bruno Bonfils <asyd...@asyd.net> wrote:
> PM <p...@gmx.de> writes:
>
>>
>> % grep ^#include /usr/include/math.h
>> #include <iso/math_iso.h>
>> #include <iso/math_c99.h>
>> #include <floatingpoint.h>
>>
>> % grep isinf /usr/include/iso/math*
>> /usr/include/iso/math_c99.h:#undef isinf
>> /usr/include/iso/math_c99.h:#define isinf(x) __builtin_isinf(x)
>
> So, why :
>
> % cat isinf.c
> #include <stdio.h>
> #include <math.h>
>
> int main (void)
> {
> float myfloat = 0.000;
> return isinf(myfloat);
> }
>
> % gcc -Wall isinf.c -o isinf -lm
> isinf.c: In function `main':
> isinf.c:7: warning: implicit declaration of function `isinf'
> Undefined first referenced
> symbol in file
> isinf /var/tmp//cc0mv2QJ.o
> ld: fatal: Symbol referencing errors. No output written to isinf

A real answer:

Because C99's isinf() can not be implemented in the library.
C99 defines isinf() to be able to cope with ANY floating-point type.
And obviously C doesn't allow that in an actual function.
So this has to be implemented by a macro that
is specific to a particular implementation of the C99 compiler.
In Sun Studio, isinf() becomes a compiler builtin function called
__builtin_isinf() and the compiler takes care of that.

# uname -a
SunOS park2 5.10 Generic_118822-02 sun4u sparc SUNW,Sun-Blade-1000
# cat isinf.c
#include <math.h>

int func(double a)
{
return isinf(a);
}
# cc -V isinf.c -c -xO3 -S
cc: Sun C 5.7 2005/01/07
acomp: Sun C 5.7 2005/01/07
iropt: Sun Compiler Common 10 2005/01/07
cg: Sun Compiler Common 10 2005/01/07
# cat isinf.s
...
.global func
func:
/* 000000 5 */ sethi %hi(0x80000000),%o5
/* 0x0004 */ sethi %hi(0x7ff00000),%o4
/* 0x0008 */ andn %o0,%o5,%o3
/* 0x000c 4 */ add %sp,-104,%sp
/* 0x0010 5 */ xor %o3,%o4,%o2
/* 0x0014 */ st %o1,[%sp+92]
/* 0x0018 */ srl %o2,0,%g5
/* 0x001c */ st %o0,[%sp+96]
/* 0x0020 */ srl %o1,0,%o1
/* 0x0024 */ sub %g0,%g5,%g4
/* 0x0028 */ sub %g0,%o1,%g1
/* 0x002c */ srlx %g4,63,%g3
/* 0x0030 */ srlx %g1,63,%o5
/* 0x0034 */ xor %g3,1,%g2
/* 0x0038 */ xor %o5,1,%o0
/* 0x003c */ and %g2,%o0,%o0
/* 0x0040 */ retl ! Result = %o0
/* 0x0044 */ add %sp,104,%sp
/* 0x0048 0 */ .type func,2
/* 0x0048 0 */ .size func,(.-func)
...


As you see from above, there's no call.

A background on what's going on above:

isinf() macro is defined within the #if of:

#if defined(_STDC_C99) || _XOPEN_SOURCE - 0 >= 600 || defined(__C99FEATURES__)

and gcc 3.x obviously doesn't seem to define any of those macros
(and it shouldn't unless it can cope with all those macros
under that condition).

As Casper pointed out, there's a new math.h coming
that would work with gcc.

> and for Thomas :
>
> % gcc -Wall isinf.c -o isinf -lm -lsunmath
> isinf.c: In function `main':
> isinf.c:7: warning: implicit declaration of function `isinf'
> ld: fatal: library -lsunmath: not found
> ld: fatal: File processing errors. No output written to isinf
> collect2: ld returned 1 exit status
> zsh: exit 1 gcc -Wall isinf.c -o isinf -lm -lsunmath

libsunmath.a is included in the Sun compiler.
However, isinf() in libsunmath is different than C99's isinf().
It's "int isinf(double)" and is a real library routine.
--
#pragma ident "Seongbae Park, compiler, http://blogs.sun.com/seongbae/"

0 new messages