Exemple #1
0
void NumberValue::verifyUnits(const NumberValue& n) {
  if (type == Value::DIMENSION && n.type == Value::DIMENSION &&
      getUnit().compare(n.getUnit()) != 0) {
    setValue(convert(n.getUnit()));
    setUnit(n.getUnit());
  }
}
Exemple #2
0
Value* NumberValue::tan(const vector<const Value*> &args) {
  if (args[0]->type != Value::NUMBER &&
      args[0]->type != Value::DIMENSION) {
    throw new ValueException("tan() only works on numbers "
                             "or dimensions", *args[0]->getTokens());
  }
  NumberValue* n = new NumberValue(*(const NumberValue*)args[0]);
  double val = n->getValue();
  std::string unit;
    
  if (n->type == Value::DIMENSION) {
    unit = n->getUnit();
    if(unit.compare("rad") != 0 &&
       unit.compare("deg") != 0 &&
       unit.compare("grad") != 0 &&
       unit.compare("turn") != 0) {
      throw new ValueException("ta() requires rad, deg, "
                               "grad or turn units.", *args[0]->getTokens());
    }
    val = UnitValue::angleToRad(val, unit);
  }

  n->setValue(std::tan(val));
  n->type = Value::NUMBER;
  n->setUnit("");
  return n;
}    
Exemple #3
0
void NumberValue::setType(const NumberValue &n) {
  type = n.type;
  if (n.type == DIMENSION)
    setUnit(n.getUnit());
  else if (n.type == PERCENTAGE) 
    tokens.front().type = Token::PERCENTAGE;
  else if (n.type == NUMBER) {
    setUnit("");
  }
}