Пример #1
0
void AnalogLowPass::design (int numPoles,
                            WorkspaceBase* w)
{
  if (m_numPoles != numPoles)
  {
    m_numPoles = numPoles;

    reset ();

    RootFinderBase& solver (w->roots);
    for (int i = 0; i < numPoles + 1; ++i)
      solver.coef()[i] = reversebessel (i, numPoles);
    solver.solve (numPoles);

    const int pairs = numPoles / 2;
    for (int i = 0; i < pairs; ++i)
    {
      complex_t c = solver.root()[i];
      addPoleZeroConjugatePairs (c, infinity());
    }

    if (numPoles & 1)
      add (solver.root()[pairs].real(), infinity());
  }
}
Пример #2
0
bool Master::feasibleFound() const
{
	if (optSense_.max()) {
		return primalBound_ > -infinity();
	}
	else {
		return primalBound_ <  infinity();
	}
}
Пример #3
0
void Master::printGuarantee() const // warning: this should only be called if it has already been ensured that logging allows this output!
{
	double lb = lowerBound();
	double ub = upperBound();

	if (lb == -infinity() || ub == infinity() ||
		((fabs(lb) < machineEps()) && (fabs(ub) > machineEps())))
		Logger::ifout() << "---";
	else
		Logger::ifout() << guarantee() << '%';
}
Пример #4
0
/** Returns a Numeric object which is the difference of this and
   * other */
