Ejemplo n.º 1
0
double
jn (int n, double x) 
{
  int i;
  
  if (n < 0)
    {
      n = -n;
      x = -x;
    }
  if (n == 0) 
    return j0(x);
  if (n == 1) 
    return j1(x);
  if (x == 0.0) 
    return 0.0;

  if (n <= x)
    {
      double a = j0(x), b = j1(x), tmp;

      for (i = 1; i < n; i++)
	{
	  tmp = b;
	  b = (2.0*i / x) * b - a;
	  a = tmp;
	}
      return b;
    }
  else	/* n > x */
    {
      double a, b, xsq, t, tmp;

      xsq = x*x;
      for (t=0, i=n+16; i > n; i--)
	t = xsq / (2.0*i - t);
      t = x / (2.0*n - t);
      a = t;
      b = 1.0;
      for (i = n - 1; i > 0; i--)
	{
	  tmp = b;
	  b = (2.0*i / x ) * b - a;
	  a = tmp;
	}
      return t*j0(x)/b;
    }
}
Ejemplo n.º 2
0
int main() {
    double x = 1.0;
    double y = 1.0;
    int i = 1;
    acosh(x);
    asinh(x);
    atanh(x);
    cbrt(x);
    expm1(x);
    erf(x);
    erfc(x);
    isnan(x);
    j0(x);
    j1(x);
    jn(i,x);
    ilogb(x);
    logb(x);
    log1p(x);
    rint(x);
    y0(x);
    y1(x);
    yn(i,x);
#   ifdef _THREAD_SAFE
    gamma_r(x,&i);
    lgamma_r(x,&i);
#   else
    gamma(x);
    lgamma(x);
#   endif
    hypot(x,y);
    nextafter(x,y);
    remainder(x,y);
    scalb(x,y);
    return 0;
}
Ejemplo n.º 3
0
Archivo: db.cpp Proyecto: zhuk/mongo
    void testTheDb() {
        stringstream ss;

        setClient("sys.unittest.pdfile");

        /* this is not validly formatted, if you query this namespace bad things will happen */
        theDataFileMgr.insert("sys.unittest.pdfile", (void *) "hello worldx", 13);
        theDataFileMgr.insert("sys.unittest.pdfile", (void *) "hello worldx", 13);

        BSONObj j1((const char *) &js1);
        deleteObjects("sys.unittest.delete", j1, false);
        theDataFileMgr.insert("sys.unittest.delete", &js1, sizeof(js1));
        deleteObjects("sys.unittest.delete", j1, false);
        updateObjects("sys.unittest.delete", j1, j1, true,ss);
        updateObjects("sys.unittest.delete", j1, j1, false,ss);

        auto_ptr<Cursor> c = theDataFileMgr.findAll("sys.unittest.pdfile");
        while ( c->ok() ) {
            c->_current();
            c->advance();
        }
        out() << endl;

        database = 0;
    }
