## Newbie question: missing math.h functions?

### Newbie question: missing math.h functions?

--
Hello,
Somehow two functions, irint and nint, have dissapeared from our C
library here at work.  I've been given the wonderful task of rewriting them :-)

The first, nint(), seems pretty straightforward.
From the man page:
nint() converts x into int format rounding to the nearest int value,
except halfway cases are rounded to the int value larger in magnitude.

The second, irint,is giving me some trouble.
From the man page:
irint converts x to an integral value according to the current IEEE
rounding direction.

I looked around in some GNU source and found the following sample of
code.  It looked like something that I could change to fit my needs.

/*************************************************************************/
static __inline__ __const__ int __inline_irint (double x)
{
union { double d; unsigned long long ll; } u;
u.d = x;
#if _IEEE_FLOAT_
u.ll = (u.ll & 0x8000000000000000LL) | 0x3fe0000000000000LL;
#else
u.ll = (u.ll & 0x8000000000000000LL) | 0x4000000000000000LL;
#endif
return x + u.d;

Quote:}

/************************************************************************/

I modified this so that it would work on my machine.  sizeof double = 8 bytes,
sizeof unsigned long = 4 bytes.

int irint (double x)
{
union { double d; unsigned long l; } u;
u.d = x;
#if _IEEE_FLOAT_
u.l = (u.l & 0x8000L) | 0x3fe0L;
#else
u.l = (u.l & 0x8000L) | 0x4000L;
#endif
return (x + u.d);
}

One thing that bothered me is that double and unsigned long were different sizes
so I'v also tried changing the first two lines to:
union { float f; unsigned long l; } u;
u.f = (float) x;
I hadn't ever seen "unsigned long long" before. I assume it's machine
specific?

To figure out what is actually going on I've tried a couple of little test
programs composed of the function with some values inserted and the if/else
statements removed but nothing seems to work how I would expect.  I think I
understand the IEEE floating point definition :-) and I think I understand what's
going on in when value is written to u.*.
main(){
union { float f; unsigned long l; } u;
u.l = 0x3fe0L;  // binary- 0011 111 1110 000
cout << u.f << "\n";
cout << u.l << "\n";

Quote:}

I would expect to get:
1.5
16352
What I get is:
2.2914e-41
16352
If I do it the other way:
main(){
unioun {float f; unigned longl; } u;
u.f = 0x3fe0L;
cout << u.f << "\n";
cout << u.l << "\n";
Quote:}

I get:
16352                   <- This is the number I should get its binary is
0011 1111 1110 0000
1182760960

If anyone would be so kind as to point be in the right direction with
this problem I would really appreciate it.  If you happen to have access to the
sorce for these functions I would love to take a look, as I figure my summer job

-AHRAN

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Drexel University                Johns Hopkins University
Electrical Engineering             Applied Physics Laboratory

~~~~~~~~~~~~~~~~~~~~~~ oPInIOnS ArE mY OwN ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hi all,
I hope I am posting to the right group this
time. ( I have just been gently flamed for posting to
the wrong group )

I am trying to port the program DSTOOL from
BSD based SunOS to SysVr4 based Solris2.2, but I
am having problems with no-longer available c-library
routines :
nint & iszero - both SunOS 4.1.x only
Does anyone know the routines that can replace these
under Solaris 2.x ?

I successfully replaced getwd with getcwd , but this
is marked as alternate in Sun's dec. 1992 tech. bulletin.

The errors I recieve are as follows:
Undefined                       first referenced
symbol                             in file
iszero                              /nova1/dstool/src/computation/complib/complib.a(blas.o)
nint                                /nova1/dstool/src/computation/complib/complib.a(color_filter.o)
ld: fatal: Symbol referencing errors. No output written to /nova1/dstool/bin/dstool
*** Error code 1
make: Fatal error: Command failed for target `dstool'
Current working directory /nova1/dstool/src
*** Error code 1
make: Fatal error: Command failed for target `dstool'

Regards,

Colin Linahan