예제 #1
0
  virtual IOperand *operator*(const IOperand &rhs) const // mul
  {
    IOperand		*operand = NULL;
    eOperandType	type;

    type = _precision >= rhs.getPrecision() ? _type : rhs.getType();
    switch (type) {
    case INT8:
      operand = new Operand<char>(type, _value * my_atof(rhs.toString()));
      break;
    case INT16:
      operand = new Operand<short>(type, _value * my_atof(rhs.toString()));
      break;
    case INT32:
      operand = new Operand<int>(type, _value * my_atof(rhs.toString()));
      break;
    case FLOAT:
      operand = new Operand<float>(type, _value * my_atof(rhs.toString()));
      break;
    case DOUBLE:
      operand = new Operand<double>(type, _value * my_atof(rhs.toString()));
      break;
    }
    return (operand);
  }
예제 #2
0
//android bionic glibc
int main()
{
	char data[1024];
	my_strcpy(data, "hehe");
	printf("%s\n", data);
	my_strcat(data, "来自中国1024");
	printf("%s\n", data);
	char hehe[1024];
	my_memset(hehe, 0, sizeof(hehe));
	my_memccpy(hehe, data, '1', my_strlen(data));
	printf("%s\n", hehe);
	printf("%d\n", my_strlen(hehe));

	char s[] = "-abc-=-def";
	char *x = my_strtok(s, "-");		// x = "abc"
	printf("%s\n", x);
	x = my_strtok(NULL, "-=");		// x = "def"
	printf("%s\n", x);
	x = my_strtok(NULL, "=");		// x = NULL
	printf("%s\n", x);

	printf("%f %d %ld\n", my_atof("1.245"), my_atoi("1024"), my_atol("152.63"));

	return 0;
}
예제 #3
0
int my_roundf(double myfloat)
{
	char tmp[50] ;
	sprintf(tmp, "%0.f", myfloat) ;
	int number = my_atof(tmp) ;
	return number ;
}
예제 #4
0
파일: ex_4_2.c 프로젝트: Pfju/K_R_Exercises
int main ( int argc, char **argv )
{
	double dValue;
	dValue = my_atof ( "123.4678e-3" );
	printf ( "%.4f\n", dValue );

	return 0;
}
void DlgEditBoardCorner::GetFields()
{
	// get x and y values
	CString xstr;
	m_edit_x.GetWindowText( xstr );
	CString ystr;
	m_edit_y.GetWindowText( ystr );
	if( m_units == MIL )
	{
		m_x = my_atof( &xstr )*NM_PER_MIL;
		m_y = my_atof( &ystr )*NM_PER_MIL;
	}
	else
	{
		m_x = my_atof( &xstr )*1000000.0;
		m_y = my_atof( &ystr )*1000000.0;
	}
}
예제 #6
0
  virtual IOperand		*operator/(const IOperand &rhs) const
  {
    IOperand			*res;
    eOperandType		type;
    double			value;

    if (my_atof(rhs.toString()) == 0)
      throw Exception("Division by zero bro, \"Are u madding brooo ?! Kreooooog\"");
    value = this->_value / my_atof(rhs.toString());
    if (this->_precision >= rhs.getPrecision())
      type = this->_type;
    else
      type = rhs.getType();
    switch (type)
      {
      case INT8 :
	{
	  res = new Operand<char>(type, value);
	  break;
	}
      case INT16 :
	{
	  res = new Operand<short>(type, value);
	  break;
	}
      case INT32 :
	{
	  res = new Operand<int>(type, value);
	  break;
	}
      case FLOAT :
	{
	  res = new Operand<float>(type, value);
	  break;
	}
      case DOUBLE :
	{
	  res = new Operand<double>(type, value);
	  break;
	}
      }
    return (res);
  }