Numeric::Ptr ATFloatOrDerivedImpl::subtract(const Numeric::Ptr &other, const DynamicContext* context) const {
  if(other->getPrimitiveTypeIndex() == AnyAtomicType::DECIMAL) {
    // if other is a decimal, promote it to xs:float
    return this->subtract((const Numeric::Ptr )other->castAs(this->getPrimitiveTypeIndex(), context), context);
  } else if (other->getPrimitiveTypeIndex() == AnyAtomicType::DOUBLE) {
    // if other is a double, promote this to xs:double
    return ((const Numeric::Ptr )this->castAs(other->getPrimitiveTypeIndex(), context))->subtract(other, context);
  } else if (other->getPrimitiveTypeIndex() == AnyAtomicType::FLOAT) {
    // same primitive type, can make comparison
    ATFloatOrDerivedImpl* otherImpl = (ATFloatOrDerivedImpl*)(const Numeric*)other;
    if(otherImpl->_state == NaN) return notANumber(context);

    switch (_state) {
      case NaN: return notANumber(context);
      case INF: {
        switch(otherImpl->_state) {
          case NaN: return notANumber(context);   // case taken care of above
          case NEG_NUM:
          case NUM: return infinity(context);     // INF - NUM = INF
          case INF: return notANumber(context);   // INF - INF = NaN
          case NEG_INF: return infinity(context); // INF - (-INF) = INF
          default: assert(false); return 0; // should never get here
        }
      }
      case NEG_INF: {
        switch(otherImpl->_state) {
          case NaN: return notANumber(context);          //case taken care of above
          case NEG_NUM:
          case NUM: return negInfinity(context);         // -INF - NUM = -INF
          case INF: return negInfinity(context);         // -INF - INF = -INF
          case NEG_INF: return notANumber(context);      // -INF - (-INF) = NaN
          default: assert(false); return 0; // should never get here
        }
      }                
      case NEG_NUM:
      case NUM: {
        switch(otherImpl->_state) {
          case NaN: return notANumber(context);          // case taken care of above
          case INF: return negInfinity(context);         // NUM - INF = -INF
          case NEG_INF: return infinity(context);        // NUM - (-INF) = INF
          case NEG_NUM:
          case NUM: return newFloat(_float - otherImpl->_float, context);
          default: assert(false); return 0;  // should never get here
        }
      }
      default: assert(false); return 0;  // should never get here
    } 
  } else {
    assert(false); // should never get here, numeric types are xs:decimal, xs:float, xs:integer and xs:double
    return 0;
  }
}
Пример #5
0
void AnalogLowPass::design (int numPoles,
                            double stopBandDb)
{
  if (m_numPoles != numPoles ||
      m_stopBandDb != stopBandDb)
  {
    m_numPoles = numPoles;
    m_stopBandDb = stopBandDb;

    reset ();

    const double eps = std::sqrt (1. / (std::exp (stopBandDb * 0.1 * doubleLn10) - 1));
    const double v0 = asinh (1 / eps) / numPoles;
    const double sinh_v0 = -sinh (v0);
    const double cosh_v0 = cosh (v0);
    const double fn = doublePi / (2 * numPoles);

    int k = 1;
    for (int i = numPoles / 2; --i >= 0; k+=2)
    {
      const double a = sinh_v0 * cos ((k - numPoles) * fn);
      const double b = cosh_v0 * sin ((k - numPoles) * fn);
      const double d2 = a * a + b * b;
      const double im = 1 / cos (k * fn);
      addPoleZeroConjugatePairs (complex_t (a / d2, b / d2),
                                       complex_t (0, im));
    }

    if (numPoles & 1)
    {
      add (1 / sinh_v0, infinity());
    }
  }
}
Пример #6
0
ComplexPair BandPassTransform::transform (complex_t c)
{
  if (c == infinity())
    return ComplexPair (-1, 1);

  c = (1. + c) / (1. - c); // bilinear

  complex_t v = 0;
  v = addmul (v, 4 * (b2 * (a2 - 1) + 1), c);
  v += 8 * (b2 * (a2 - 1) - 1);
  v *= c;
  v += 4 * (b2 * (a2 - 1) + 1);
  v = std::sqrt (v);

  complex_t u = -v;
  u = addmul (u, ab_2, c);
  u += ab_2;

  v = addmul (v, ab_2, c);
  v += ab_2;

  complex_t d = 0;
  d = addmul (d, 2 * (b - 1), c) + 2 * (1 + b);

  return ComplexPair (u/d, v/d);
}
Пример #7
0
ComplexPair BandStopTransform::transform (complex_t c)
{
  if (c == infinity())
    c = -1;
  else
    c = (1. + c) / (1. - c); // bilinear

  complex_t u (0);
  u = addmul (u, 4 * (b2 + a2 - 1), c);
  u += 8 * (b2 - a2 + 1);
  u *= c;
  u += 4 * (a2 + b2 - 1);
  u = std::sqrt (u);

  complex_t v = u * -.5;
  v += a;
  v = addmul (v, -a, c);

  u *= .5;
  u += a;
  u = addmul (u, -a, c);
  
  complex_t d (b + 1);
  d = addmul (d, b-1, c);

  return ComplexPair (u/d, v/d);
}
Пример #8
0
// return distance between line of two points and center
double distance( const QgsPoint& p1, const QgsPoint& p2, const QgsPoint& p, QgsPoint& center )
{

  // first line
  double A1, B1, C1;
  A1 = p1.y() - p2.y();
  B1 = p2.x() - p1.x();
  C1 = p1.x() * ( -A1 ) + p1.y() * ( -B1 );

  // second line. First and second line is perpendicular.
  double A2, B2, C2;
  A2 = B1;
  B2 = -A1;
  C2 = -p.x() * A2 - p.y() * B2;

  // union point
  double x, y, det;
  det = A1 * B2 - B1 * A2;
  x = ( C2 * B1 - B2 * C1 ) / det;
  y = ( -A1 * C2 + C1 * A2 ) / det;

  center = QgsPoint( x, y );

  det = sqrt( A1 * A1 + B1 * B1 );
  A1 /= det;
  B1 /= det;
  C1 /= det;
  if ( std::min( p1.x(), p2.x() ) <= x && std::max( p1.x(), p2.x() ) >= x &&
       std::min( p1.y(), p2.y() ) <= y && std::max( p1.y(), p2.y() ) >= y )
    return std::abs( A1*p.x() + B1*p.y() + C1 );

  return infinity();
}// RoadGraphPlugin::distance()
Пример #9
0
	void FlexibleTimeMeasurement::setBoundaryValues(
			    double minValue,
			    double maxValue) {

		if (minValue > maxValue)
			minValue = maxValue;

		if (minValue < 0)
			minimumValue = 0;

		else if (!isNaN(expectedValue)
			    && minValue > TimeMeasurement::expectedValue)

			minimumValue = expectedValue;
		else
			minimumValue = minValue;

		if (maxValue < 0)
			maximumValue = infinity();

		else if ((!isNaN(
			    TimeMeasurement::expectedValue)) &&
				(maxValue < TimeMeasurement::expectedValue))

			maximumValue = expectedValue;
		else
			maximumValue = maxValue;
	}
