Beispiel #1
0
static void to_angle_and_axe(void)
{
	HklVector v_ref = {{0 ,0, 1}};
	HklVector v_null = {{0 ,0, 0}};
	HklQuaternion q_I = {{1, 0, 0, 0}};

	int i;
	double angle_ref;
	double angle;
	HklVector v;
	HklQuaternion q;


	/* test the q = (1, 0, 0, 0) solution axe == (0, 0, 0) and angle = 0. */
	hkl_quaternion_to_angle_and_axe(&q_I, &angle, &v);
	ok(0 == hkl_vector_cmp(&v_null, &v), __func__);
	is_double(0., angle, HKL_EPSILON, __func__);

	/* test other cases */
	for(i=-180; i<180; i++) {
		angle_ref = i *  HKL_DEGTORAD;
		hkl_quaternion_init_from_angle_and_axe(&q, angle_ref, &v_ref);
		hkl_quaternion_to_angle_and_axe(&q, &angle, &v);

		if (!hkl_vector_cmp(&v_ref, &v))
			is_double(angle_ref, angle, HKL_EPSILON, __func__);
		else if (hkl_vector_is_opposite(&v, &v_ref))
			is_double(angle_ref, -angle, HKL_EPSILON, __func__);
	}
}
static void
effect_point (edit_env env, box b, tree xt, tree yt, SI& x, SI& y) {
  if (is_double (xt)) x= as_int (b->x1 + as_double (xt) * b->w ());
  else x= env->as_length (xt);
  if (is_double (yt)) y= as_int (b->y1 + as_double (yt) * b->h ());
  else y= env->as_length (yt);
}
void pwn::postfix_writer::do_add_node(cdk::add_node * const node, int lvl) {
  CHECK_TYPES(_compiler, _symtab, node);
  
  if (is_pointer(node->type())) {
    if (is_int(node->left()->type())) {
      node->right()->accept(this, lvl + 1); // load the pointer
      node->left()->accept(this, lvl + 1); // load the shift
    } else {
      node->left()->accept(this, lvl + 1); // load the pointer
      node->right()->accept(this, lvl + 1); // load the shift
    } 
    
    _pf.INT(4); // pointer size
    _pf.MUL(); // pointer arithmetics shift calculation
    _pf.ADD();
      
    return;
  }
  
  node->left()->accept(this, lvl);
  if (is_double(node->type()) && is_int(node->left()->type())) {
    _pf.I2D();
  }
  
  node->right()->accept(this, lvl);
  if (is_double(node->type()) && is_int(node->right()->type())) {
    _pf.I2D();
  }
  
  if (is_int(node->type())) {
    _pf.ADD();    
  } else if (is_double(node->type())) {
    _pf.DADD();
  }
}
Beispiel #4
0
tree
sub (tree t1, tree t2) {
  if (is_double (t1) && is_double (t2))
    return as_tree (as_double (t1) - as_double (t2));
  if (t1 == "0") return tree (MINUS, t2);
  if (t2 == "0") return t1;
  return tree (MINUS, t1, t2);
}
Beispiel #5
0
tree
div (tree t1, tree t2) {
  if (is_double (t1) && is_double (t2))
    return as_tree (as_double (t1) / as_double (t2));
  if (t1 == "0") return "0";
  if (t2 == "1") return t1;
  return tree (OVER, t1, t2);
}
Beispiel #6
0
tree
add (tree t1, tree t2) {
  if (is_double (t1) && is_double (t2))
    return as_tree (as_double (t1) + as_double (t2));
  if (t1 == "0") return t2;
  if (t2 == "0") return t1;
  return tree (PLUS, t1, t2);
}
Beispiel #7
0
tree
pow (tree t1, tree t2) {
  if (is_double (t1) && is_double (t2))
    return as_tree (pow (as_double (t1), as_double (t2)));
  if (t1 == "0" || t1 == "1") return t1;
  if (t2 == "0") return "1";
  if (t2 == "1") return t1;
  return tree (POW, t1, t2);
}
Beispiel #8
0
tree
mul (tree t1, tree t2) {
  if (is_double (t1) && is_double (t2))
    return as_tree (as_double (t1) * as_double (t2));
  if (t1 == "0" || t2 == "0") return "0";
  if (t1 == "1") return t2;
  if (t2 == "1") return t1;
  return tree (TIMES, t1, t2);
}
Beispiel #9
0
static void assignment(void)
{
	HklQuaternion q = {{1, 0, 0, 0}};
	HklQuaternion copy = q;

	is_double(1., copy.data[0], HKL_EPSILON, __func__);
	is_double(0., copy.data[1], HKL_EPSILON, __func__);
	is_double(0., copy.data[2], HKL_EPSILON, __func__);
	is_double(0., copy.data[3], HKL_EPSILON, __func__);
}
Beispiel #10
0
static void init(void)
{
	HklSource s;

	hkl_source_init(&s, 1, 1, 0, 0);

	is_double(1., s.wave_length, HKL_EPSILON, __func__);
	is_double(1., s.direction.data[0], HKL_EPSILON, __func__);
	is_double(0., s.direction.data[1], HKL_EPSILON, __func__);
	is_double(0., s.direction.data[2], HKL_EPSILON, __func__);
}
Beispiel #11
0
void test_IsDouble(void)
{
	int temp;	
	temp = is_double("0");
	TEST_ASSERT_TRUE(temp);
	temp = is_double("123");
	TEST_ASSERT_TRUE(temp);
	temp = is_double("123.45"); //DOESN'T WORK WITH 123,45, not sure if intented?
	TEST_ASSERT_TRUE(temp);
	temp = is_double("-123.45"); //DOESN'T WORK WITH 123,45, not sure if intented?
	TEST_ASSERT_TRUE(temp);
}
Beispiel #12
0
tree
evaluate_lesseq (tree t) {
  if (N(t)!=2) return evaluate_error ("bad less or equal");
  tree t1= evaluate (t[0]);
  tree t2= evaluate (t[1]);
  if (is_compound (t1) || is_compound (t2))
    return evaluate_error ("bad less or equal");
  string s1= t1->label;
  string s2= t2->label;
  if (is_double (s1) && (is_double (s2)))
    return as_string_bool (as_double (s1) <= as_double (s2));
  if (is_length (s1) && is_length (s2))
    return as_string_bool (as_length (s1) <= as_length (s2));
  return evaluate_error ("bad less or equal");
}
Beispiel #13
0
void pwn::postfix_writer::do_print_node(pwn::print_node * const node, int lvl) {
  CHECK_TYPES(_compiler, _symtab, node);
  node->argument()->accept(this, lvl); // determine the value to print
  if (is_int(node->argument()->type())) {
    _pf.CALL("printi");
    _pf.TRASH(4); // delete the printed value
    std::string *f_name = new std::string("printi");
    _declared_functions.push_back(f_name);
    _called_functions.push_back(f_name);
  }
  else if (is_string(node->argument()->type())) {
    _pf.CALL("prints");
    _pf.TRASH(4); // delete the printed value's address
    std::string *f_name = new std::string("prints");
    _declared_functions.push_back(f_name);
    _called_functions.push_back(f_name);
  } else if (is_double(node->argument()->type())) {
    _pf.CALL("printd");
    _pf.TRASH(8); // delete double printed value
    std::string *f_name = new std::string("printd");
    _declared_functions.push_back(f_name);
    _called_functions.push_back(f_name);
  } else {
    std::cerr << "ERROR: Trying to print invalid type." << std::endl;
    exit(1);
  }
  if (node->new_line()) {
    _pf.CALL("println"); // print a newline
    std::string *f_name = new std::string("println");
    _declared_functions.push_back(f_name);
    _called_functions.push_back(f_name);
  }
}
Beispiel #14
0
void pwn::postfix_writer::do_simple_lvalue_node(pwn::simple_lvalue_node * const node, int lvl) {
  CHECK_TYPES(_compiler, _symtab, node);

  std::string id = fix_id(node->value());
  std::shared_ptr<pwn::symbol> symbol = _symtab.find(id); 
  
  if ( ! _current_function) {
    // global context
    if ( ! symbol->is_var()) {
      throw "Error: assigning a value to a function";
    }
    
    _pf.ADDR(id);
  } else {
    // local context
    bool is_return_symbol = ( ! symbol->is_var()) // the symbol is a function
                         && (_current_function->name() == symbol->name()) // the symbol has the same name as the current function
                         && ( ! is_void(_current_function->type())); // the function doesnt "return" void
                         
    if (is_return_symbol) {
      if (is_double(_current_function->type())) {
        _pf.LOCAL(-8); // double @ -8
      } else {
        _pf.LOCAL(-4); // int, string, pointer @ -4
      }
    } else if (symbol->is_var() && symbol->name() != _current_function->name()) {
      _pf.LOCAL(symbol->offset());
    } else {
      throw "Error: invalid left value";
    }
  }

}
Beispiel #15
0
static Value ripe_to_real(Value v)
{
    if (is_int64(v)) return v;
    if (is_double(v)) return v;
    Complex* c = val_to_complex(v);
    return double_to_val(c->real);
}
Beispiel #16
0
int	zbx_variant_set_numeric(zbx_variant_t *value, const char *text)
{
	zbx_uint64_t	value_ui64;
	char		buffer[MAX_STRING_LEN];

	zbx_strlcpy(buffer, text, sizeof(buffer));

	zbx_rtrim(buffer, "\n\r"); /* trim newline for historical reasons / backwards compatibility */
	zbx_trim_integer(buffer);
	del_zeros(buffer);

	if ('+' == buffer[0])
	{
		/* zbx_trim_integer() stripped one '+' sign, so there's more than one '+' sign in the 'text' argument */
		return FAIL;
	}

	if (SUCCEED == is_uint64(buffer, &value_ui64))
	{
		zbx_variant_set_ui64(value, value_ui64);
		return SUCCEED;
	}

	if (SUCCEED == is_double(buffer))
	{
		zbx_variant_set_dbl(value, atof(buffer));
		return SUCCEED;
	}

	return FAIL;
}
Beispiel #17
0
static int	variant_to_dbl(zbx_variant_t *value)
{
	char	buffer[MAX_STRING_LEN];
	double	value_dbl;

	switch (value->type)
	{
		case ZBX_VARIANT_DBL:
			return SUCCEED;
		case ZBX_VARIANT_UI64:
			zbx_variant_set_dbl(value, (double)value->data.ui64);
			return SUCCEED;
		case ZBX_VARIANT_STR:
			zbx_strlcpy(buffer, value->data.str, sizeof(buffer));
			break;
		default:
			return FAIL;
	}

	zbx_rtrim(buffer, "\n\r"); /* trim newline for historical reasons / backwards compatibility */
	zbx_trim_float(buffer);

	if (SUCCEED != is_double(buffer))
		return FAIL;

	value_dbl = atof(buffer);

	zbx_variant_clear(value);
	zbx_variant_set_dbl(value, value_dbl);

	return SUCCEED;
}
Beispiel #18
0
static short	get_prio(char **cmd, int in, short i, short prio)
{
	while ((*cmd)[++i])
	{
		if (!(in = is_in((i > 0) ? (*cmd)[i - 1] : 0, (*cmd)[i], in))
			&& (*cmd)[i - 1] && (*cmd)[i - 1] != '\\')
		{
			if (is_double(*cmd, i, 1) && ((*cmd)[i] = ' '))
				prio = (*cmd)[i++];
			if (((*cmd)[i] == PIPE && (*cmd)[i + 1] == PIPE)
				|| ((*cmd)[i] == '&' && (*cmd)[i + 1] == '&'))
			{
				i += 2;
				break ;
			}
			else if (((*cmd)[i] == PIPE)\
				|| ((*cmd)[i] == CHEVRON_R && (*cmd)[i + 1] != '&')\
				|| ((*cmd)[i] == CHEVRON_L && (*cmd)[i + 1] != '&'))
			{
				get_current_id_prio(prio != 0 ? CHEVRON_DOUBLE : (*cmd)[i]);
				break ;
			}
		}
	}
	(*cmd)[i] = '\0';
	return (i + 1);
}
Beispiel #19
0
void pwn::postfix_writer::do_function_call_node(pwn::function_call_node * const node, int lvl) {
  CHECK_TYPES(_compiler, _symtab, node);

  std::string id = fix_id(node->name());
  std::shared_ptr<pwn::symbol> symbol = _symtab.find(id);
  
  // put arguments in stack (reverse order)
  int args_size = 0;
  if (node->arguments()) {
    for (int i = node->arguments()->size() - 1; i >= 0; i--) {
      node->arguments()->node(i)->accept(this, lvl);
      args_size += ((cdk::expression_node *) node->arguments()->node(i))->type()->size();
    }
  }
  
  // call function
  _pf.CALL(id);
  
  // remove arguments from stack
  _pf.TRASH(args_size);
  
  // put return value in the stack
  if (is_int(symbol->type()) || is_pointer(symbol->type()) || is_string(symbol->type())) {
    _pf.PUSH();
  } else if (is_double(symbol->type())) {
    _pf.DPUSH();
  }
  
  // add this function to called functions
  _called_functions.push_back(new std::string(id));
}
Beispiel #20
0
static short	get_total_node(char *cmd, int on, short i, short n_node)
{
	short	in;

	in = 0;
	while (cmd[++i])
	{
		if (!(on = is_in((i > 1) ? cmd[i - 1] : 0, cmd[i], on)))
			if (i == 0 || (cmd[i - 1] && cmd[i - 1] != '\\'))
			{
				if (is_double(cmd, i, 2))
					i++;
				if (cmd[i] == PIPE && cmd[i + 1] == PIPE)
					i++;
				if (cmd[i] == '&' && cmd[i + 1] == '&')
					n_node++;
				if (cmd[i] == PIPE || cmd[i] == CHEVRON_R \
					|| cmd[i] == CHEVRON_L)
					in = 0;
				else if (in == 0)
				{
					n_node++;
					in = 1;
				}
			}
	}
	return (n_node);
}
Beispiel #21
0
void Flag::print_as_flag(outputStream* st) {
  if (is_bool()) {
    st->print("-XX:%s%s", get_bool() ? "+" : "-", name);
  } else if (is_intx()) {
    st->print("-XX:%s=" INTX_FORMAT, name, get_intx());
  } else if (is_uintx()) {
    st->print("-XX:%s=" UINTX_FORMAT, name, get_uintx());
  } else if (is_uint64_t()) {
    st->print("-XX:%s=" UINT64_FORMAT, name, get_uint64_t());
  } else if (is_double()) {
    st->print("-XX:%s=%f", name, get_double());
  } else if (is_ccstr()) {
    st->print("-XX:%s=", name);
    const char* cp = get_ccstr();
    if (cp != NULL) {
      // Need to turn embedded '\n's back into separate arguments
      // Not so efficient to print one character at a time,
      // but the choice is to do the transformation to a buffer
      // and print that.  And this need not be efficient.
      for (; *cp != '\0'; cp += 1) {
        switch (*cp) {
          default:
            st->print("%c", *cp);
            break;
          case '\n':
            st->print(" -XX:%s=", name);
            break;
        }
      }
    }
  } else {
    ShouldNotReachHere();
  }
}
Beispiel #22
0
int main(){ 
	std::vector<test> test_inputs{
		{ "1", true },
		{ "-1", true },
		{ "1.2", true },
		{ "-1.3", true },
		{ "1.", true },
		{ ".3", true },
		{ "-.4", true },
		{ "1e3", true },
		{ "1.2e3", true },
        { "-12.34e56", true },
        { "-1.23e-78", true },
		{ "f", false },
		{ "-f", false },
		{ "e", false },
        { ".e", false },
        { "e1", false }        
	};

	for (auto t : test_inputs)
		if (is_double(t.input) == t.result) 
			std::cout << "Test of : " << t.input << " passed\n";
		
		else
			std::cout << "Test of : " << t.input << " failed\n";
}		
Beispiel #23
0
void Flag::print_on(outputStream* st, bool withComments) {
  st->print("%9s %-40s %c= ", type, name, (origin != DEFAULT ? ':' : ' '));
  if (is_bool())     st->print("%-16s", get_bool() ? "true" : "false");
  if (is_intx())     st->print("%-16ld", get_intx());
  if (is_uintx())    st->print("%-16lu", get_uintx());
  if (is_uint64_t()) st->print("%-16lu", get_uint64_t());
  if (is_double())   st->print("%-16f", get_double());

  if (is_ccstr()) {
     const char* cp = get_ccstr();
     if (cp != NULL) {
       const char* eol;
       while ((eol = strchr(cp, '\n')) != NULL) {
         char format_buffer[FORMAT_BUFFER_LEN];
         size_t llen = pointer_delta(eol, cp, sizeof(char));
         jio_snprintf(format_buffer, FORMAT_BUFFER_LEN,
                     "%%." SIZE_FORMAT "s", llen);
         st->print(format_buffer, cp);
         st->cr();
         cp = eol+1;
         st->print("%5s %-35s += ", "", name);
       }
       st->print("%-16s", cp);
     }
     else st->print("%-16s", "");
  }
  st->print("%-20s", kind);
  if (withComments) {
#ifndef PRODUCT
    st->print("%s", doc );
#endif
  }
  st->cr();
}
Beispiel #24
0
static void get_wavelength(void)
{
	HklSource s;

	hkl_source_init(&s, 1, 1, 0, 0);

	is_double(1., hkl_source_get_wavelength(&s), HKL_EPSILON, __func__);
}
Beispiel #25
0
 void ConfUnit::set_double(double d) {
     if (is_double()) {
         _union.d = d;
     }
     else {
         throw std::exception();
     }
 }
PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL
void Flag::print_on(outputStream* st, bool withComments) {
  // Don't print notproduct and develop flags in a product build.
  if (is_constant_in_binary()) {
    return;
  }

  st->print("%9s %-40s %c= ", _type, _name, (!is_default() ? ':' : ' '));

  if (is_bool()) {
    st->print("%-16s", get_bool() ? "true" : "false");
  }
  if (is_intx()) {
    st->print("%-16ld", get_intx());
  }
  if (is_uintx()) {
    st->print("%-16lu", get_uintx());
  }
  if (is_uint64_t()) {
    st->print("%-16lu", get_uint64_t());
  }
  if (is_double()) {
    st->print("%-16f", get_double());
  }
  if (is_ccstr()) {
    const char* cp = get_ccstr();
    if (cp != NULL) {
      const char* eol;
      while ((eol = strchr(cp, '\n')) != NULL) {
        char format_buffer[FORMAT_BUFFER_LEN];
        size_t llen = pointer_delta(eol, cp, sizeof(char));
        jio_snprintf(format_buffer, FORMAT_BUFFER_LEN,
            "%%." SIZE_FORMAT "s", llen);
PRAGMA_DIAG_PUSH
PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL
        st->print(format_buffer, cp);
PRAGMA_DIAG_POP
        st->cr();
        cp = eol+1;
        st->print("%5s %-35s += ", "", _name);
      }
      st->print("%-16s", cp);
    }
    else st->print("%-16s", "");
  }

  st->print("%-20s", " ");
  print_kind(st);

  if (withComments) {
#ifndef PRODUCT
    st->print("%s", _doc);
#endif
  }
  st->cr();
}
Beispiel #27
0
// Done - untested
void pwn::postfix_writer::do_div_node(cdk::div_node * const node, int lvl) {
  CHECK_TYPES(_compiler, _symtab, node);
  
  node->left()->accept(this, lvl);
  if (is_double(node->type()) && is_int(node->left()->type())) {
    _pf.DIV();
  }
  
  node->right()->accept(this, lvl);
  if (is_double(node->type()) && is_int(node->right()->type())) {
    _pf.I2D();
  }
  
  if (is_int(node->type())) {
    _pf.ADD();    
  } else if (is_double(node->type())) {
    _pf.DDIV();
  }
}
Beispiel #28
0
static void new_copy(void)
{
	HklSource s, c;

	hkl_source_init(&s, 1.54, 1, 0, 0);
	c = s;

	is_double(c.wave_length, s.wave_length, HKL_EPSILON, __func__);
	ok(FALSE == hkl_vector_cmp(&c.direction, &s.direction), __func__);
}
Beispiel #29
0
const double* json_node::get_double(void) const
{
	if (!is_double())
		return NULL;
	const char* txt = get_text();
	if (txt == NULL || *txt == 0)
		return NULL;
	const_cast<json_node*>(this)->node_val_.d = atof(txt);
	return &node_val_.d;
}
Beispiel #30
0
void pwn::postfix_writer::do_rvalue_node(pwn::rvalue_node * const node, int lvl) {
  CHECK_TYPES(_compiler, _symtab, node);
  node->lvalue()->accept(this, lvl);
  
  if (is_double(node->type())) {
    _pf.DLOAD();        
  } else {
    _pf.LOAD();    
  }
}