Пример #1
0
bool ieee_not_equal(const ieee_floatt &a, const ieee_floatt &b)
{
  if(a.NaN || b.NaN) return true; // !!!
  if(a.is_zero() && b.is_zero()) return false;
  assert(a.spec==b.spec);
  return a!=b;
}
Пример #2
0
bvt float_utilst::build_constant(const ieee_floatt &src)
{
  unbiased_floatt result;

  result.sign=const_literal(src.get_sign());
  result.NaN=const_literal(src.is_NaN());
  result.infinity=const_literal(src.is_infinity());
  result.exponent=bv_utils.build_constant(src.get_exponent(), spec.e);
  result.fraction=bv_utils.build_constant(src.get_fraction(), spec.f+1);

  return pack(bias(result));
}
Пример #3
0
bool ieee_floatt::operator<(const ieee_floatt &other) const
{
  if(NaN_flag || other.NaN_flag)
    return false;

  // check both zero?
  if(is_zero() && other.is_zero())
    return false;

  // one of them zero?
  if(is_zero())
    return !other.sign_flag;
  else if(other.is_zero())
    return sign_flag;

  // check sign
  if(sign_flag!=other.sign_flag)
    return sign_flag;

  // handle infinity
  if(infinity_flag)
  {
    if(other.infinity_flag)
      return false;
    else
      return sign_flag;
  }
  else if(other.infinity_flag)
    return !sign_flag;

  // check exponent
  if(exponent!=other.exponent)
  {
    if(sign_flag) // both negative
      return exponent>other.exponent;
    else
      return exponent<other.exponent;
  }

  // check significand
  if(sign_flag) // both negative
    return fraction>other.fraction;
  else
    return fraction<other.fraction;
}
Пример #4
0
bool ieee_floatt::ieee_not_equal(const ieee_floatt &other) const
{
  if(NaN_flag || other.NaN_flag)
    return true; // !!!
  if(is_zero() && other.is_zero())
    return false;
  assert(spec==other.spec);
  return *this!=other;
}
Пример #5
0
bool operator <=(const ieee_floatt &a, const ieee_floatt &b)
{
  if(a.NaN || b.NaN) return false;
  
  // check zero
  if(a.is_zero() && b.is_zero())
    return true;

  //handle infinity
  if(a.infinity && b.infinity && a.sign==b.sign)
    return true;
  
  if(!a.infinity && !b.infinity &&
     a.sign==b.sign &&
     a.exponent==b.exponent &&
     a.fraction==b.fraction)
    return true;
    
  return a<b;
}
Пример #6
0
bool operator < (const ieee_floatt &a, const ieee_floatt &b)
{
  if(a.NaN || b.NaN) return false;

  // check both zero?
  if(a.is_zero() && b.is_zero())
    return false;

  // one of them zero?
  if(a.is_zero())
    return !b.sign;
  else if(b.is_zero())
    return a.sign;

  // check sign
  if(a.sign!=b.sign)
    return a.sign;
   
  // handle infinity
  if(a.infinity)
  {
    if(b.infinity) return false;
    else return a.sign; 
  }
  else if(b.infinity) return !a.sign;

  // check exponent
  if(a.exponent!=b.exponent)
  {
    if(a.sign) // both negative
      return a.exponent>b.exponent;
    else
      return a.exponent<b.exponent;
  }
  
  // check significand
  if(a.sign) // both negative
    return a.fraction>b.fraction;
  else
    return a.fraction<b.fraction;
}
Пример #7
0
bool ieee_floatt::operator<=(const ieee_floatt &other) const
{
  if(NaN_flag || other.NaN_flag)
    return false;

  // check zero
  if(is_zero() && other.is_zero())
    return true;

  // handle infinity
  if(infinity_flag && other.infinity_flag &&
     sign_flag==other.sign_flag)
    return true;

  if(!infinity_flag && !other.infinity_flag &&
     sign_flag==other.sign_flag &&
     exponent==other.exponent &&
     fraction==other.fraction)
    return true;

  return *this<other;
}