Ejemplo n.º 4
0
int main(void)
{
	#pragma STDC FENV_ACCESS ON
	double y;
	float d;
	int e, i, err = 0;
	struct d_d *p;

	for (i = 0; i < sizeof t/sizeof *t; i++) {
		p = t + i;

		if (p->r < 0)
			continue;
		fesetround(p->r);
		feclearexcept(FE_ALL_EXCEPT);
		y = j1(p->x);
		e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);

		if (!checkexcept(e, p->e, p->r)) {
			printf("%s:%d: bad fp exception: %s j1(%a)=%a, want %s",
				p->file, p->line, rstr(p->r), p->x, p->y, estr(p->e));
			printf(" got %s\n", estr(e));
			err++;
		}
		d = ulperr(y, p->y, p->dy);
		if (!checkulp(d, p->r)) {
			printf("%s:%d: %s j1(%a) want %a got %a ulperr %.3f = %a + %a\n",
				p->file, p->line, rstr(p->r), p->x, p->y, y, d, d-p->dy, p->dy);
			err++;
		}
	}
	return !!err;
}
Ejemplo n.º 5
0
static double jinc(params *p, double x)
{
    if (fabs(x) < 1e-8)
        return 1.0;
    double pix = M_PI * x;
    return 2.0 * j1(pix) / pix;
}
Ejemplo n.º 6
0
RtFloat	RiBesselFilter( RtFloat x, RtFloat y, RtFloat xwidth, RtFloat ywidth )
{

	double d, w, xx, yy;

	xx = x * x;
	yy = y * y;

	xwidth *= 0.5;
	ywidth *= 0.5;

	w = ( xx ) / ( xwidth * xwidth ) + ( yy ) / ( ywidth * ywidth );
	if ( w < 1.0 )
	{
		d = sqrt( xx + yy );
		if ( d != 0.0 )
		{
			/* Half cosine window. */
			w = cos( 0.5 * RI_PI * sqrt( w ) );
			return w * 2*j1( RI_PI * d ) / d;
		}
		else
		{
			return RI_PI;
		}
	}
	else
	{
		return 0.0;
	}
}
Ejemplo n.º 7
0
int create_Result_file()
{

	int i, nbVal;
	double tabR[20000], Inc;
	char *F_name;
	int fp;

	F_name = "j1_out.ref2";
	nbVal = 20000;

	Inc = exp(1);

	for (i = 0; i < nbVal; i++)
		tabR[i] = j1(Inc * i);

	fp = open(F_name, O_RDWR | O_CREAT | O_TRUNC, 0777);
	if (!fp) {
		printf("error opening file");
		close(fp);
		return -1;
	} else {
		for (i = 0; i < nbVal; i++) {
			write(fp, &tabR[i], sizeof(double));
		}

		close(fp);
		return 0;
	}
	return (0);
}
Ejemplo n.º 8
0
complex<double> CUniformDisk::GetVis(OIUVPtr uv, double wavelength)
{
	// TODO: Implement memoization to speed up computations.
	double b = uv->GetBaselineLength();
	double x = M_PI * mDiameter * b / wavelength;
	return 2 * j1(x) / x;
}
void Foam::equationReader::evalDimsJ1DimCheck
(
    const equationReader * eqnReader,
    const label index,
    const label i,
    const label storageOffset,
    label& storeIndex,
    dimensionSet& xDims,
    dimensionSet sourceDims
) const
{
    if
    (
        !xDims.dimensionless() && dimensionSet::debug
    )
    {
        WarningIn("equationReader::evalDimsJ1DimCheck")
            << "Dimension error thrown for operation ["
            << equationOperation::opName
            (
                operator[](index)[i].operation()
            )
            << "] in equation " << operator[](index).name()
            << ", given by:" << token::NL << token::TAB
            << operator[](index).rawText();
    }
    dimensionedScalar ds("temp", xDims, 0.0);
    xDims.reset(j1(ds).dimensions());
    operator[](index)[i].assignOpDimsFunction
    (
        &Foam::equationReader::evalDimsJ1
    );
}
Ejemplo n.º 10
0
double
Date::getYearDaysNum( double myY )
{
    Julian j1(date2Julian( myY+1., 1., 1., 0.) );
    Julian j0(date2Julian( myY, 1., 1., 0.) );

    return static_cast<double>( j1.jdn - j0.jdn ) ;
}
Ejemplo n.º 11
0
bool Test::JobDefaultState::run()
{
    Job j1(1, "test-machine1");

    if (j1.moveable())
        return true;
    else
        return false;
}
Ejemplo n.º 12
0
double
y1(double x)
{
	double z, s, c, ss, cc, u, v;
    /* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */
	if (!finite(x)) {
		if (!_IEEE) return (infnan(EDOM));
		else if (x < 0)
			return(zero/zero);
		else if (x > 0)
			return (0);
		else
			return(x);
	}
	if (x <= 0) {
		if (_IEEE && x == 0) return -one/zero;
		else if(x == 0) return(infnan(-ERANGE));
		else if(_IEEE) return (zero/zero);
		else return(infnan(EDOM));
	}
        if (x >= 2) {			 /* |x| >= 2.0 */
                s = sin(x);
                c = cos(x);
                ss = -s-c;
                cc = s-c;
		if (x < .5 * DBL_MAX) {	/* make sure x+x not overflow */
                    z = cos(x+x);
                    if ((s*c)>zero) cc = z/ss;
                    else            ss = z/cc;
                }
        /* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x0)+q1(x)*cos(x0))
         * where x0 = x-3pi/4
         *      Better formula:
         *              cos(x0) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
         *                      =  1/sqrt(2) * (sin(x) - cos(x))
         *              sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
         *                      = -1/sqrt(2) * (cos(x) + sin(x))
         * To avoid cancellation, use
         *              sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
         * to compute the worse one.
         */
                if (_IEEE && x>two_129) {
			z = (invsqrtpi*ss)/sqrt(x);
                } else {
                    u = pone(x); v = qone(x);
                    z = invsqrtpi*(u*ss+v*cc)/sqrt(x);
                }
                return z;
        }
        if (x <= two_m54) {    /* x < 2**-54 */
            return (-tpi/x);
        }
        z = x*x;
        u = u0[0]+z*(u0[1]+z*(u0[2]+z*(u0[3]+z*u0[4])));
        v = one+z*(v0[0]+z*(v0[1]+z*(v0[2]+z*(v0[3]+z*v0[4]))));
        return (x*(u/v) + tpi*(j1(x)*log(x)-one/x));
}
Ejemplo n.º 13
0
bool Test::JobID::run()
{
    const int job_id = 1;
    Job j1(job_id, "test-machine1");

    if (j1.get_id() == job_id)
        return true;
    else
        return false;
}
Ejemplo n.º 14
0
bool Test::JobMachineName::run()
{
    const std::string machine_name("test-machine1");
    Job j1(1, machine_name);

    if (j1.get_machine() == machine_name)
        return true;
    else
        return false;
}
Ejemplo n.º 15
0
 std::complex<double> SBTopHat::SBTopHatImpl::kValue2(double kr0sq) const
 {
     if (kr0sq < 1.e-4) {
         // Use the Taylor expansion for small arguments.
         // Error from omitting next term is about 1.e-16 for kr0sq = 1.e-4
         return _flux * (1. - kr0sq * ( (1./8.) + (1./192.) * kr0sq ));
     } else {
         double kr0 = sqrt(kr0sq);
         return 2.*_flux * j1(kr0)/kr0;
     }
 }