Пример #10
0
 ArPosteriorSampler::ArPosteriorSampler(
     ArModel *model, Ptr<GammaModelBase> siginv_prior)
       : model_(model),
         siginv_prior_(siginv_prior),
         max_number_of_regression_proposals_(3),
         upper_sigma_truncation_point_(infinity())
   {}
Пример #11
0
Numeric::Ptr ATFloatOrDerivedImpl::abs(const DynamicContext* context) const {
    switch (_state) {
    case NaN:
        return this;
    case INF:
        return infinity(context);
    case NEG_INF:
        return infinity(context);
    case NEG_NUM:
    case NUM:
        return newFloat(_float.abs(), context);
    default:
        assert(false);
        return 0;  // should never get here
    }
}
Пример #12
0
double GlobalLpNorm(const double p, double loc_norm, MPI_Comm comm)
{
   double glob_norm;

   if (p < infinity())
   {
      // negative quadrature weights may cause the error to be negative
      if (loc_norm < 0.0)
      {
         loc_norm = -pow(-loc_norm, p);
      }
      else
      {
         loc_norm = pow(loc_norm, p);
      }

      MPI_Allreduce(&loc_norm, &glob_norm, 1, MPI_DOUBLE, MPI_SUM, comm);

      if (glob_norm < 0.0)
      {
         glob_norm = -pow(-glob_norm, 1.0/p);
      }
      else
      {
         glob_norm = pow(glob_norm, 1.0/p);
      }
   }
   else
   {
      MPI_Allreduce(&loc_norm, &glob_norm, 1, MPI_DOUBLE, MPI_MAX, comm);
   }

   return glob_norm;
}
	double LinearCostFunctionDuration::getStretchingCostRate() {
		if (maximumValue == infinity())
			return ((LinearTimeCostFunction*)CostFunctionDuration::
				    costFunction)->getMaxStretchingCost();
		else
			return ((LinearTimeCostFunction*)CostFunctionDuration::
				    costFunction)->getMaxStretchingCost() /
				    (maximumValue - expectedValue);
	}
Пример #14
0
namespace interfaces {
	//if the representation changes, update isObjectDuration method
	const double IntervalAnchor::OBJECT_DURATION = infinity();

	IntervalAnchor::IntervalAnchor(string id, double begin, double end)
		    : ContentAnchor(id) {

		typeSet.insert("IntervalAnchor");
		this->begin = 0;
		setEnd(end);
		setBegin(begin);
	}

	double IntervalAnchor::getBegin() {
		return begin;
	}

	double IntervalAnchor::getEnd() {
		return end;
	}

	void IntervalAnchor::setBegin(double b) {
		if (b < 0 && !isObjectDuration(b)) {
			begin = 0;

		} else if ((!isObjectDuration(b) &&
				!isObjectDuration(end) && b > end) ||
				(isObjectDuration(b) &&
				!isObjectDuration(end))) {

			begin = end;

		} else {
			begin = b;
		}
	}

	void IntervalAnchor::setEnd(double e) {
		if (e < 0 && !isObjectDuration(e)) {
			end = IntervalAnchor::OBJECT_DURATION;

		} else if ((!isObjectDuration(e) &&
				!isObjectDuration(begin) && e < begin)) {

			end = begin;

		} else {
			end = e;
		}
	}