예제 #7
0
파일: krx40200.c 프로젝트: HenryNi/mycode
/*
** Lame and evil wrapper function to give the exercise the requested
** interface.  Dann Corbit will plead innocent to the end.
** It's very existence means that the code is not conforming.
** Pretend you are a C library implementer, OK?  But you would fix
** all those bleeding gaps, I am sure.
*/
double atof(char *s)
{
    double          d = 0.0;
    if (!my_atof(s, &d))
    {
#ifdef DEBUG
        fputs("Error converting string in [sic] atof()", stderr);
#endif
        raise(SIGFPE);
    }
    return d;
}
예제 #8
0
  virtual IOperand *operator/(const IOperand &rhs) const
  {
IOperand		*operand = NULL;
    eOperandType	type;
     const Operand		&tmp = static_cast<const Operand &>(rhs);

    if (my_atof(tmp.toString()) == 0)
      throw Exception("Division by zero.");
    type = _precision >= rhs.getPrecision() ? _type : rhs.getType();
    switch (type) {
    case INT8:
      operand = new Operand<char>(type, _value / my_atof(rhs.toString()));
      break;
    case INT16:
      operand = new Operand<short>(type, _value / my_atof(rhs.toString()));
      break;
    case INT32:
      operand = new Operand<int>(type, _value / my_atof(rhs.toString()));
      break;
    case FLOAT:
      operand = new Operand<float>(type, _value / my_atof(rhs.toString()));
      break;
    case DOUBLE:
      operand = new Operand<double>(type, _value / my_atof(rhs.toString()));
      break;
    }
    return (operand);
  }
예제 #9
0
  virtual IOperand *operator%(const IOperand &rhs) const
  {
      IOperand                  *operand = NULL;
      eOperandType              type;
      const Operand		&tmp = static_cast<const Operand &>(rhs);

    if (my_atof(tmp.toString()) == 0)
      throw Exception("Modulo by zero.");
    type = _precision >= rhs.getPrecision() ? _type : rhs.getType();
    if (_type == FLOAT || rhs.getType() == FLOAT)
        throw Exception("Modulo with float.");
    else if (_type == DOUBLE || rhs.getType() == DOUBLE)
        throw Exception("Modulo with double.");
    operand = new Operand(type, (int)_value % my_atoi(tmp.toString()));
    return (operand);
  }
/* ex:val */
void AzSvDataS::decomposeFeat(const char *token,
                              int line_no,
                              /*---  output  ---*/
                              int *ex,
                              double *val)
{
  /* *ex = atol(token); */
  *ex = my_fno(token, "AzSvDataS::decomposeFeat", line_no);

  *val = 1;
  const char *ptr = strchr(token, ':');
  if (ptr != NULL) {
    /* *val = atof(ptr + 1); */
    *val = my_atof(ptr+1, "AzSvDataS::decomposeFeat", line_no);
  }
}
예제 #11
0
  virtual IOperand		*operator%(const IOperand &rhs) const
  {
    IOperand			*res;
    eOperandType		type;

    if (my_atof(rhs.toString()) == 0)
      throw Exception("Modulo by zero bro, \"Are u madding brooo ?! Kreooooog\"");
    if (this->_precision >= rhs.getPrecision())
      type = this->_type;
    else
      type = rhs.getType();
    if (this->_type == FLOAT || rhs.getType() == FLOAT)
      throw Exception("Try to make a modulo with FLOAT ? Kreog u Bro !");
    else if (this->_type == DOUBLE || rhs.getType() == DOUBLE)
      throw Exception("Try to make a modulo with DOUBLE ? Kreog u Bro !");
    res = new Operand(type, (int)this->_value % my_atoi(rhs.toString()));
    return (res);
  }
예제 #12
0
static char *
perform_math (char *input)
{
   char buf[256];
   double res;

   /* FIXME
    * Always apply floating-point arithmetic.
    * Does this cause problems for integer parameters? (yes it will)
    *
    * What we should do is, loop over the string and figure out whether
    * there are floating point operands, too and then switch to
    * floating point math.
    */
   res = my_atof(input);
   snprintf(buf, sizeof (buf), "%lf", res);
   return strdup(buf);
}
예제 #13
0
  virtual IOperand		*operator+(const IOperand &rhs) const
  {
    IOperand			*res;
    eOperandType		type;
    double			value = this->_value + my_atof(rhs.toString());

    if (this->_precision >= rhs.getPrecision())
      type = this->_type;
    else
      type = rhs.getType();
    switch (type)
      {
      case INT8 :
	{
	  res = new Operand<char>(type, value);
	  break;
	}
      case INT16 :
	{
	  res = new Operand<short>(type, value);
	  break;
	}
      case INT32 :
	{
	  res = new Operand<int>(type, value);
	  break;
	}
      case FLOAT :
	{
	  res = new Operand<float>(type, value);
	  break;
	}
      case DOUBLE :
	{
	  res = new Operand<double>(type, value);
	  break;
	}
      }
    return (res);
  }