Ejemplo n.º 16
0
double
Date::getDayOfTheYear(double y, double mo, double d,
                      double h, double mi, double s)
{
    double deciH = h + mi/60. + s/3600. ;
    Julian j0(date2Julian( y, 1., 1., 0.) );
    Julian j1(date2Julian( y, mo, d, deciH) );

    // the 1st of Jan, etc.!
    return ( static_cast<double>( j1.jdn - j0.jdn ) + 1. ) ;
}
Ejemplo n.º 17
0
 // This is a scale-free version of the Airy radial function.
 // Input radius is in units of lambda/D.  Output normalized
 // to integrate to unity over input units.
 double AiryInfoObs::RadialFunction::operator()(double radius) const
 {
     double nu = radius*M_PI;
     // Taylor expansion of j1(u)/u = 1/2 - 1/16 x^2 + ...
     // We can truncate this to 1/2 when neglected term is less than xvalue_accuracy
     // (relative error, so divide by 1/2)
     // xvalue_accuracy = 1/8 x^2
     const double thresh = sqrt(8.*_gsparams->xvalue_accuracy);
     double xval;
     if (nu < thresh) {
         // lim j1(u)/u = 1/2
         xval =  0.5 * (1.-_obssq);
     } else {
         // See Schroeder eq (10.1.10)
         xval = ( j1(nu) - _obscuration*j1(_obscuration*nu) ) / nu ;
     }
     xval *= xval;
     // Normalize to give unit flux integrated over area.
     xval *= _norm;
     return xval;
 }
