Example #1
0
// Close a control connection by sending QUIT command.
int muroar_quit   (muroar_t fh) {
 char quit[] = "\0\6\0\0\0\0\0\0\0\0"; // QUIT command
 int ret = 0;

 if ( fh == MUROAR_HANDLE_INVALID ) {
  _SET_ERRNO(EBADF);
  return -1;
 }

 if ( muroar_write(fh, quit, 10) != 10 )
  ret = -1;

 // read in case the server response
 // ignore errors as the server do not necessary
 // response to our request.
 muroar_read(fh, quit, 10);

 if ( muroar_close(fh) == -1 )
  ret = -1;

 return ret;
}
Example #2
0
long double __tgammal_r(long double x, int* sgngaml)
{
	long double p, q, z;
	int i;

	*sgngaml = 1;
#ifdef NANS
	if (isnanl(x))
		return (NANL);
#endif
#ifdef INFINITIES
#ifdef NANS
	if (x == INFINITYL)
		return (x);
	if (x == -INFINITYL)
		return (NANL);
#else
	if (!isfinite(x))
		return (x);
#endif
#endif
	q = fabsl(x);

	if (q > 13.0L)
	{
		if (q > MAXGAML)
			goto goverf;
		if (x < 0.0L)
		{
			p = floorl(q);
			if (p == q)
			{
gsing:
				_SET_ERRNO(EDOM);
				mtherr("tgammal", SING);
#ifdef INFINITIES
				return (INFINITYL);
#else
				return (*sgngaml * MAXNUML);
#endif
			}
			i = p;
			if ((i & 1) == 0)
				*sgngaml = -1;
			z = q - p;
			if (z > 0.5L)
			{
				p += 1.0L;
				z = q - p;
			}
			z = q * sinl(PIL * z);
			z = fabsl(z) * stirf(q);
			if (z <= PIL/MAXNUML)
			{
goverf:
				_SET_ERRNO(ERANGE);
				mtherr("tgammal", OVERFLOW);
#ifdef INFINITIES
				return(*sgngaml * INFINITYL);
#else
				return(*sgngaml * MAXNUML);
#endif
			}
			z = PIL/z;
		}
		else
		{
			z = stirf(x);
		}
		return (*sgngaml * z);
	}

	z = 1.0L;
	while (x >= 3.0L)
	{
		x -= 1.0L;
		z *= x;
	}

	while (x < -0.03125L)
	{
		z /= x;
		x += 1.0L;
	}

	if (x <= 0.03125L)
		goto Small;

	while (x < 2.0L)
	{
		z /= x;
		x += 1.0L;
	}

	if (x == 2.0L)
		return (z);

	x -= 2.0L;
	p = polevll( x, P, 7 );
	q = polevll( x, Q, 8 );
	return (z * p / q);

Small:
	if (x == 0.0L)
	{
		goto gsing;
	}
	else
	{
		if (x < 0.0L)
		{
			x = -x;
			q = z / (x * polevll(x, SN, 8));
		}
		else
			q = z / (x * polevll(x, S, 8));
	}
	return q;
}
Example #3
0
float __tgammaf_r( float x, int* sgngamf)
{
float p, q, z, nz;
int i, direction, negative;

#ifdef NANS
if( isnan(x) )
	return(x);
#endif
#ifdef INFINITIES
#ifdef NANS
if( x == INFINITYF )
	return(x);
if( x == -INFINITYF )
	return(NANF);
#else
if( !isfinite(x) )
	return(x);
#endif
#endif

*sgngamf = 1;
negative = 0;
nz = 0.0;
if( x < 0.0 )
	{
	negative = 1;
	q = -x;
	p = floorf(q);
	if( p == q )
		{
gsing:
		_SET_ERRNO(EDOM);
		mtherr( "tgammaf", SING );
#ifdef INFINITIES
		return (INFINITYF);
#else
		return (MAXNUMF);
#endif
			}
	i = p;
	if( (i & 1) == 0 )
		*sgngamf = -1;
	nz = q - p;
	if( nz > 0.5 )
		{
		p += 1.0;
		nz = q - p;
		}
	nz = q * sinf( PIF * nz );
	if( nz == 0.0 )
		{
		_SET_ERRNO(ERANGE);
		mtherr( "tgamma", OVERFLOW );
#ifdef INFINITIES
		return( *sgngamf * INFINITYF);
#else
		return( *sgngamf * MAXNUMF);
#endif
		}
	if( nz < 0 )
		nz = -nz;
	x = q;
	}
if( x >= 10.0 )
	{
	z = stirf(x);
	}
if( x < 2.0 )
	direction = 1;
else
	direction = 0;
z = 1.0;
while( x >= 3.0 )
	{
	x -= 1.0;
	z *= x;
	}
/*
while( x < 0.0 )
	{
	if( x > -1.E-4 )
		goto Small;
	z *=x;
	x += 1.0;
	}
*/
while( x < 2.0 )
	{
	if( x < 1.e-4 )
		goto Small;
	z *=x;
	x += 1.0;
	}

if( direction )
	z = 1.0/z;

if( x == 2.0 )
	return(z);

x -= 2.0;
p = z * polevlf( x, P, 7 );

gdone:

if( negative )
	{
	p = *sgngamf * PIF/(nz * p );
	}
return(p);

Small:
if( x == 0.0 )
	{
	goto gsing;
	}
else
	{
	p = z / ((1.0 + 0.5772156649015329 * x) * x);
	goto gdone;
	}
}
Example #4
0
// Open Control connection
muroar_t muroar_connect(const char * server, const char * name) {
 char   useraddr[80] = MUROAR_INVALID;
 char * addr[] = {useraddr, MUROAR_GSOCK, MUROAR_HOST, "::" MUROAR_OBJECT, MUROAR_ABSTRACT, NULL};
 const char * home;
 unsigned char buf[MUROAR_IOBUF];
 uint16_t tmpu16;
 uint16_t pid;
 muroar_t fh = MUROAR_HANDLE_INVALID;
 int i;
#if !defined(__WIN32)
 ssize_t len;
#endif

 // Prepare server address:
 if ( server != NULL && *server == 0 )
  server = NULL;

 if ( server == NULL )
  server = getenv("ROAR_SERVER");

#if !defined(__WIN32)
 if ( server == NULL ) {
  if ( (len = readlink("/etc/roarserver", useraddr, sizeof(useraddr))) != -1 ) {
   useraddr[len < (ssize_t)sizeof(useraddr) ? (size_t)len : sizeof(useraddr)-1] = 0;
   server = useraddr;
  }
 }
#endif

 if ( server != NULL ) {
  // "+default" is an alias to NULL.
  if ( !strcmp(server, MUROAR_DEFAULT) ) {
   server = NULL;

  // "+invalid" always return an invalid handle.
  } else if ( !strcmp(server, MUROAR_INVALID) ) {
#ifdef ECANCELED
   _SET_ERRNO(ECANCELED);
#else
   _SET_ERRNO(EINVAL);
#endif
   return MUROAR_HANDLE_INVALID;
  }
 }

 // Connect to server:
 if ( server != NULL ) {
  if ( (fh = muroar_open_socket(server)) == MUROAR_HANDLE_INVALID )
   return MUROAR_HANDLE_INVALID;
 } else {
  // build string for ~/.roar
  home = getenv("HOME");
  if ( home != NULL && home[0] == '/' && strlen(home) < (sizeof(useraddr) - 7) ) {
   snprintf(useraddr, sizeof(useraddr), "%s/.roar", home);
   useraddr[sizeof(useraddr)-1] = 0;
  }

  // go thru list of possible defaults:
  for (i = 0; fh == MUROAR_HANDLE_INVALID && addr[i] != NULL; i++) {
   if ( !strcmp(addr[i], MUROAR_INVALID) )
    continue;

   fh = muroar_open_socket(addr[i]);
  }

  if ( fh == MUROAR_HANDLE_INVALID ) {
   _SET_ERRNO(ENOENT);
   return MUROAR_HANDLE_INVALID;
  }
 }

 // Prepare client name:
 if ( name == NULL || *name == 0 )
  name = _DEFAULT_CLIENT_NAME;

 // Send IDENTIFY command to server:
 memset(buf, 0, sizeof(buf));
 buf[1] = MUROAR_CMD_IDENTIFY;

 // Calculate the length for the data part of the package.
 // Its 5 bytes plus the length of the name string.
 tmpu16 = strlen(name) + 5;

 // check if we have space for 5 bytes + length of name + tailing \0
 // in the buffer.
 if ( tmpu16 >= MUROAR_IOBUF ) {
  _CLOSE(fh);
  _SET_ERRNO(EINVAL);
  return MUROAR_HANDLE_INVALID;
 }

 buf[8] = (tmpu16 & 0xFF00) >> 8;
 buf[9] = (tmpu16 & 0x00FF);

 if ( muroar_write(fh, buf, 10) != 10 ) {
  _CLOSE(fh);
  return MUROAR_HANDLE_INVALID;
 }

 buf[0] = 1;
 pid = getpid();
 buf[1] = (pid & 0xFF000000UL) >> 24;
 buf[2] = (pid & 0x00FF0000UL) >> 16;
 buf[3] = (pid & 0x0000FF00UL) >>  8;
 buf[4] = (pid & 0x000000FFUL) >>  0;

 // sizes are already checked.
 strcpy((char*)&(buf[5]), name);

 if ( muroar_write(fh, buf, tmpu16) != tmpu16 ) {
  _CLOSE(fh);
  return MUROAR_HANDLE_INVALID;
 }

 if ( muroar_read(fh, buf, 10) != 10 ) {
  _CLOSE(fh);
  return MUROAR_HANDLE_INVALID;
 }

 if ( buf[1] != MUROAR_CMD_OK ) {
  _CLOSE(fh);
  _SET_ERRNO(EACCES);
  return MUROAR_HANDLE_INVALID;
 }

 // Send AUTH command to server:
 // We send zero-byte AUTH command
 // (type=NONE).
 memset(buf, 0, 10);
 buf[1] = MUROAR_CMD_AUTH;

 if ( muroar_write(fh, buf, 10) != 10 ) {
  _CLOSE(fh);
  return MUROAR_HANDLE_INVALID;
 }

 if ( muroar_read(fh, buf, 10) != 10 ) {
  _CLOSE(fh);
  return MUROAR_HANDLE_INVALID;
 }

 if ( buf[1] != MUROAR_CMD_OK ) {
  _CLOSE(fh);
  _SET_ERRNO(EACCES);
  return MUROAR_HANDLE_INVALID;
 }

 // We now have a working control connection, return it.
 return fh;
}
Example #5
0
float __lgammaf_r( float x, int* sgngamf )
{
float p, q, w, z;
float nx, tx;
int i, direction;

*sgngamf = 1;
#ifdef NANS
if( isnan(x) )
	return(x);
#endif

#ifdef INFINITIES
if( !isfinite(x) )
	return(x);
#endif


if( x < 0.0 )
	{
	q = -x;
	w = __lgammaf_r(q, sgngamf); /* note this modifies sgngam! */
	p = floorf(q);
	if( p == q )
		{
lgsing:
		_SET_ERRNO(EDOM);
		mtherr( "lgamf", SING );
#ifdef INFINITIES
		return (INFINITYF);
#else
	return( *sgngamf * MAXNUMF );
#endif
		}
	i = p;
	if( (i & 1) == 0 )
		*sgngamf = -1;
	else
		*sgngamf = 1;
	z = q - p;
	if( z > 0.5 )
		{
		p += 1.0;
		z = p - q;
		}
	z = q * sinf( PIF * z );
	if( z == 0.0 )
		goto lgsing;
	z = -logf( PIINV*z ) - w;
	return( z );
	}

if( x < 6.5 )
	{
	direction = 0;
	z = 1.0;
	tx = x;
	nx = 0.0;
	if( x >= 1.5 )
		{
		while( tx > 2.5 )
			{
			nx -= 1.0;
			tx = x + nx;
			z *=tx;
			}
		x += nx - 2.0;
iv1r5:
		p = x * polevlf( x, B, 7 );
		goto cont;
		}
	if( x >= 1.25 )
		{
		z *= x;
		x -= 1.0; /* x + 1 - 2 */
		direction = 1;
		goto iv1r5;
		}
	if( x >= 0.75 )
		{
		x -= 1.0;
		p = x * polevlf( x, C, 7 );
		q = 0.0;
		goto contz;
		}
	while( tx < 1.5 )
		{
		if( tx == 0.0 )
			goto lgsing;
		z *=tx;
		nx += 1.0;
		tx = x + nx;
		}
	direction = 1;
	x += nx - 2.0;
	p = x * polevlf( x, B, 7 );

cont:
	if( z < 0.0 )
		{
		*sgngamf = -1;
		z = -z;
		}
	else
		{
		*sgngamf = 1;
		}
	q = logf(z);
	if( direction )
		q = -q;
contz:
	return( p + q );
	}

if( x > MAXLGM )
	{
	_SET_ERRNO(ERANGE);
	mtherr( "lgamf", OVERFLOW );
#ifdef INFINITIES
	return( *sgngamf * INFINITYF );
#else
	return( *sgngamf * MAXNUMF );
#endif

	}

/* Note, though an asymptotic formula could be used for x >= 3,
 * there is cancellation error in the following if x < 6.5.  */
q = LS2PI - x;
q += ( x - 0.5 ) * logf(x);

if( x <= 1.0e4 )
	{
	z = 1.0/x;
	p = z * z;
	q += ((    6.789774945028216E-004 * p
		 - 2.769887652139868E-003 ) * p
		+  8.333316229807355E-002 ) * z;
	}
return( q );
}
Example #6
0
double __tgamma_r(double x, int *sgngam)
{
    double p, q, z;
    int i;

    *sgngam = 1;
#ifdef NANS
    if (isnan(x))
        return (x);
#endif
#ifdef INFINITIES
#ifdef NANS
    if (x == INFINITY)
        return (x);
    if (x == -INFINITY)
        return (NAN);
#else
    if (!isfinite(x))
        return (x);
#endif
#endif
    q = fabs(x);

    if (q > 33.0)
    {
        if (x < 0.0)
        {
            p = floor(q);
            if (p == q)
            {
gsing:
                _SET_ERRNO(EDOM);
                mtherr("tgamma", SING);
#ifdef INFINITIES
                return (INFINITY);
#else
                return (MAXNUM);
#endif
            }
            i = p;
            if ((i & 1) == 0)
                *sgngam = -1;
            z = q - p;
            if (z > 0.5)
            {
                p += 1.0;
                z = q - p;
            }
            z = q * sin(PI * z);
            if (z == 0.0)
            {
                _SET_ERRNO(ERANGE);
                mtherr("tgamma", OVERFLOW);
#ifdef INFINITIES
                return (*sgngam * INFINITY);
#else
                return (*sgngam * MAXNUM);
#endif
            }
            z = fabs(z);
            z = PI/(z * stirf(q));
        }
        else
        {
            z = stirf(x);
        }
        return (*sgngam * z);
    }

    z = 1.0;
    while (x >= 3.0)
    {
        x -= 1.0;
        z *= x;
    }

    while (x < 0.0)
    {
        if (x > -1.E-9)
            goto Small;
        z /= x;
        x += 1.0;
    }

    while (x < 2.0)
    {
        if (x < 1.e-9)
            goto Small;
        z /= x;
        x += 1.0;
    }

    if (x == 2.0)
        return (z);

    x -= 2.0;
    p = polevl( x, P, 6 );
    q = polevl( x, Q, 7 );
    return (z * p / q);

Small:
    if (x == 0.0)
    {
        goto gsing;
    }
    else
        return (z/((1.0 + 0.5772156649015329 * x) * x));
}
int muroar_setvolume   (muroar_t fh, int stream, long unsigned int left, long unsigned int right) {
 unsigned char buf[20];
 unsigned char ans[10];
 int channels;
 int mode;
 size_t len;

 if ( fh == MUROAR_HANDLE_INVALID ) {
  _SET_ERRNO(EBADF);
  return -1;
 }

 if ( stream < 0 ) {
  _SET_ERRNO(EINVAL);
  return -1;
 }

 memset(buf, 0, sizeof(buf));

 // header:
 buf[1] = MUROAR_CMD_SET_VOL;
 buf[2] = (stream & 0xFF00) >> 8;
 buf[3] = (stream & 0x00FF);

 // body:
 buf[10] = 0;    // Version MSB
 buf[11] = 1;    // Version LSB
 buf[12] = 0xFF; // scale MSB
 buf[13] = 0xFF; // scale LSB
 buf[14] = 0;    // mode MSB

 for (channels = 2; channels > 0; channels--) {
  len = 10 + 6 + 2*channels; // total request length.
  buf[9] = len - 10; // body length LSB, the 10 is thhe header length

  for (mode = 4; mode > 0; mode -= 3) {
   buf[15] = mode; // mode LSB
   buf[16] = (left  & 0xFF00) >> 8; // channel 0 MSB
   buf[17] = (left  & 0x00FF);      // channel 0 LSB
   buf[18] = (right & 0xFF00) >> 8; // channel 1 MSB
   buf[19] = (right & 0x00FF);      // channel 1 LSB

   // send request:
   if ( muroar_write(fh, buf, len) != (ssize_t)len ) {
    return -1;
   }

   if ( muroar_read(fh, ans, 10) != 10 ) {
    return -1;
   }

   if ( ans[1] == MUROAR_CMD_OK )
    return 0;
  }

  left = left/2 + right/2;
 }

#ifdef ENOTSUP
 _SET_ERRNO(ENOTSUP);
#else
 _SET_ERRNO(ENOSYS);
#endif
 return -1;
}