int			my_getnbr_base(char *str, char *base)
{
  int			result;
  int			i;
  int			len;
  char			sign;

  i = 0;
  result = 0;
  sign ='+';
  if (str && base)
    {
      len = my_strlen(base);
      check_sign(str, len, base);
      if (str[i] == '-' || str[i] == '+')
	sign = sign_base(str, &i);
      if (check_base(str[i], base) == -1)
	return (-1);
      result = calc_nbr(str, i, base, len);
      if (sign == '-')
	result = -result;
      return (result);
    }
  else
    return (-1);
}
void set_motor_b(void){
	static int nowspeed = 0;
	static int nextspeed = 0;
	
	if(nextspeed < terget_spd_b)
		nextspeed = limit(nowspeed + CHANGE, -255 / 2, terget_spd_b);
	else if(nextspeed > terget_spd_b)
		nextspeed = limit(nowspeed - CHANGE, terget_spd_b, 255 / 2);
  
  if(check_sign(nowspeed) != check_sign(nextspeed)){
	  set_off_motor_b();
	  chenge_direction_b();
	  nowspeed = nextspeed;
    motor_b_func_p = wait_motor_b_chattering;
  }
  else{
    nowspeed = nextspeed;
	  setSpeedMotorB(nowspeed * 2);
  }
}	
/**
 *@brief Aモータのメイン関数
 */
void set_motor_a(void) {
	static int now_speed = 0;
	static int next_speed = 0;
	
	if( next_speed < target_spd_a )
	  next_speed = limit( now_speed + CHANGE, -( 255 / 2 ), target_spd_a );
	else if( next_speed > target_spd_a )
	  next_speed = limit( now_speed - CHANGE, target_spd_a, ( 255 / 2 ) );
	
	if( check_sign( &now_speed ) != check_sign( &next_speed ) ) {
		set_off_motor_a();
		chenge_direction_a();
		now_speed = next_speed;
		motor_a_func_p = wait_motor_a_chatterring;
	}
	else {
		now_speed = next_speed;
		setSpeedMotorA( now_speed * 2 );
	}
}
Пример #4
0
int
main (int argc, char *argv[])
{
  tests_start_mpfr ();

  check_nans ();
  check_exact ();
  check_float ();

  check53("6.9314718055994530941514e-1", "0.0", MPFR_RNDZ, "0.0");
  check53("0.0", "6.9314718055994530941514e-1", MPFR_RNDZ, "0.0");
  check_sign();
  check53("-4.165000000e4", "-0.00004801920768307322868063274915", MPFR_RNDN,
          "2.0");
  check53("2.71331408349172961467e-08", "-6.72658901114033715233e-165",
          MPFR_RNDZ, "-1.8251348697787782844e-172");
  check53("2.71331408349172961467e-08", "-6.72658901114033715233e-165",
          MPFR_RNDA, "-1.8251348697787786e-172");
  check53("0.31869277231188065", "0.88642843322303122", MPFR_RNDZ,
          "2.8249833483992453642e-1");
  check("8.47622108205396074254e-01", "3.24039313247872939883e-01", MPFR_RNDU,
        28, 45, 2, "0.375");
  check("8.47622108205396074254e-01", "3.24039313247872939883e-01", MPFR_RNDA,
        28, 45, 2, "0.375");
  check("2.63978122803639081440e-01", "6.8378615379333496093e-1", MPFR_RNDN,
        34, 23, 31, "0.180504585267044603");
  check("1.0", "0.11835170935876249132", MPFR_RNDU, 6, 41, 36,
        "0.1183517093595583");
  check53("67108865.0", "134217729.0", MPFR_RNDN, "9.007199456067584e15");
  check("1.37399642157394197284e-01", "2.28877275604219221350e-01", MPFR_RNDN,
        49, 15, 32, "0.0314472340833162888");
  check("4.03160720978664954828e-01", "5.854828e-1"
        /*"5.85483042917246621073e-01"*/, MPFR_RNDZ,
        51, 22, 32, "0.2360436821472831");
  check("3.90798504668055102229e-14", "9.85394674650308388664e-04", MPFR_RNDN,
        46, 22, 12, "0.385027296503914762e-16");
  check("4.58687081072827851358e-01", "2.20543551472118792844e-01", MPFR_RNDN,
        49, 3, 2, "0.09375");
  check_max();
  check_min();

  check_regression ();
  test_generic (2, 500, 100);

  data_check ("data/mulpi", mpfr_mulpi, "mpfr_mulpi");

  valgrind20110503 ();

  tests_end_mpfr ();
  return 0;
}
Пример #5
0
  void check_sign(const MatrixType& matrix, const std::vector <bipartite_graph_bfs_node>& spanning_tree, const bipartite_graph_dimensions& dim,
      const std::set <size_t>& nodes, size_t current_index, size_t column, std::map <size_t, bool>& changes)
  {
    /// Root does never change.
    if (spanning_tree[current_index].predecessor == current_index)
    {
      changes[dim.index_to_row(current_index)] = false;
      return;
    }

    /// Search for ancestors until reaching one of the given nodes.
    int value = matrix(dim.index_to_row(current_index), column);
    size_t last, index = current_index;
    do
    {
      last = index;
      index = spanning_tree[index].predecessor;
      std::pair <size_t, size_t> coords = dim.indexes_to_coordinates(index, last);
      value += matrix(coords.first, coords.second);
    }
    while (nodes.find(index) == nodes.end());

    /// If the ancestor is not yet processed, we recurse.
    if (changes.find(dim.index_to_row(index)) == changes.end())
    {
      check_sign(matrix, spanning_tree, dim, nodes, index, column, changes);
    }

    value += matrix(dim.index_to_row(index), column);
    if (changes[dim.index_to_row(index)])
    {
      value += 2;
    }

    value = (value >= 0 ? value : -value) % 4;
    /// If sum (modulo 4) is not 0, we'd like to change the current one
    changes[dim.index_to_row(current_index)] = (value == 2);

    if (value != 0 && value != 2)
    {
      throw std::logic_error("Signing procedure: modulo-sum of cycle was neither 0, nor 2!");
    }
  }