예제 #14
0
//逆ポーランドモードの関数
void rpn_calc(char* formula)
{
	printf("\tRPN Calc Exec : formula = \"%s\"\n",formula);

	double answer = 0;
	double ret = 0;
	int i;

	char tmp_buffer[BUFFER_LENGTH];
	int tmp_buffer_pointer = 0;
	string_clear(tmp_buffer,'\0',BUFFER_LENGTH);

	//実数が含まれるか確認
	for(i=0;formula[i]!='\0';i++)
	{
		if(formula[i]=='.')
		{
			double_flag = 1;
			printf("\tRPN Calc Exec : double mode is true\n");
			break;
		}
	}

	//計算ループ
	for(i=0;formula[i]!='\0';i++)
	{
		//数値の場合
		if((formula[i]>='0'&&formula[i]<='9')||formula[i]=='.')
		{
			tmp_buffer[tmp_buffer_pointer++] = formula[i];
		}
		//演算子の場合
		else if(formula[i]=='+'||formula[i]=='-'||formula[i]=='*'||formula[i]=='/')
		{
			if(tmp_buffer[0]!='\0')
			{
				if(double_flag==1)
					ret = my_atof(tmp_buffer);
				else
					ret = my_atoi(tmp_buffer);

				stack_push(ret);
				string_clear(tmp_buffer,'\0',BUFFER_LENGTH);
				tmp_buffer_pointer = 0;
			}
			stack_push(calc_exec(formula[i]));
		}
		//スペースまたはコンマの場合
		else if(formula[i]==' '||formula[i]==',')
		{
			if(tmp_buffer[0]!='\0')
			{
				if(double_flag==1)
					ret = my_atof(tmp_buffer);
				else
					ret = my_atoi(tmp_buffer);

				stack_push(ret);
				string_clear(tmp_buffer,'\0',BUFFER_LENGTH);
				tmp_buffer_pointer = 0;
			}
		}
	}

	//解答を取り出す
	answer = stack_pop();

	//エラーフラグのチェック
	if(error_flag==0)
	{
		//実数フラグによって表示方法を変更
		if(double_flag==0)
		{
			printf("\tAnswer : %d\n",(int)answer);
		}
		else
		{
			printf("\tAnswer : %lf\n",answer);
			double_flag = 0;
		}
	}
	else
	{
		//エラーが起こったときに答えを表示せずにエラー件数を表示して終了
		printf("\tError : Total Error -> %d\n",error_flag);
		error_flag = 0;
	}
}
예제 #15
0
static struct params parseargs(int argc, char **argv)
{
	struct params p = {
		.waveform = -1,				/* invalid */
		.duration = INVALID_DOUBLE,		/* invalid */
		.frequency = INVALID_DOUBLE,	 	/* invalid */
		.bandwidth = INVALID_DOUBLE,		/* invalid */
		.q = INVALID_DOUBLE,			/* invalid */
		.phase = DEFAULT_PHASE,
		.eccentricity = DEFAULT_ECCENTRICITY,
		.amplitude = INVALID_DOUBLE,		/* invalid */
		.hrss = INVALID_DOUBLE,			/* invalid */
		.fluence = INVALID_DOUBLE,		/* invalid */
		.srate = DEFAULT_SRATE
	};
	struct LALoption long_options[] = {
		{"help", no_argument, 0, 'h'},
		{"verbose", no_argument, 0, 'v'},
		{"waveform", required_argument, 0, 'w'},
		{"duration", required_argument, 0, 't'},
		{"frequency", required_argument, 0, 'f'},
		{"bandwidth", required_argument, 0, 'b'},
		{"quality-factor", required_argument, 0, 'q'},
		{"eccentricity", required_argument, 0, 'e'},
		{"phase", required_argument, 0, 'p'},
		{"amplitude", required_argument, 0, 'A'},
		{"hrss", required_argument, 0, 'H'},
		{"fluence", required_argument, 0, 'F'},
		{"sample-rate", required_argument, 0, 'R'},
		{0, 0, 0, 0}
	};
	char args[] = "hvw:t:f:b:q:e:A:H:F:d:R:";