Ejemplo n.º 18
0
double 
y1 (double x)
{
  if (x <= 0.0)
    return (dzero/dzero);	/* IEEE machines: invalid operation */
  if (x < 8.0)
    return x * yone(x) + TWO_ON_PI * (j1(x) * log(x) - 1.0/x);
  else
    return (sqrt(TWO_ON_PI/x) 
	    * (pone(x) * sin (x - THREE_PI_ON_FOUR) 
	       + (8.0/x) * qone(x) * cos(x - THREE_PI_ON_FOUR)));
}
void Foam::equationReader::evalScalarFieldJ1
(
    const equationReader * eqnReader,
    const label index,
    const label i,
    const label storageOffset,
    label& storeIndex,
    scalarField& x,
    const scalarField& source
) const
{
    j1(x, x);
}
Ejemplo n.º 20
0
double
y1(double x)
{
	double z, s,c,ss,cc,u,v;
	int32_t hx,ix,lx;

	EXTRACT_WORDS(hx,lx,x);
        ix = 0x7fffffff&hx;
    /* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */
	if(ix>=0x7ff00000) return  one/(x+x*x);
        if((ix|lx)==0) return -one/zero;
        if(hx<0) return zero/zero;
        if(ix >= 0x40000000) {  /* |x| >= 2.0 */
                s = sin(x);
                c = cos(x);
                ss = -s-c;
                cc = s-c;
                if(ix<0x7fe00000) {  /* make sure x+x not overflow */
                    z = cos(x+x);
                    if ((s*c)>zero) cc = z/ss;
                    else            ss = z/cc;
                }
        /* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x0)+q1(x)*cos(x0))
         * where x0 = x-3pi/4
         *      Better formula:
         *              cos(x0) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
         *                      =  1/sqrt(2) * (sin(x) - cos(x))
         *              sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
         *                      = -1/sqrt(2) * (cos(x) + sin(x))
         * To avoid cancellation, use
         *              sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
         * to compute the worse one.
         */
                if(ix>0x48000000) z = (invsqrtpi*ss)/sqrt(x);
                else {
                    u = pone(x); v = qone(x);
                    z = invsqrtpi*(u*ss+v*cc)/sqrt(x);
                }
                return z;
        }
        if(ix<=0x3c900000) {    /* x < 2**-54 */
            return(-tpi/x);
        }
        z = x*x;
        u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4])));
        v = one+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4]))));
        return(x*(u/v) + tpi*(j1(x)*log(x)-one/x));
}
Ejemplo n.º 21
0
int main(int argc, char * argv[])
{
  printf("hello\n");
  Polygon p1;
  Polygon p2;
  Polygons ps1;
  Polygons ps2;

  IntPoint i1(0, 0);
  IntPoint i2(0, 100);
  IntPoint i3(100, 100);
  IntPoint i4(100, 0);

  IntPoint j1(0, 0);
  IntPoint j2(50, 200);
  IntPoint j3(100, 0);

  p1.push_back(i1);
  p1.push_back(i2);
  p1.push_back(i3);
  p1.push_back(i4);

  p2.push_back(j1);
  p2.push_back(j2);
  p2.push_back(j3);

  ps1.push_back(p1);
  ps2.push_back(p2);

  Clipper clipper;

  clipper.AddPolygons(ps1, ptSubject);
  clipper.AddPolygons(ps2, ptClip);
  Polygons soln;
  clipper.Execute(ctIntersection, soln);

  for(int i = 0; i < soln.size(); i++)
  {
    Polygon& p = soln[i];
    for(int j = 0; j < p.size(); j++)
    {
      printf("Point:(%lld,%lld)\n", p[j].X, p[j].Y);
    }
  }

  printf("hehe\n");
  return 0;
}
Ejemplo n.º 22
0
void Deck::formDeck()
{
    for (int i = 0; i < 4; ++i)
    {
        for (int j = 0; j < 13; ++j)
        {
            Card c(i, j);
            mDeck.push_back(c);
        }
    }
    if (withJoker != 0)
    {
        Card j1(4, 13);
        mDeck.push_back(j1);
        mDeck.push_back(j1);
    }
}
Ejemplo n.º 23
0
void massive() {

  for ( int i = 0; i < 2; ++i ) { 

    double p = 30;
    double m = 5;

    PxPyPzM j1(p*sin(4.*atan(1.)*2./3.),p*cos(4.*atan(1.)*2./3.),0.,i==0?m:0.);
    PxPyPzM j2(p*sin(4.*atan(1.)*4./3.),p*cos(4.*atan(1.)*4./3.),0.,i==0?m:0.);
  
    double ht = j1.Et() + j2.Et();
    double mht = (j1 + j2).Pt();
    double dht = j1.Et() - j2.Et();
    double at = (0.5*(ht-dht))/sqrt(ht*ht-mht*mht);

    std::cout << (i==0?"[massive] ":"[massless] ")
	      << std::endl
	      << " M: " << j1.M()
	      << " Px: " << j1.Px()
	      << " Py: " << j1.Py()
	      << " Pz: " << j1.Pz()
	      << " P: " << j1.P()
	      << " E: " << j1.E()
	      << " PT: " << j1.Pt()
	      << " ET: " << j1.Et()
	      << std::endl
	      << " M: " << j2.M()
	      << " Px: " << j2.Px()
	      << " Py: " << j2.Py()
	      << " Pz: " << j2.Pz()
	      << " P: " << j2.P()
	      << " E: " << j2.E()
	      << " PT: " << j2.Pt()
	      << " ET: " << j2.Et()
	      << std::endl
	      << " ht: " << ht
	      << " dht: " << dht
	      << " mht: " << mht
	      << " at: " << at
	      << std::endl;

  }

}
Ejemplo n.º 24
0
double y1(double arg)
{
	double xsq, n, d, x;
	int i;

	x = arg;
	if(x <= 0.){
		return(-HUGE_VAL);
	}
	if(x > 8.){
		asympt(x);
		n = x - 3*pio4;
		return(sqrt(tpi/x)*(pzero*sin(n) + qzero*cos(n)));
	}
	xsq = x*x;
	for(n=0,d=0,i=9;i>=0;i--){
		n = n*xsq + p4[i];
		d = d*xsq + q4[i];
	}
	return(x*n/d + tpi*(j1(x)*log(x)-1./x));
}
Ejemplo n.º 25
0
_WMRTLINK double y1( double x )         /* Bessel function y1(x) */
/*******************/
    {
        double  xx, y, z;

        if( x < 0.0 ) {
//            z = _matherr( DOMAIN, "y1", &x, &x, - HUGE_VAL );
            z = __math1err( FUNC_Y1 | M_DOMAIN | V_NEG_HUGEVAL, &x );
        } else if( x < 8.0 ) {
            y = x * x;
            z = PDIV( x * _EvalPoly( y, _Y1P, 10 )  ,  _EvalPoly( y, _Y1Q, 4 ) )
                   + Two_over_pi * ( j1(x) * log(x) - PDIV(1.0,x) );
        } else {
            z = PDIV( 8.0 , x );
            y = z * z;
            xx = x - ThreePIby4;
            z = sqrt( PDIV( Two_over_pi , x ) ) *
                ( PDIV( sin(xx) * _EvalPoly( y, _P1P, 4 ) , _EvalPoly( y, _P1Q, 5 ) )
            + z * cos(xx) *(PDIV(_EvalPoly( y, _Q1P, 4 ) , _EvalPoly( y, _Q1Q, 4 ))));
        }
        return( z );
    }
