コード例 #1
0
bool Interpreter::Data::operator<(const Data& x) const {
  if (type == NONE || x.type == NONE) return false;
  if (type == INT) {
    if (x.type == INT) return Int() < x.Int();
    else return Int() < x.Float() + EPS;
  } else if (type == FLOAT) {
    if (x.type == INT) return Float() < x.Int() + EPS;
    else return Float() < x.Float() + EPS;
  } else if (type == ARRAY) return Array() < x.Array();
  else return Str() < x.Str();
}
コード例 #2
0
bool Interpreter::Data::operator==(const Data& x) const {
  if (type == NONE && x.type == NONE) return true;
  if (type == NONE || x.type == NONE) return false;
  if (type == INT) {
    if (x.type == INT) return Int() == x.Int();
    else return abs(Int() - x.Float()) < EPS;
  } else if (type == FLOAT) {
    if (x.type == INT) return abs(Float() - x.Int()) < EPS;
    else return abs(Float() - x.Float()) < EPS;
  } else if (type == ARRAY) return Array() == x.Array();
  else return Str() == x.Str();
}