	bool IntervalAnchor::isObjectDuration(double value) {
		return isInfinity(value);
	}
}
Пример #15
0
void AnalogLowPass::design (int numPoles,
                            WorkspaceBase* w)
{
  if (m_numPoles != numPoles)
  {
    m_numPoles = numPoles;

    reset ();

    PolynomialFinderBase& poly (w->poly);
    RootFinderBase& poles (w->roots);

    poly.solve (numPoles);
    int degree = numPoles * 2;

    poles.coef()[0] = 1 + poly.coef()[0];
    poles.coef()[1] = 0;
    for (int i = 1; i <= degree; ++i)
    {
      poles.coef()[2*i] = poly.coef()[i] * ((i & 1) ? -1 : 1);
      poles.coef()[2*i+1] = 0;
    }
    poles.solve (degree);

    int j = 0;
    for (int i = 0; i < degree; ++i)
      if (poles.root()[i].real() <= 0)
        poles.root()[j++] = poles.root()[i];
    // sort descending imag() and cut degree in half
    poles.sort (degree/2);

    const int pairs = numPoles / 2;
    for (int i = 0; i < pairs; ++i)
    {
      complex_t c = poles.root()[i];
      addPoleZeroConjugatePairs (c, infinity());
    }

    if (numPoles & 1)
      add (poles.root()[pairs].real(), infinity());
  }
}
Пример #16
0
void AnalogLowPass::design (int numPoles)
{
  if (m_numPoles != numPoles)
  {
    m_numPoles = numPoles;

    reset ();

    const double n2 = 2 * numPoles;
    const int pairs = numPoles / 2;
    for (int i = 0; i < pairs; ++i)
    {
      complex_t c = std::polar (1., doublePi_2 + (2 * i + 1) * doublePi / n2);
      addPoleZeroConjugatePairs (c, infinity());
    }

    if (numPoles & 1)
      add (-1, infinity());
  }
}
Пример #17
0
complex_t HighPassTransform::transform (complex_t c)
{
  if (c == infinity())
    return complex_t (1, 0);

  // frequency transform
  c = f * c; 

  // bilinear high pass transform
  return - (1. + c) / (1. - c);
}
Пример #18
0
complex_t LowPassTransform::transform (complex_t c)
{
  if (c == infinity())
    return complex_t (-1, 0);

  // frequency transform
  c = f * c; 
  
  // bilinear low pass transform
  return (1. + c) / (1. - c);
}
Пример #19
0
void MinCostFlowReinelt::start(Array<int> &supply)
{
	/*----------------------------------------------------------------------*/
	/*     determine intial basis tree and initialize data structure        */
	/*----------------------------------------------------------------------*/

	/* initialize artificial root node */
	root->father = root;
	root->successor = &nodes[1];
	root->arc_id = NULL;
	root->orientation = false;
	root->dual = 0;
	root->flow = 0;
	root->nr_of_nodes = nn + 1;
	root->last = &nodes[nn];
	root->name = nn + 1;
	// artificials = nn; moved to mcf() [CG]
	int highCost = 1 + (nn+1) * m_maxCost;

	for (int i = 1; i <= nn; i++)
	{   /* for every node an artificial arc is created */
		arctype *ep = OGDF_NEW arctype;
		if (supply[i - 1] >= 0) {
			ep->tail = &nodes[i];
			ep->head = root;
		} else {
			ep->tail = root;
			ep->head = &nodes[i];
		}
		ep->cost = highCost;
		ep->upper_bound = infinity();
		ep->arcnum = mm + i - 1;
		ep->next_arc = start_b;
		start_b = ep;
		nodes[i].father = root;
		if (i < nn)
			nodes[i].successor = &nodes[i+1];
		else
			nodes[i].successor = root;
		if (supply[i - 1] < 0) {
			nodes[i].orientation = false;
			nodes[i].dual = -highCost;
		} else {
			nodes[i].orientation = true;
			nodes[i].dual = highCost;
		}
		nodes[i].flow = abs(supply[i - 1]);
		nodes[i].nr_of_nodes = 1;
		nodes[i].last = &nodes[i];
		nodes[i].arc_id = ep;
	}  /* for i */
	start_n1 = start_arc;
}  /*start*/
Пример #20
0
void AnalogLowPass::design(int numPoles,
                           double rippleDb)
{
    if (m_numPoles != numPoles ||
        m_rippleDb != rippleDb)
    {
        m_numPoles = numPoles;
        m_rippleDb = rippleDb;

        reset();

        const double eps = std::sqrt(1. / std::exp(-rippleDb * 0.1 * doubleLn10) - 1);
        const double v0 = asinh(1 / eps) / numPoles;
        const double sinh_v0 = -sinh(v0);
        const double cosh_v0 = cosh(v0);

        const double n2 = 2 * numPoles;
        const int pairs = numPoles / 2;
        for (int i = 0; i < pairs; ++i)
        {
            const int k = 2 * i + 1 - numPoles;
            double a = sinh_v0 * cos(k * doublePi / n2);
            double b = cosh_v0 * sin(k * doublePi / n2);

            //addPoleZero (complex_t (a, b), infinity());
            //addPoleZero (complex_t (a, -b), infinity());
            addPoleZeroConjugatePairs(complex_t (a, b), infinity());
        }

        if (numPoles & 1)
        {
            add(complex_t (sinh_v0, 0), infinity());
            setNormal(0, 1);
        }
        else
        {
            setNormal(0, pow(10, -rippleDb/20.));
        }
    }
}
Пример #21
0
void print_limits (std::ostream &strm, const char *tname, T)
{
#define PRINT_MEMBER(type, member)                     \
    strm << "    static " << type << " " #member " = "            \
         << std::numeric_limits<T>::member << ";\n"

    strm << "struct std::numeric_limits<" << tname << "> {\n";

    PRINT_MEMBER ("const bool", is_specialized);

    PRINT_MEMBER (tname, min ());
    PRINT_MEMBER (tname, max ());

    PRINT_MEMBER ("const int", digits);
    PRINT_MEMBER ("const int", digits10);

    PRINT_MEMBER ("const bool", is_signed);
    PRINT_MEMBER ("const bool", is_integer);
    PRINT_MEMBER ("const bool", is_exact);
    PRINT_MEMBER ("const int", radix);

    PRINT_MEMBER (tname, epsilon ());
    PRINT_MEMBER ("int", round_error ());

    PRINT_MEMBER ("const int", min_exponent);
    PRINT_MEMBER ("const int", min_exponent10);
    PRINT_MEMBER ("const int", max_exponent);
    PRINT_MEMBER ("const int", max_exponent10);

    PRINT_MEMBER ("const bool", has_infinity);
    PRINT_MEMBER ("const bool", has_quiet_NaN);
    PRINT_MEMBER ("const bool", has_signaling_NaN);
    PRINT_MEMBER ("const std::float_denorm_style", has_denorm);

    PRINT_MEMBER ("const bool", has_denorm_loss);

    PRINT_MEMBER (tname, infinity ());
    PRINT_MEMBER (tname, quiet_NaN ());
    PRINT_MEMBER (tname, signaling_NaN ());
    PRINT_MEMBER (tname, denorm_min ());

    PRINT_MEMBER ("const bool", is_iec559);
    PRINT_MEMBER ("const bool", is_bounded);
    PRINT_MEMBER ("const bool", is_modulo);

    PRINT_MEMBER ("const bool", traps);
    PRINT_MEMBER ("const bool", tinyness_before);

    PRINT_MEMBER ("const int", round_style);

    strm << "};\n";
}
Пример #22
0
    static float signaling_NaN () {

#if defined (FLT_SNAN)
        return FLT_SNAN;
#elif defined (_RWSTD_NO_DBL_TRAPS)

        union {
            float val;
            char bits [sizeof (float)];
        } snan;

        snan.val = infinity ();

#  ifdef __hpux

        if (big_endian) {
            snan.bits [sizeof snan.val - 2] = '\xc0';
        }
        else {
            snan.bits [1] = '\xc0';
        }

#  else   // if !defined (__hpux)

        // convert infinity into a signaling NAN
        // (toggle any bit in signifcand)
        if (big_endian) {
            snan.bits [sizeof snan.val - 1] |= 1;
        }
        else {
            snan.bits [0] |= 1;
        }

#  endif   // __hpux

        return snan.val;

#else

        const union {
            char bits [sizeof (float)];
            float val;
        } val = {
            _RWSTD_FLT_SNAN_BITS
        };
            
        return val.val;

#endif

    }
 double GenericGaussianVarianceSampler::draw(
     RNG &rng,
     double data_df,
     double data_ss) const {
   double DF = data_df + 2 * prior_->alpha();
   double SS = data_ss + 2 * prior_->beta();
   if (sigma_max_ == 0.0) {
     return 0.0;
   } else if(sigma_max_ == infinity()){
     return 1.0 / rgamma_mt(rng, DF/2, SS/2);
   } else {
     return 1.0 / rtrun_gamma_mt(rng, DF/2, SS/2, 1.0/square(sigma_max_));
   }
 }