Ejemplo n.º 26
0
double
Date::getMonthDaysNum( double myMon, double myY )
{
    if( currCalendarEnum == EQUAL_MONTHS )
        return 30. ;

    int  mon = static_cast<int>( myMon );
    double t = regularMonthDays[mon-1] ;

    bool is = currCalendarEnum == GREGORIAN
              || currCalendarEnum == PROLEPTIC_GREGORIAN ;

    if( mon == 2 && is )
    {
        Julian j1(date2Julian( myY, myMon +1., 1., 0.) );
        Julian j0(date2Julian( myY, myMon    , 1., 0.) );

        long double tld= j1.jdn - j0.jdn  ;
        tld += (j1.time -j0.time) ;
        t = static_cast<double>( static_cast<int>(tld+0.5) );
    }

    return t ;
}
Ejemplo n.º 27
0
double
y1(double arg)
{
    double xsq, n, d, x;
    int i;

    errno = 0;
    x = arg;
    if(x <= 0) {
        errno = EDOM;
        return -HUGE_VAL;
    }
    if(x > 8) {
        asympt(x);
        n = x - 3*pio4;
        return sqrt(tpi/x)*(pzero*sin(n) + qzero*cos(n));
    }
    xsq = x*x;
    for(n=0,d=0,i=9; i>=0; i--) {
        n = n*xsq + p4[i];
        d = d*xsq + q4[i];
    }
    return x*n/d + tpi*(j1(x)*log(x)-1/x);
}
Ejemplo n.º 28
0
double jv(double n, double x)
{
    double k, q, t, y, an;
    int i, sign, nint;

    nint = 0;			/* Flag for integer n */
    sign = 1;			/* Flag for sign inversion */
    an = fabs(n);
    y = floor(an);
    if (y == an) {
        nint = 1;
        i = an - 16384.0 * floor(an / 16384.0);
        if (n < 0.0) {
            if (i & 1)
                sign = -sign;
            n = an;
        }
        if (x < 0.0) {
            if (i & 1)
                sign = -sign;
            x = -x;
        }
        if (n == 0.0)
            return (j0(x));
        if (n == 1.0)
            return (sign * j1(x));
    }

    if ((x < 0.0) && (y != an)) {
        mtherr("Jv", DOMAIN);
        y = NPY_NAN;
        goto done;
    }

    if (x == 0 && n < 0 && !nint) {
        mtherr("Jv", OVERFLOW);
        return NPY_INFINITY / gamma(n + 1);
    }

    y = fabs(x);

    if (y * y < fabs(n + 1) * MACHEP) {
        return pow(0.5 * x, n) / gamma(n + 1);
    }

    k = 3.6 * sqrt(y);
    t = 3.6 * sqrt(an);
    if ((y < t) && (an > 21.0))
        return (sign * jvs(n, x));
    if ((an < k) && (y > 21.0))
        return (sign * hankel(n, x));

    if (an < 500.0) {
        /* Note: if x is too large, the continued fraction will fail; but then the
         * Hankel expansion can be used. */
        if (nint != 0) {
            k = 0.0;
            q = recur(&n, x, &k, 1);
            if (k == 0.0) {
                y = j0(x) / q;
                goto done;
            }
            if (k == 1.0) {
                y = j1(x) / q;
                goto done;
            }
        }

        if (an > 2.0 * y)
            goto rlarger;

        if ((n >= 0.0) && (n < 20.0)
                && (y > 6.0) && (y < 20.0)) {
            /* Recur backwards from a larger value of n */
rlarger:
            k = n;

            y = y + an + 1.0;
            if (y < 30.0)
                y = 30.0;
            y = n + floor(y - n);
            q = recur(&y, x, &k, 0);
            y = jvs(y, x) * q;
            goto done;
        }

        if (k <= 30.0) {
            k = 2.0;
        }
        else if (k < 90.0) {
            k = (3 * k) / 4;
        }
        if (an > (k + 3.0)) {
            if (n < 0.0)
                k = -k;
            q = n - floor(n);
            k = floor(k) + q;
            if (n > 0.0)
                q = recur(&n, x, &k, 1);
            else {
                t = k;
                k = n;
                q = recur(&t, x, &k, 1);
                k = t;
            }
            if (q == 0.0) {
underf:
                y = 0.0;
                goto done;
            }
        }
        else {
            k = n;
            q = 1.0;
        }

        /* boundary between convergence of
         * power series and Hankel expansion
         */
        y = fabs(k);
        if (y < 26.0)
            t = (0.0083 * y + 0.09) * y + 12.9;
        else
            t = 0.9 * y;

        if (x > t)
            y = hankel(k, x);
        else
            y = jvs(k, x);
#if CEPHES_DEBUG
        printf("y = %.16e, recur q = %.16e\n", y, q);
#endif
        if (n > 0.0)
            y /= q;
        else
            y *= q;
    }

    else {
        /* For large n, use the uniform expansion or the transitional expansion.
         * But if x is of the order of n**2, these may blow up, whereas the
         * Hankel expansion will then work.
         */
        if (n < 0.0) {
            mtherr("Jv", TLOSS);
            y = NPY_NAN;
            goto done;
        }
        t = x / n;
        t /= n;
        if (t > 0.3)
            y = hankel(n, x);
        else
            y = jnx(n, x);
    }

done:
    return (sign * y);
}
Ejemplo n.º 29
0
void VCharUnit::run() {
    VChar    x1('x');
    VChar    x2(0x78);
    VUNIT_ASSERT_EQUAL_LABELED(x1, 'x', "character ctor");
    VUNIT_ASSERT_EQUAL_LABELED(x2, 'x', "integer ctor");
    VUNIT_ASSERT_EQUAL_LABELED(x1, x2, "ctor equality");

    x1 = 'y';
    x2 = 0x79;
    VUNIT_ASSERT_EQUAL_LABELED(x1, 'y', "character assignment");
    VUNIT_ASSERT_EQUAL_LABELED(x2, 'y', "integer assignment");
    VUNIT_ASSERT_EQUAL_LABELED(x1, x2, "assignment equality");

    x1 = 'a';
    VUNIT_ASSERT_TRUE_LABELED(x1.isLowerCase(), "lower case");
    VUNIT_ASSERT_TRUE_LABELED(! x1.isUpperCase(), "not upper case");
    x2 = 'A';
    VUNIT_ASSERT_TRUE_LABELED(! x2.isLowerCase(), "not lower case");
    VUNIT_ASSERT_TRUE_LABELED(x2.isUpperCase(), "upper case");
    x2.toLowerCase();
    VUNIT_ASSERT_TRUE_LABELED(x2.isLowerCase(), "to lower case");
    VUNIT_ASSERT_EQUAL_LABELED(x2, x1, "to lower case equality");
    x1.toUpperCase();
    VUNIT_ASSERT_TRUE_LABELED(x1.isUpperCase(), "to upper case");
    VUNIT_ASSERT_EQUAL_LABELED(x1, 'A', "to upper case equality");

    x1 = 'b';
    VChar bigB = x1.upperCase();
    VUNIT_ASSERT_EQUAL_LABELED(bigB, 'B', "return upper case");
    VChar littleB = bigB.lowerCase();
    VUNIT_ASSERT_EQUAL_LABELED(littleB, 'b', "return lower case");
    VUNIT_ASSERT_EQUAL_LABELED(littleB.charValue(), 'b', "char value");
    VUNIT_ASSERT_EQUAL_LABELED(littleB.intValue(), 0x62, "int value");

    x1.set('c');
    VUNIT_ASSERT_EQUAL_LABELED(x1, 'c', "set char");
    x1.set(0x64);
    VUNIT_ASSERT_EQUAL_LABELED(x1, 'd', "set int");

    x1 = 'd';
    char littleD = x1;
    VUNIT_ASSERT_EQUAL_LABELED(littleD, 'd', "operator char");

    VChar    i1('i');
    VChar    i2('i');
    VChar    j1('j');
    VChar    j2('j');
    VUNIT_ASSERT_TRUE_LABELED(i1 != j1, "inequality");
    VUNIT_ASSERT_TRUE_LABELED(i1 < j1, "LT");
    VUNIT_ASSERT_TRUE_LABELED(!(i1 < i2), "not LT");
    VUNIT_ASSERT_TRUE_LABELED(j1 > i1, "GT");
    VUNIT_ASSERT_TRUE_LABELED(!(j1 > j2), "not GT");
    VUNIT_ASSERT_TRUE_LABELED(i1 <= i2, "LTE 1");
    VUNIT_ASSERT_TRUE_LABELED(i1 <= j1, "LTE 2");
    VUNIT_ASSERT_TRUE_LABELED(j1 >= j2, "GTE 1");
    VUNIT_ASSERT_TRUE_LABELED(j1 >= i1, "GTE 2");
    VUNIT_ASSERT_TRUE_LABELED(!(j1 <= i1), "not LTE");
    VUNIT_ASSERT_TRUE_LABELED(!(i1 >= j1), "not GTE");

    VUNIT_ASSERT_TRUE_LABELED(VChar::equalsIgnoreCase(VChar('x'), VChar('X')), "equalsIgnoreCase 1");
    VUNIT_ASSERT_TRUE_LABELED(VChar::equalsIgnoreCase('x', VChar('X')), "equalsIgnoreCase 2");
    VUNIT_ASSERT_TRUE_LABELED(VChar::equalsIgnoreCase(VChar('x'), 'X'), "equalsIgnoreCase 3");
    VUNIT_ASSERT_TRUE_LABELED(VChar::equalsIgnoreCase('x', 'X'), "equalsIgnoreCase 4");
    VUNIT_ASSERT_TRUE_LABELED(VChar::equalsIgnoreCase(VChar('5'), VChar('5')), "equalsIgnoreCase 5"); // test numbers
    VUNIT_ASSERT_TRUE_LABELED(VChar::equalsIgnoreCase(VChar('!'), VChar('!')), "equalsIgnoreCase 6"); // test punctuation
    VUNIT_ASSERT_TRUE_LABELED(VChar::equalsIgnoreCase(VChar(' '), VChar(' ')), "equalsIgnoreCase 7"); // test whitespace

    VUNIT_ASSERT_FALSE_LABELED(VChar::equalsIgnoreCase(VChar('x'), VChar('y')), "!equalsIgnoreCase 1");
    VUNIT_ASSERT_FALSE_LABELED(VChar::equalsIgnoreCase('x', VChar('y')), "!equalsIgnoreCase 2");
    VUNIT_ASSERT_FALSE_LABELED(VChar::equalsIgnoreCase(VChar('x'), 'y'), "!equalsIgnoreCase 3");
    VUNIT_ASSERT_FALSE_LABELED(VChar::equalsIgnoreCase('x', 'y'), "!equalsIgnoreCase 4");
    VUNIT_ASSERT_FALSE_LABELED(VChar::equalsIgnoreCase(VChar('5'), VChar('6')), "!equalsIgnoreCase 5"); // test numbers
    VUNIT_ASSERT_FALSE_LABELED(VChar::equalsIgnoreCase(VChar('!'), VChar('@')), "!equalsIgnoreCase 6"); // test punctuation
    VUNIT_ASSERT_FALSE_LABELED(VChar::equalsIgnoreCase(VChar(' '), VChar('\t')), "!equalsIgnoreCase 7"); // test whitespace

    // Test the known ranges of alpha/numeric/whitespace values.
    for (int i = 0; i < 256; ++i) {
        VChar    c(i);

        if ((i <= 0x20) || (i == 0x7F)) {
            // This is the range VChar considers "whitespace".
            this->test(
                !c.isLowerCase() &&
                !c.isUpperCase() &&
                (c.intValue() == i) &&
                !c.isAlpha() &&
                !c.isNumeric() &&
                !c.isAlphaNumeric() &&
                c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else if (i <= 0x2F) {
            // This is all punctuation.
            this->test(
                !c.isLowerCase() &&
                !c.isUpperCase() &&
                (c.intValue() == i) &&
                !c.isAlpha() &&
                !c.isNumeric() &&
                !c.isAlphaNumeric() &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else if (i <= 0x39) {
            // This is 0 thru 9.
            this->test(
                !c.isLowerCase() &&
                !c.isUpperCase() &&
                (c.intValue() == i) &&
                !c.isAlpha() &&
                c.isNumeric() &&
                c.isAlphaNumeric() &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else if (i <= 0x40) {
            // This is all punctuation.
            this->test(
                !c.isLowerCase() &&
                !c.isUpperCase() &&
                (c.intValue() == i) &&
                !c.isAlpha() &&
                !c.isNumeric() &&
                !c.isAlphaNumeric() &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else if (i <= 0x5A) {
            // This is A thru Z.
            this->test(
                !c.isLowerCase() &&
                c.isUpperCase() &&
                (c.intValue() == i) &&
                c.isAlpha() &&
                !c.isNumeric() &&
                c.isAlphaNumeric() &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else if (i <= 0x60) {
            // This is all punctuation.
            this->test(
                !c.isLowerCase() &&
                !c.isUpperCase() &&
                (c.intValue() == i) &&
                !c.isAlpha() &&
                !c.isNumeric() &&
                !c.isAlphaNumeric() &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else if (i <= 0x7A) {
            // This is a thru z.
            this->test(
                c.isLowerCase() &&
                !c.isUpperCase() &&
                (c.intValue() == i) &&
                c.isAlpha() &&
                !c.isNumeric() &&
                c.isAlphaNumeric() &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else if (i <= 0x7E) {
            // This is all punctuation.
            this->test(
                !c.isLowerCase() &&
                !c.isUpperCase() &&
                (c.intValue() == i) &&
                !c.isAlpha() &&
                !c.isNumeric() &&
                !c.isAlphaNumeric() &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else { // (we already checked 0x7F) so 0x80 <= i <= 0xFF
            // Properties of stuff at 0x80 and higher are not well-defined
            // and may vary based on the platform's ideas about upper case,
            // lower case, alphanumeric-ness, etc. Just test the basics.
            this->test(
                (c.intValue() == i) &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        }
    }

}
Ejemplo n.º 30
0
void test_extract() {
    int counts = 0;
    tbb::flow::tuple<int,int> dont_care;
    tbb::flow::graph g;
    typedef tbb::flow::source_node<int> snode_type;
    tbb::flow::source_node<int> s0(g, source_body<int>(counts), /*is_active*/false ); 
    tbb::flow::join_node< tbb::flow::tuple<int,int>, tbb::flow::reserving > j0(g);
    tbb::flow::join_node< tbb::flow::tuple<int,int>, tbb::flow::reserving > j1(g);
    tbb::flow::join_node< tbb::flow::tuple<int,int>, tbb::flow::reserving > j2(g);
    tbb::flow::queue_node<int> q0(g);
    tbb::flow::queue_node<tbb::flow::tuple<int,int> > q1(g);
    tbb::flow::make_edge(s0, tbb::flow::get<0>(j0.input_ports()));
    /*  s0 ----+    */
    /*         | j0 */
    /*         +    */
    ASSERT(!counts, "source_node activated too soon");
    s0.activate();
    g.wait_for_all();  // should produce one value, buffer it.
    ASSERT(counts == 1, "source_node did not react to activation");

    g.reset(tbb::flow::rf_reset_bodies);
    counts = 0;
    s0.extract();
    /*  s0     +    */
    /*         | j0 */
    /*         +    */
    s0.activate();
    g.wait_for_all();  // no successors, so the body will not execute
    ASSERT(counts == 0, "source_node shouldn't forward (no successors)");
    s0.extract(tbb::flow::rf_reset_bodies);

    tbb::flow::make_edge(s0, tbb::flow::get<0>(j0.input_ports()));
    tbb::flow::make_edge(s0, tbb::flow::get<0>(j1.input_ports()));
    tbb::flow::make_edge(s0, tbb::flow::get<0>(j2.input_ports()));

    /*        /+    */
    /*       / | j0 */
    /*      /  +    */
    /*     /        */
    /*    / /--+    */
    /*  s0-/   | j1 */
    /*    \    +    */
    /*     \        */
    /*      \--+    */
    /*         | j2 */
    /*         +    */

    // do all joins appear in successor list?
    std::vector<tbb::flow::receiver<int>*> jv1;
    jv1.push_back(&(tbb::flow::get<0>(j0.input_ports())));
    jv1.push_back(&(tbb::flow::get<0>(j1.input_ports())));
    jv1.push_back(&(tbb::flow::get<0>(j2.input_ports())));
    tbb::flow::source_node<int>::successor_vector_type sv;
    s0.copy_successors(sv);
    ASSERT(lists_match(sv, jv1), "mismatch in successor list");

    tbb::flow::make_edge(q0, tbb::flow::get<1>(j2.input_ports()));
    tbb::flow::make_edge(j2, q1);
    s0.activate();

    /*        /+           */
    /*       / | j0        */
    /*      /  +           */
    /*     /               */
    /*    / /--+           */
    /*  s0-/   | j1        */
    /*    \    +           */
    /*     \               */
    /*      \--+           */
    /*         | j2----q1  */
    /*  q0-----+           */

    q0.try_put(1);
    g.wait_for_all();
    ASSERT(q1.try_get(dont_care), "join did not emit result");
    j2.extract();
    tbb::flow::make_edge(q0, tbb::flow::get<1>(j2.input_ports()));
    tbb::flow::make_edge(j2, q1);

    /*        /+           */
    /*       / | j0        */
    /*      /  +           */
    /*     /               */
    /*    / /--+           */
    /*  s0-/   | j1        */
    /*         +           */
    /*                     */
    /*         +           */
    /*         | j2----q1  */
    /*  q0-----+           */

    jv1.clear();
    jv1.push_back(&(tbb::flow::get<0>(j0.input_ports())));
    jv1.push_back(&(tbb::flow::get<0>(j1.input_ports())));
    s0.copy_successors(sv);
    ASSERT(lists_match(sv, jv1), "mismatch in successor list");

    q0.try_put(1);
    g.wait_for_all();
    ASSERT(!q1.try_get(dont_care), "extract of successor did not remove pred link");

    s0.extract();

    /*         +           */
    /*         | j0        */
    /*         +           */
    /*                     */
    /*         +           */
    /*  s0     | j1        */
    /*         +           */
    /*                     */
    /*         +           */
    /*         | j2----q1  */
    /*  q0-----+           */

    ASSERT(s0.successor_count() == 0, "successor list not cleared");
    s0.copy_successors(sv);
    ASSERT(sv.size() == 0, "non-empty successor list");

    tbb::flow::make_edge(s0, tbb::flow::get<0>(j2.input_ports()));

    /*         +           */
    /*         | j0        */
    /*         +           */
    /*                     */
    /*         +           */
    /*  s0     | j1        */
    /*    \    +           */
    /*     \               */
    /*      \--+           */
    /*         | j2----q1  */
    /*  q0-----+           */

    jv1.clear();
    jv1.push_back(&(tbb::flow::get<0>(j2.input_ports())));
    s0.copy_successors(sv);
    ASSERT(lists_match(sv, jv1), "mismatch in successor list");

    q0.try_put(1);
    g.wait_for_all();
    ASSERT(!q1.try_get(dont_care), "extract of successor did not remove pred link");
}