Пример #6
0
double			ft_atof(char *n)
{
	t_atof	atof;

	init(&atof);
	if (!n || !*n)
		return (0);
	check_sign(&n, &atof);
	while (*n != '\0')
	{
		if (*n >= '0' && *n <= '9')
			number(&atof, n);
		else if (*n == '.')
			point(&atof);
		else
			return (atof.sign * (atof.ipart + atof.fpart / atof.divisor));
		n++;
	}
	return (atof.sign * (atof.ipart + atof.fpart
	/ atof.divisor));
}
Пример #7
0
int readserial::read()
{
		counter = 0;
		int transfer_speed = TRANS_SPEED;
		if(Serial.available() == 0){
				return 0;
		}else{
				while(byte = Serial.read())
				{
						if(byte != '#'){
								readin(&counter, &byte);
								delayMicroseconds(transfer_speed * 10 + 25);
//+25 used to offset deviation
						}else{
								delayMicroseconds(transfer_speed * 30 + 25);
								char buffer[3];
								Serial.readBytes(buffer, 3);
								//countinue - 0
								//break -1
								if(check_sign(buffer)){
										continue;
								}else{
										break;
								}
						}
				}
				//Debug
				Serial.println("Debug:");
				Serial.println(node_name);
				Serial.println(p_type);
				Serial.println(temp_data);
				node_name = NULL;
				//p_name = NULL;
				return 1;
		}
}
Пример #8
0
int		my_getnbr(char *str)
{
  int		compt;
  int		i;

  i = 0;
  compt = 0;
  while (clean_lett(str[compt]) == 0)
    {
      if (str[compt] != '+' && str[compt] != '-')
	return (0);
      else
	compt++;
    }
  while (clean_lett(str[compt]) == 1)
    {
      i = i * 10;
      i = i + (str[compt] - '0');
      compt++;
    }
  if (check_sign(str) == -1)
    i = i * -1;
  return (i);
}
Пример #9
0
  bool sign_matrix(M& matrix, submatrix_indices* violator)
  {
    bool result = true;
    matrix_permuted <M> permuted(matrix);
    size_t handled_rows = 0;

    /// Go trough column by column.
    for (size_t handled_columns = 0; handled_columns < permuted.size2(); ++handled_columns)
    {
      if (find_nonzero_column(permuted, handled_columns, permuted.size2(), 0, handled_rows, handled_columns))
      {
        /// There is a non-zero column right of the already-handled submatrix.

        std::set <size_t> start_nodes;
        std::set <size_t> end_nodes;
        std::set <size_t> all_nodes;

        bipartite_graph_dimensions dim(handled_rows, handled_columns);
        for (size_t row = 0; row < handled_rows; ++row)
        {
          if (permuted(row, handled_columns) != 0)
          {
            size_t index = dim.row_to_index(row);
            if (start_nodes.empty())
              start_nodes.insert(index);
            else
              end_nodes.insert(index);
            all_nodes.insert(index);
          }
        }

        /// Start a BFS on bipartite graph of the submatrix and look for shortest paths from first 1 to all others

        std::vector <bipartite_graph_bfs_node> bfs_result;
        if (!bipartite_graph_bfs(permuted, dim, start_nodes, end_nodes, true, bfs_result))
          throw std::logic_error("Signing procedure: Did not reach all nodes via bfs!");

        /// Evaluate matrix-entries on the shortest paths
        std::map <size_t, bool> changes;
        for (typename std::set <size_t>::const_iterator iter = end_nodes.begin(); iter != end_nodes.end(); ++iter)
        {
          check_sign(permuted, bfs_result, dim, all_nodes, *iter, handled_columns, changes);
        }

        /// Checking changes
        for (std::map <size_t, bool>::iterator iter = changes.begin(); iter != changes.end(); ++iter)
        {
          if (!iter->second)
            continue;

          if (boost::is_const <M>::value)
          {
            if (violator)
            {
              /// Find the violator, going along the path
              std::set <size_t> violator_rows, violator_columns;

              size_t index = iter->first;
              do
              {
                if (dim.is_row(index))
                  violator_rows.insert(permuted.perm1()(dim.index_to_row(index)));
                else
                  violator_columns.insert(permuted.perm2()(dim.index_to_column(index)));

                index = bfs_result[index].predecessor;
              }
              while (all_nodes.find(index) == all_nodes.end());
              violator_rows.insert(permuted.perm1()(dim.index_to_row(index)));
              violator_columns.insert(permuted.perm2()(handled_columns));

              /// Fill violator data
              violator->rows = submatrix_indices::indirect_array_type(violator_rows.size());
              violator->columns = submatrix_indices::indirect_array_type(violator_columns.size());
              size_t i = 0;
              for (std::set <size_t>::const_iterator iter = violator_rows.begin(); iter != violator_rows.end(); ++iter)
                violator->rows[i++] = *iter;
              i = 0;
              for (std::set <size_t>::const_iterator iter = violator_columns.begin(); iter != violator_columns.end(); ++iter)
                violator->columns[i++] = *iter;
            }
            return false;
          }
          else
          {
            /// We are not just testing, so swap the sign on a one.
            size_t real_row = permuted.perm1()(dim.index_to_row(iter->first));
            size_t real_column = permuted.perm2()(handled_columns);
            matrix_set_value(matrix, real_row, real_column, -matrix(real_row, real_column));

            result = false;
          }
        }

        matrix_reorder_rows(permuted, handled_rows, permuted.size1(), handled_columns, permuted.size2(), abs_greater <int> ());

        /// Augment submatrix by rows with 1 in the new column.
        while (handled_rows < permuted.size1())
        {
          if (permuted(handled_rows, handled_columns) == 0)
            break;
          else
            ++handled_rows;
        }
      }
      else
      {
        /// Handled upper-left submatrix and lower-right submatrix are disconnected
        for (size_t column = handled_columns; column < permuted.size2(); ++column)
        {
          size_t count = 0;
          for (size_t row = handled_rows; row < permuted.size1(); ++row)
          {
            if (permuted(row, column) != 0)
              ++count;
          }

          /// A zero column can be skipped, as it is handled by definition.
          if (count > 0)
          {
            /// Found a nonzero column and swap ones to the top.
            matrix_reorder_rows(permuted, handled_rows, permuted.size1(), handled_columns, permuted.size2(), abs_greater <int> ());
            while (handled_rows < permuted.size1())
            {
              if (permuted(handled_rows, handled_columns) == 0)
                break;
              else
                ++handled_rows;
            }

            break;
          }
        }
      }
    }

    return result;
  }