	while (1) {
		int option_index = 0;
		int c;

		c = LALgetopt_long_only(argc, argv, args, long_options, &option_index);
		if (c == -1) /* end of options */
			break;

		switch (c) {
		case 0:		/* if option set a flag, nothing else to do */
			if (long_options[option_index].flag)
				break;
			else {
				fprintf(stderr, "error parsing option %s with argument %s\n", long_options[option_index].name, LALoptarg);
				exit(1);
			}
		case 'h':	/* help */
			usage(argv[0]);
			exit(0);
		case 'v':	/* verbose */
			verbose = 1;
			break;
		case 'w':	/* waveform */
			p.waveform = waveform_value(LALoptarg);
			break;
		case 't':	/* duration */
			p.duration = my_atof(LALoptarg);
			break;
		case 'f':	/* frequency */
			p.frequency = my_atof(LALoptarg);
			break;
		case 'b':	/* bandwidth */
			p.bandwidth = my_atof(LALoptarg);
			break;
		case 'q':	/* quality-factor */
			p.q = my_atof(LALoptarg);
			break;
		case 'e':	/* eccentricity */
			p.eccentricity = my_atof(LALoptarg);
			break;
		case 'p':	/* phase */
			/* convert phase from degrees to radians */
			p.phase = my_atof(LALoptarg) * LAL_PI_180;
			break;
		case 'A':	/* amplitude */
			p.amplitude = my_atof(LALoptarg);
			break;
		case 'H':	/* hrss */
			p.hrss = my_atof(LALoptarg);
			break;
		case 'F':	/* fluence */
			/* convert fluence to sum-squared hdot */
			p.fluence = my_atof(LALoptarg);
			break;
		case 'R':	/* sample-rate */
			p.srate = my_atof(LALoptarg);
			break;
		case '?':
		default:
			fprintf(stderr, "unknown error while parsing options\n");
			exit(1);
		}
	}
	if (LALoptind < argc) {
		fprintf(stderr, "extraneous command line arguments:\n");
		while (LALoptind < argc)
			fprintf(stderr, "%s\n", argv[LALoptind++]);
		exit(1);
	}
	return p;
}
/*------------------------------------------------------------------*/
void AzSvDataS::_parseDataLine(const AzByte *inp,
                              int inp_len,
                              int f_num,
                              const char *data_fn,
                              int line_no,
                              /*---  output  ---*/
                              AzIFarr &ifa_ex_val)
{
  const char *eyec = "AzSvDataS::_parseDataLine";

  ifa_ex_val.prepare(f_num);
  const AzByte *wp = inp, *line_end = inp + inp_len;
//  AzIFarr ifa_ex_val;
  int ex = 0;
  for ( ; ; ) {
    if (wp >= line_end) break;

#if 1
    int str_len;
    const AzByte *str = AzTools::getString(&wp, line_end, &str_len);
    if (str_len > 0) {
      if (ex >= f_num) {
        AzBytArr s("Error in "); s.c(data_fn); s.c(": Line#="); s.cn(line_no);
        AzPrint::writeln(log_out, s);
        s.reset(); s.c("Too many values per line: expected "); s.cn(f_num); s.c(" values.");
        throw new AzException(AzInputNotValid, eyec, s.c_str());
      }

#if 1
      double val = my_atof((char *)str, eyec, line_no);
#else
      double val = atof((char *)str);
      if (val == 0 && *str != '0' && *str != '+' && *str != '-') {
        AzBytArr s("Invalid token "); s.c(str, str_len); s.c(" in "); s.c(data_fn); s.c(": Line#="); s.cn(line_no);
        AzPrint::writeln(log_out, s);
        throw new AzException(AzInputNotValid, eyec, s.c_str());
      }
#endif

      if (val != 0) {
        ifa_ex_val.put(ex, val);
      }
      ++ex;
    }
#else
    AzBytArr str_token;
    AzTools::getString(&wp, line_end, &str_token);
    if (str_token.getLen() > 0) {
      if (ex >= f_num) {
        AzBytArr s("Error in "); s.c(data_fn); s.c(": Line#="); s.cn(line_no);
        AzPrint::writeln(log_out, s);
        s.reset(); s.c("Too many values per line: expected "); s.cn(f_num); s.c(" values.");
        throw new AzException(AzInputNotValid, eyec, s.c_str());
      }
      /* double val = atof(str_token.c_str()); */
      double val = my_atof(str_token.c_str(), eyec, line_no);
      if (val != 0) {
        ifa_ex_val.put(ex, val);
      }
      ++ex;
    }
#endif
  }
  if (ex < f_num) {
    AzTimeLog::print("Error in Line#=", line_no, log_out);
    throw new AzException(AzInputNotValid, eyec, "Too few values");
  }

//  m_feat->load(col, &ifa_ex_val);
}