示例#1
0
文件: Range.cpp 项目: nhauser/cdma
//---------------------------------------------------------------------------
// Range::unionRanges
//---------------------------------------------------------------------------
RangePtr Range::unionRanges(const Range& r) throw ( Exception )
{
  if( r.stride() != m_stride ) 
  {
    THROW_INVALID_RANGE("Stride must identical to make a Range union!", "Range::unionRanges");
  }

  if (this->length() == 0) 
  {
    return RangePtr(new Range(r));
  }

  if (r.length() == 0) 
  {
    return RangePtr(new Range(* this));
  }

  long first, last;
  std::string name = m_name;

  // Seek the smallest value
  first = m_first < r.first() ? m_first : r.first();
  last  = m_last > r.last() ? m_last : r.last();

  return RangePtr(new Range(name, first, last, m_stride));
}
示例#2
0
文件: Range.cpp 项目: nhauser/cdma
//---------------------------------------------------------------------------
// Range::intersect
//---------------------------------------------------------------------------
RangePtr Range::intersect(const Range& r) throw ( Exception )
{
  if ((length() == 0) || (r.length() == 0))
  {
    return  RangePtr ( new Range());
  }

  long last = this->last() > r.last() ? r.last() : this->last();
  long stride = this->stride() * r.stride();
  long useFirst;
  if (stride == 1)
  {
    useFirst = this->first() > r.first() ? this->first() : r.first();
  }
  else if (this->stride() == 1)
  { // then r has a stride
    if (r.first() >= first())
    {
      useFirst = r.first();
    }
    else
    {
      long incr = (first() - r.first()) / stride;
      useFirst = r.first() + incr * stride;
      if (useFirst < first())
        useFirst += stride;
    }
  }
  else if (r.stride() == 1)
  { // then this has a stride
    if (first() >= r.first())
    {
      useFirst = first();
    }
    else
    {
      long incr = (r.first() - first()) / stride;
      useFirst = first() + incr * stride;
      if (useFirst < r.first())
        useFirst += stride;
    }
  }
  else
  {
    THROW_INVALID_RANGE("Intersection when both ranges have a stride", "Range::intersect");
  }
  if (useFirst > last)
  {
    return  RangePtr(new Range());
  }
  else 
  {
    return  RangePtr(new Range(m_name, useFirst, last, stride));
  }
}
示例#3
0
文件: Range.cpp 项目: nhauser/cdma
//---------------------------------------------------------------------------
// Range::intersects
//---------------------------------------------------------------------------
bool Range::intersects(const Range& r)
{
  if ((length() == 0) || (r.length() == 0))
  {
#ifdef CDMA_STD_SMART_PTR
    return  bool(RangePtr ( new Range()));
#else
    return RangePtr( new Range() );
#endif
  }

  long last = this->last() > r.last() ? r.last() : this->last();
  long stride = this->stride() * r.stride();
  long useFirst;
  if (stride == 1) 
  {
    useFirst = this->first() > r.first() ? this->first() : r.first();
  }
  else if (this->stride() == 1) // then r has a stride
  { 
    if (r.first() >= first()) 
    {
      useFirst = r.first();
    }
    else 
    {
      long incr = (first() - r.first()) / stride;
      useFirst = r.first() + incr * stride;
      if (useFirst < first())
        useFirst += stride;
    }
  }
  else if (r.stride() == 1) // then this has a stride
  { 
    if (first() >= r.first()) 
    {
      useFirst = first();
    }
    else 
    {
      long incr = (r.first() - first()) / stride;
      useFirst = first() + incr * stride;
      if (useFirst < r.first())
        useFirst += stride;
    }
  }
  else 
  {
    THROW_INVALID_RANGE("Intersection when both ranges have a stride", "Range::intersects");
  }
  return (useFirst <= last);
}
示例#4
0
文件: Range.cpp 项目: nhauser/cdma
//---------------------------------------------------------------------------
// Range::compose
//---------------------------------------------------------------------------
RangePtr Range::compose(const Range& range) throw ( Exception )
{
  Range* res = NULL;
  if ((length() == 0) || (range.length() == 0))
  {
    res = new Range();
  }
  else
  {
    long first = element(range.first());
    long strid = stride() * range.stride();
    long last  = element(range.last());
    res = new Range( m_name, first, last, strid);
  }
  return RangePtr(res);
}
示例#5
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;
}
示例#6
0
	void Camera::updateview(Range<int16_t> mapwalls, Range<int16_t> mapborders)
	{
		hbounds = Range<int16_t>(-mapwalls.first() - 10, -mapwalls.second() + 10);
		vbounds = -mapborders;
	}