double yn (int n, double x) { int i, sign; double a, b, tmp; if (x <= 0) return (dzero/dzero); /* IEEE machines: invalid operation */ sign = 1; if (n < 0) { n = -n; if (n%2 == 1) sign = -1; } if (n == 0) return y0(x); if (n == 1) return sign*y1(x); a = y0(x); b = y1(x); for (i = 1; i<n; i++) { tmp = b; b = (2.0*i / x) * b - a; a = tmp; } return sign*b; }
/* MapLine::needsTexture * Returns a flag set of any parts of the line that require a texture *******************************************************************/ int MapLine::needsTexture() { // Check line is valid if (!frontSector()) return 0; // If line is 1-sided, it only needs front middle if (!backSector()) return TEX_FRONT_MIDDLE; // Get sector planes plane_t floor_front = frontSector()->getFloorPlane(); plane_t ceiling_front = frontSector()->getCeilingPlane(); plane_t floor_back = backSector()->getFloorPlane(); plane_t ceiling_back = backSector()->getCeilingPlane(); double front_height, back_height; int tex = 0; // Check the floor front_height = floor_front.height_at(x1(), y1()); back_height = floor_back.height_at(x1(), y1()); if (front_height - back_height > EPSILON) tex |= TEX_BACK_LOWER; if (back_height - front_height > EPSILON) tex |= TEX_FRONT_LOWER; front_height = floor_front.height_at(x2(), y2()); back_height = floor_back.height_at(x2(), y2()); if (front_height - back_height > EPSILON) tex |= TEX_BACK_LOWER; if (back_height - front_height > EPSILON) tex |= TEX_FRONT_LOWER; // Check the ceiling front_height = ceiling_front.height_at(x1(), y1()); back_height = ceiling_back.height_at(x1(), y1()); if (back_height - front_height > EPSILON) tex |= TEX_BACK_UPPER; if (front_height - back_height > EPSILON) tex |= TEX_FRONT_UPPER; front_height = ceiling_front.height_at(x2(), y2()); back_height = ceiling_back.height_at(x2(), y2()); if (back_height - front_height > EPSILON) tex |= TEX_BACK_UPPER; if (front_height - back_height > EPSILON) tex |= TEX_FRONT_UPPER; return tex; }
void Quad::set_range(double nx1, double nx2, double ny1, double ny2) { *x1() = nx1; *x2() = nx2; *y1() = ny1; *y2() = ny2; *x_mid() = ( *x1() + *x2() )*0.5f; *y_mid() = ( *y1() + *y2() )*0.5f; }
double yn(int n, double x) { int i, sign; double a, b, temp; /* Y(n,NaN), Y(n, x < 0) is NaN */ if (x <= 0 || isnan(x)) if (_IEEE && x < 0) return zero/zero; else if (x < 0) return (infnan(EDOM)); else if (_IEEE) return -one/zero; else return(infnan(-ERANGE)); else if (!finite(x)) return(0); sign = 1; if (n<0){ n = -n; sign = 1 - ((n&1)<<2); } if (n == 0) return(y0(x)); if (n == 1) return(sign*y1(x)); if(_IEEE && x >= 8.148143905337944345e+090) { /* x > 2**302 */ /* (x >> n**2) * Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi) * Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi) * Let s=sin(x), c=cos(x), * xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then * * n sin(xn)*sqt2 cos(xn)*sqt2 * ---------------------------------- * 0 s-c c+s * 1 -s-c -c+s * 2 -s+c -c-s * 3 s+c c-s */ switch (n&3) { case 0: temp = sin(x)-cos(x); break; case 1: temp = -sin(x)-cos(x); break; case 2: temp = -sin(x)+cos(x); break; case 3: temp = sin(x)+cos(x); break; } b = invsqrtpi*temp/sqrt(x); } else { a = y0(x); b = y1(x); /* quit if b is -inf */ for (i = 1; i < n && !finite(b); i++){ temp = b; b = ((double)(i+i)/x)*b - a; a = temp; } } if (!_IEEE && !finite(b)) return (infnan(-sign * ERANGE)); return ((sign > 0) ? b : -b); }
bool SimpleRegion::intersects(SimpleRegion obstacle) { return ( ( (x1() <= obstacle.x1() && obstacle.x1() <= x2()) || (x1() <= obstacle.x2() && obstacle.x2() <= x2()) ) && ( (y1() <= obstacle.y1() && obstacle.y1() <= y2()) || (y1() <= obstacle.y2() && obstacle.y2() <= y2()) ) ); }
void Terrain::split() { if(is_split()) return; quads[0][0] = new Terrain(V); quads[0][1] = new Terrain(V); quads[1][0] = new Terrain(V); quads[1][1] = new Terrain(V); quads[0][0]->set_range(*x1(), *x_mid(), *y1(), *y_mid()); quads[0][1]->set_range(*x_mid(), *x2(), *y1(), *y_mid()); quads[1][0]->set_range(*x1(), *x_mid(), *y_mid(), *y2()); quads[1][1]->set_range(*x_mid(), *x2(), *y_mid(), *y2()); }
void Quad::split() { if(is_split()) return; quads[0][0] = new Quad(V); quads[0][1] = new Quad(V); quads[1][0] = new Quad(V); quads[1][1] = new Quad(V); quads[0][0]->set_range( *x1(), *x_mid(), *y1(), *y_mid() ); quads[0][1]->set_range( *x_mid(), *x2(), *y1(), *y_mid() ); quads[1][0]->set_range( *x1(), *x_mid(), *y_mid(), *y2() ); quads[1][1]->set_range( *x_mid(), *x2(), *y_mid(), *y2() ); }
std::vector< std::vector<Real> > ElectroIonicModel::getJac (const std::vector<Real>& v, Real h) { std::vector< std::vector<Real> > J ( M_numberOfEquations, std::vector<Real> (M_numberOfEquations, 0.0) ); std::vector<Real> f1 (M_numberOfEquations, 0.0); std::vector<Real> f2 (M_numberOfEquations, 0.0); std::vector<Real> y1 (M_numberOfEquations, 0.0); std::vector<Real> y2 (M_numberOfEquations, 0.0); for (int i = 0; i < M_numberOfEquations; i++) { for (int j = 0; j < M_numberOfEquations; j++) { y1[j] = v[j] + ( (double) (i == j) ) * h; y2[j] = v[j] - ( (double) (i == j) ) * h; } this->computeRhs (y1, f1); f1[0] += M_appliedCurrent; this->computeRhs (y2, f2); f2[0] += M_appliedCurrent; for (int j = 0; j < M_numberOfEquations; j++) { J[j][i] = (f1[j] - f2[j]) / (2.0 * h); } } return J; }
//.. // Our verification program simply instantiate several 'MyGenericContainer' // templates with the two test types above, and checks that the allocator // slot is as expected: //.. int usageExample() { bslma::TestAllocator ta0; bslma::TestAllocator ta1; //.. // With 'MyTestTypeWithNoBslmaAllocatorTraits', the slot should never be set. //.. MyTestTypeWithNoBslmaAllocatorTraits x; allocSlot = &ta0; MyGenericContainer<MyTestTypeWithNoBslmaAllocatorTraits> x0(x); ASSERT(&ta0 == allocSlot); allocSlot = &ta0; MyGenericContainer<MyTestTypeWithNoBslmaAllocatorTraits> x1(x, &ta1); ASSERT(&ta0 == allocSlot); //.. // With 'MyTestTypeWithBslmaAllocatorTraits', the slot should be set to the // allocator argument, or to 0 if not specified: //.. MyTestTypeWithBslmaAllocatorTraits y; allocSlot = &ta0; MyGenericContainer<MyTestTypeWithBslmaAllocatorTraits> y0(y); ASSERT(0 == allocSlot); allocSlot = &ta0; MyGenericContainer<MyTestTypeWithBslmaAllocatorTraits> y1(y, &ta1); ASSERT(&ta1 == allocSlot); return 0; }
void Foam::equationReader::evalDimsY1DimCheck ( 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::evalDimsY1DimCheck") << "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, 1.0); xDims.reset(y1(ds).dimensions()); operator[](index)[i].assignOpDimsFunction ( &Foam::equationReader::evalDimsY1 ); }
test_one() { X1 x1(1); Y1 y1(1); f1( x1, y1 ); // in fact, it should find ambiguity, not pass this }
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 = y1(p->x); e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW); if (!checkexcept(e, p->e, p->r)) { printf("%s:%d: bad fp exception: %s y1(%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 ((!(p->x < 0) && !checkulp(d, p->r)) || (p->x < 0 && !isnan(y) && y != -inf)) { printf("%s:%d: %s y1(%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; }
double angle(CBundle* const &b) const { double ax=x1()-x0; double ay=y1()-y0; double bx=b->x1()-b->x0; double by=b->y1()-b->y0; return vangle(ax,ay,bx,by); }
/** * returns the spherical Bessel function of the second kind * needed for continuum states \param l = order of the function (orbital angular momentum) \param rho = independent variable (rho = k * r) */ double sphericalB::y(int l, double rho) { switch (l) { case 0: return y0(rho); case 1: return y1(rho); case 2: return y2(rho); case 3: return y3(rho); case 4: return y4(rho); case 5: return y5(rho); case 6: return y6(rho); case 7: return y7(rho); default: cout << "no l>6 programed in sphericalB" << endl; return 0.; } }
void StringTest::testCompareShort() { cxxtools::String s(L"abcd"); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abcd") , 0); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abc") , 1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abcxyz") , -1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abd") , -1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abb") , 1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("ab") , 1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abcd", 4) , 0); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abcxyz", 3) , 1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abcxyz", 4) , -1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abd", 3) , -1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abb", 3) , 1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("ab", 2) , 1); cxxtools::String x1(L"abc"); CXXTOOLS_UNIT_ASSERT(x1 == "abc"); cxxtools::String y1(L""); cxxtools::String y2(""); CXXTOOLS_UNIT_ASSERT(y1 == y2); CXXTOOLS_UNIT_ASSERT(y1 == ""); CXXTOOLS_UNIT_ASSERT(y2 == ""); }
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; }
void CompOutput::setWorkArea (const CompRect& workarea) { mWorkArea = workarea; if (workarea.x () < (int) x1 ()) mWorkArea.setX (x1 ()); if (workarea.y () < (int) y1 ()) mWorkArea.setY (y1 ()); if (workarea.x2 () > (int) x2 ()) mWorkArea.setWidth (x2 () - mWorkArea.x ()); if (workarea.y2 () > (int) y2 ()) mWorkArea.setHeight (y2 () - mWorkArea.y ()); }
void PointPort::drawItem(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); painter->setPen(pen()); painter->setBrush(brush()); mPointImpl.drawItem(painter, x1() + mUnrealRadius, y1() + mUnrealRadius, mRadius); }
/* MapLine::dirTabPoint * Calculates and returns the end point of the 'direction tab' for * the line (used as a front side indicator for 2d map display) *******************************************************************/ fpoint2_t MapLine::dirTabPoint(double tablen) { // Calculate midpoint fpoint2_t mid(x1() + ((x2() - x1()) * 0.5), y1() + ((y2() - y1()) * 0.5)); // Calculate tab length if (tablen == 0) { tablen = getLength() * 0.1; if (tablen > 16) tablen = 16; if (tablen < 2) tablen = 2; } // Calculate tab endpoint if (front_vec.x == 0 && front_vec.y == 0) frontVector(); return fpoint2_t(mid.x - front_vec.x*tablen, mid.y - front_vec.y*tablen); }
void CompOutput::setWorkArea (const CompRect &workarea) { mWorkArea = workarea; if (workarea.x () < static_cast <int> (x1 ())) mWorkArea.setX (x1 ()); if (workarea.y () < static_cast <int> (y1 ())) mWorkArea.setY (y1 ()); if (workarea.x2 () > static_cast <int> (x2 ())) mWorkArea.setWidth (x2 () - mWorkArea.x ()); if (workarea.y2 () > static_cast <int> (y2 ())) mWorkArea.setHeight (y2 () - mWorkArea.y ()); }
Type Foam::interpolation2DTable<Type>::operator() ( const scalar valueX, const scalar valueY ) const { // Considers all of the list in Y being equal label nX = this->size(); const table& t = *this; if (nX == 0) { WarningIn ( "Type Foam::interpolation2DTable<Type>::operator()" "(" "const scalar, " "const scalar" ") const" ) << "cannot interpolate a zero-sized table - returning zero" << endl; return pTraits<Type>::zero; } else if (nX == 1) { // only 1 column (in X) - interpolate to find Y value return interpolateValue(t.first().second(), valueY); } else { // have 2-D data, interpolate // find low and high indices in the X range that bound valueX label x0i = Xi(lessOp<scalar>(), valueX, false); label x1i = Xi(greaterOp<scalar>(), valueX, true); if (x0i == x1i) { return interpolateValue(t[x0i].second(), valueY); } else { Type y0(interpolateValue(t[x0i].second(), valueY)); Type y1(interpolateValue(t[x1i].second(), valueY)); // gradient in X scalar x0 = t[x0i].first(); scalar x1 = t[x1i].first(); Type mX = (y1 - y0)/(x1 - x0); // interpolate return y0 + mX*(valueX - x0); } } }
line2 line2::interpolate(line2 const& l, double fraction) const { return line2( denormalize(fraction, x1(), l.x1()), denormalize(fraction, y1(), l.y1()), denormalize(fraction, x2(), l.x2()), denormalize(fraction, y2(), l.y2()) ); }
ExecStatus MultPlusDom<VA,VB,VC>::propagate(Space& home, const ModEventDelta& med) { if (VA::me(med) != ME_INT_DOM) { GECODE_ES_CHECK((prop_mult_plus_bnd<VA,VB,VC>(home,*this,x0,x1,x2))); return home.ES_FIX_PARTIAL(*this,VA::med(ME_INT_DOM)); } IntView y0(x0.varimp()), y1(x1.varimp()), y2(x2.varimp()); return prop_mult_dom<IntView>(home,*this,y0,y1,y2); }
void test_rat2( void ) { NUPrecRational x1(10.0), y1(10.0), x2(20.0), y2(20.0), y(15.0), c; double n,d; c = x1 + (y-y1)*(x2-x1)/(y2-y1); c.Dump(&n,&d); printf( "%f/%f\n", n, d ); }
float G77_besy1_0 (const real * x) { #if defined(BUILD_OS_DARWIN) return (float) y1 ((double) *x); #else /* defined(BUILD_OS_DARWIN) */ return y1f (*x); #endif /* defined(BUILD_OS_DARWIN) */ }
void MainWindow::showMes(QList<Measure> * measures) { // Item * item=(Item *)params; ui->lcd_pulse_0->display(measures->at(0).angle); ui->lcd_pulse_4->display(measures->at(0).angle); ui->lcd_pulse_8->display(measures->at(0).angle); ui->lcd_pulse_12->display(measures->at(0).angle); ui->lcd_pulse_16->display(measures->at(0).angle); ui->lcd_pulse_20->display(measures->at(0).angle); ui->lcd_pulse_24->display(measures->at(0).angle); ui->lcd_pulse_28->display(measures->at(0).angle); customPlot=ui->widget; QVector<double> x(101), y(101); // initialize with entries 0..100 QVector<double> x1(101), y1(101); for(int i=0; i<8; i++) { x1[i] = 0; y1[i] = 0; x[i] = 0; y[i] = 0; customPlot->graph(1)->setData(x1, y1); customPlot->graph(0)->setData(x, y); } int pulse=0; int i=0; while(measures->at(i).angle!=0) { x[i]=pulse; y[i]=measures->at(i).angle; i++; pulse+=4; } customPlot->graph(0)->setData(x, y); /* if(item->approx[0].angle!=0) { for (int i=0; i<8; ++i) { x1[i] = i*4; y1[i] = item->approx[i].angle; } customPlot->graph(1)->setData(x1, y1); } */ /* customPlot->yAxis->setRange(item->measures[0].angle, item->measures[0].angle+550); ui->widget->replot(); */ }
void CustomPlotRegression::setupQuadraticDemo(double * kernely, int size_kernely, double * kernelx, int size_kernelx ) { QCustomPlot* customPlot=m_CustomPlot; // make top right axes clones of bottom left axes: // generate some data: QVector<double> x1( 0 ), y1( 0 ); // initialize with entries 0..100 customPlot->addGraph(); customPlot->graph( 0 )->setPen( QPen( Qt::red ) ); //customPlot->graph( 0 )->setSelectedPen( QPen( Qt::blue, 2 ) ); // customPlot->graph( 0 )->setData( x1, y1 ); QVector<double> x; QVector<double> y; //std::cout << "****************************************************************+++" <<endl; double maxx= DBL_MIN; double maxy= DBL_MIN; for (int i = 0; i < size_kernelx; i++) { // std::cout << kernel[i] << endl; x.push_back(kernelx[i]); y.push_back(kernely[i]); if(kernelx[i] > maxx){ maxx=kernelx[i]; } if(kernely[i] > maxy){ maxy=kernely[i]; } } m_CustomPlot->graph( 0 )->setData( x, y); // std::cout << "ok" << endl; customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 10)); customPlot->addGraph(); customPlot->graph( 1 )->setPen( QPen( Qt::green ) ); //customPlot->graph( 1 )->setSelectedPen( QPen( Qt::blue, 2 ) ); // customPlot->graph( 1 )->setData( x1, y1 ); customPlot->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 10)); // give the axes some labels: customPlot->xAxis->setLabel( "Generation" ); customPlot->yAxis->setLabel( "Fitness" ); // set axes ranges, so we see all data: customPlot->xAxis->setRange( 0, maxx ); customPlot->yAxis->setRange( 0, maxy); customPlot ->setInteractions( QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables ); connect( customPlot, SIGNAL( plottableClick( QCPAbstractPlottable*, QMouseEvent* ) ), this, SLOT( graphClicked( QCPAbstractPlottable* ) ) ); for (int i = 0; i < number_of_function; ++i) { customPlot->addGraph(); } }
void main() { double x, y, z; x = j0( 2.4 ); y = y1( 1.58 ); z = jn( 3, 2.4 ); printf( "j0(2.4) = %f, y1(1.58) = %f\n", x, y ); printf( "jn(3,2.4) = %f\n", z ); }
inline complex<typename boost::tr1_detail::largest_real<T, U>::type> pow(const complex<T>& x, const complex<U>& y) { typedef complex<typename boost::tr1_detail::largest_real<T, U>::type> result_type; typedef typename boost::mpl::if_<boost::is_same<result_type, complex<T> >, result_type const&, result_type>::type cast1_type; typedef typename boost::mpl::if_<boost::is_same<result_type, complex<U> >, result_type const&, result_type>::type cast2_type; cast1_type x1(x); cast2_type y1(y); return std::pow(x1, y1); }
inline complex<typename boost::tr1_detail::promote_to_real<T, U>::type> pow (const T& x, const complex<U>& y) { typedef typename boost::tr1_detail::promote_to_real<T, U>::type real_type; typedef complex<typename boost::tr1_detail::promote_to_real<T, U>::type> result_type; typedef typename boost::mpl::if_<boost::is_same<result_type, complex<U> >, result_type const&, result_type>::type cast_type; real_type r = x; std::complex<real_type> x1(r); cast_type y1(y); return std::pow(x1, y1); }