Пример #24
0
/** Returns the floor of this Numeric */
Numeric::Ptr ATFloatOrDerivedImpl::floor(const DynamicContext* context) const {
  switch (_state) {
    case NaN: return notANumber(context);
    case INF: return infinity(context);
    case NEG_INF: return negInfinity(context);
    case NEG_NUM:
    case NUM: { 
      if (isZero() && isNegative())
        return negZero(context);
      return newFloat(_float.floor(), context); 
    }
    default: { assert(false); return 0; // should never get here 
    }
  }
}
Пример #25
0
static DecimalFormatSymbols* makeDecimalFormatSymbols(JNIEnv* env,
        jstring currencySymbol0, jchar decimalSeparator, jchar digit,
        jstring exponentSeparator0, jchar groupingSeparator0,
        jstring infinity0, jstring internationalCurrencySymbol0,
        jchar minusSign, jchar monetaryDecimalSeparator, jstring nan0,
        jchar patternSeparator, jchar percent, jchar perMill, jchar zeroDigit) {
    ScopedJavaUnicodeString currencySymbol(env, currencySymbol0);
    ScopedJavaUnicodeString exponentSeparator(env, exponentSeparator0);
    ScopedJavaUnicodeString infinity(env, infinity0);
    ScopedJavaUnicodeString internationalCurrencySymbol(env,
            internationalCurrencySymbol0);
    ScopedJavaUnicodeString nan(env, nan0);
    UnicodeString groupingSeparator(groupingSeparator0);

    DecimalFormatSymbols* result = new DecimalFormatSymbols;
    result->setSymbol(DecimalFormatSymbols::kCurrencySymbol,
                      currencySymbol.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol,
                      UnicodeString(decimalSeparator));
    result->setSymbol(DecimalFormatSymbols::kDigitSymbol, UnicodeString(digit));
    result->setSymbol(DecimalFormatSymbols::kExponentialSymbol,
                      exponentSeparator.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol,
                      groupingSeparator);
    result->setSymbol(DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol,
                      groupingSeparator);
    result->setSymbol(DecimalFormatSymbols::kInfinitySymbol,
                      infinity.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol,
                      internationalCurrencySymbol.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kMinusSignSymbol,
                      UnicodeString(minusSign));
    result->setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol,
                      UnicodeString(monetaryDecimalSeparator));
    result->setSymbol(DecimalFormatSymbols::kNaNSymbol, nan.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol,
                      UnicodeString(patternSeparator));
    result->setSymbol(DecimalFormatSymbols::kPercentSymbol,
                      UnicodeString(percent));
    result->setSymbol(DecimalFormatSymbols::kPerMillSymbol,
                      UnicodeString(perMill));
    result->setSymbol(DecimalFormatSymbols::kZeroDigitSymbol,
                      UnicodeString(zeroDigit));
    return result;
}
Пример #26
0
/** Rounds this Numeric to the given precision, and rounds a half to even */
Numeric::Ptr ATFloatOrDerivedImpl::roundHalfToEven(const Numeric::Ptr &precision, const DynamicContext* context) const {
    switch (_state) {
    case NaN:
        return notANumber(context);
    case INF:
        return infinity(context);
    case NEG_INF:
        return negInfinity(context);
    case NEG_NUM:
    case NUM:
        break;
    default: {
        assert(false);
        return 0; // should never get here
    }
    }

    if (isZero() && isNegative())
        return this;

    ATFloatOrDerived::Ptr float_precision = (const Numeric::Ptr)precision->castAs(this->getPrimitiveTypeIndex(), context);
    MAPM exp = MAPM(10).pow(((ATFloatOrDerivedImpl*)(const ATFloatOrDerived*)float_precision)->_float);
    MAPM value = _float * exp;
    bool halfVal = false;

    // check if we're rounding on a half value
    if((value-0.5) == (value.floor())) {
        halfVal = true;
    }
    value = _float * exp + 0.5;
    value = value.floor();

    // if halfVal make sure what we return has the least significant digit even
    if (halfVal) {
        if(value.is_odd()) {
            value = value - 1;
        }
    }
    value = value / exp;

    // the spec doesn't actually say to do this, but djf believes this is the correct way to handle rounding of -ve values which will result in 0.0E0
    // if (value == 0 && isNegative())
    // return negZero(context);
    return newFloat(value, context);
}
Пример #27
0
/** Returns the Additive inverse of this Numeric */
Numeric::Ptr ATFloatOrDerivedImpl::invert(const DynamicContext* context) const {
  switch (_state) {
    case NaN: return this;
    case INF: return negInfinity(context);
    case NEG_INF: return infinity(context);
    case NEG_NUM:
    case NUM: 
        if(this->isZero())
        {
          if(this->isNegative())
            return newFloat(0, context);
          else
            return negZero(context);
        }
        return newFloat(_float.neg(), context);
    default: assert(false); return 0;  // should never get here
  }
}
static DecimalFormatSymbols* makeDecimalFormatSymbols(JNIEnv* env,
        jstring currencySymbol0, jchar decimalSeparator, jchar digit, jstring exponentSeparator0,
        jchar groupingSeparator0, jstring infinity0,
        jstring internationalCurrencySymbol0, jstring minusSign0,
        jchar monetaryDecimalSeparator, jstring nan0, jchar patternSeparator,
        jstring percent0, jchar perMill, jchar zeroDigit) {
    ScopedJavaUnicodeString currencySymbol(env, currencySymbol0);
    ScopedJavaUnicodeString exponentSeparator(env, exponentSeparator0);
    ScopedJavaUnicodeString infinity(env, infinity0);
    ScopedJavaUnicodeString internationalCurrencySymbol(env, internationalCurrencySymbol0);
    ScopedJavaUnicodeString nan(env, nan0);
    ScopedJavaUnicodeString minusSign(env, minusSign0);
    ScopedJavaUnicodeString percent(env, percent0);
    UnicodeString groupingSeparator(groupingSeparator0);

    DecimalFormatSymbols* result = new DecimalFormatSymbols;
    result->setSymbol(DecimalFormatSymbols::kCurrencySymbol, currencySymbol.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, UnicodeString(decimalSeparator));
    result->setSymbol(DecimalFormatSymbols::kDigitSymbol, UnicodeString(digit));
    result->setSymbol(DecimalFormatSymbols::kExponentialSymbol, exponentSeparator.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol, groupingSeparator);
    result->setSymbol(DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol, groupingSeparator);
    result->setSymbol(DecimalFormatSymbols::kInfinitySymbol, infinity.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, internationalCurrencySymbol.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kMinusSignSymbol, minusSign.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol, UnicodeString(monetaryDecimalSeparator));
    result->setSymbol(DecimalFormatSymbols::kNaNSymbol, nan.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol, UnicodeString(patternSeparator));
    result->setSymbol(DecimalFormatSymbols::kPercentSymbol, percent.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kPerMillSymbol, UnicodeString(perMill));
    // java.text.DecimalFormatSymbols just uses a zero digit,
    // but ICU >= 4.6 has a field for each decimal digit.
    result->setSymbol(DecimalFormatSymbols::kZeroDigitSymbol, UnicodeString(zeroDigit + 0));
    result->setSymbol(DecimalFormatSymbols::kOneDigitSymbol, UnicodeString(zeroDigit + 1));
    result->setSymbol(DecimalFormatSymbols::kTwoDigitSymbol, UnicodeString(zeroDigit + 2));
    result->setSymbol(DecimalFormatSymbols::kThreeDigitSymbol, UnicodeString(zeroDigit + 3));
    result->setSymbol(DecimalFormatSymbols::kFourDigitSymbol, UnicodeString(zeroDigit + 4));
    result->setSymbol(DecimalFormatSymbols::kFiveDigitSymbol, UnicodeString(zeroDigit + 5));
    result->setSymbol(DecimalFormatSymbols::kSixDigitSymbol, UnicodeString(zeroDigit + 6));
    result->setSymbol(DecimalFormatSymbols::kSevenDigitSymbol, UnicodeString(zeroDigit + 7));
    result->setSymbol(DecimalFormatSymbols::kEightDigitSymbol, UnicodeString(zeroDigit + 8));
    result->setSymbol(DecimalFormatSymbols::kNineDigitSymbol, UnicodeString(zeroDigit + 9));
    return result;
}
Пример #29
0
int main()
{
    double z = 1.0;

    cout << "Some inquiries into the nature of double:" << endl
         << "digits(z) = " << digits(z) << endl
         << "epsilon(z) = " << epsilon(z) << endl
         << "huge(z) = " << huge(z) << endl
         << "tiny(z) = " << tiny(z) << endl
         << "max_exponent(z) = " << max_exponent(z) << endl
         << "min_exponent(z) = " << min_exponent(z) << endl
         << "max_exponent10(z) = " << max_exponent10(z) << endl
         << "min_exponent10(z) = " << min_exponent10(z) << endl
         << "precision(z) = " << precision(z) << endl
         << "radix(z) = " << radix(z) << endl;

    Range r = range(z);
    cout << "range(z) = [ " << r.first() << ", " << r.last() << " ]"
         << endl;

    cout << endl << "More obscure properties:" << endl
         << "is_signed(z) = " << is_signed(z) << endl
         << "is_integer(z) = " << is_integer(z) << endl
         << "is_exact(z) = " << is_exact(z) << endl
         << "round_error(z) = " << round_error(z) << endl
         << "has_infinity(z) = " << has_infinity(z) << endl
         << "has_quiet_NaN(z) = " << has_quiet_NaN(z) << endl
         << "has_signaling_NaN(z) = " << has_signaling_NaN(z) << endl
         << "has_denorm(z) = " << has_denorm(z) << endl
         << "has_denorm_loss(z) = " << has_denorm_loss(z) << endl
         << "infinity(z) = " << infinity(z) << endl
         << "quiet_NaN(z) = " << quiet_NaN(z) << endl
         << "signaling_NaN(z) = " << signaling_NaN(z) << endl
         << "denorm_min(z) = " << denorm_min(z) << endl
         << "is_iec559(z) = " << is_iec559(z) << endl
         << "is_bounded(z) = " << is_bounded(z) << endl
         << "is_modulo(z) = " << is_modulo(z) << endl
         << "traps(z) = " << traps(z) << endl
         << "tinyness_before(z) = " << tinyness_before(z) << endl;

    return 0;
}
Пример #30
0
    //------------------------------------------------------------------------------
    float Cmath::acoshf( float x ) // wrapper acoshf
    {
        float z;
        struct fexception exc;
        z = __ieee754_acoshf( x );
        if( m_fdlib_version == _IEEE_ || isnanf( x ) )
        {
            return z;
        }
        if( x < (float)1.0 )
        {
            // acoshf(x<1)
            exc.type = EX_DOMAIN;
            exc.name = "acoshf";
            exc.err = 0;
            exc.arg1 = exc.arg2 = (double)x;
            exc.retval = infinity();
            if( m_fdlib_version == _POSIX_ )
            {
                errno = EDOM;
            }
            else if( !matherr( &exc ) )
            {
                errno = EDOM;
            }

            if( exc.err != 0 )
            {
                errno = exc.err;
            }
            return (float)exc.retval;
        }
        else
        {
            return z;
        }
    }