Exemplo n.º 1
0
TEST(math, __fpclassifyd) {
#if defined(__GLIBC__)
#define __fpclassifyd __fpclassify
#endif
  ASSERT_EQ(FP_INFINITE, __fpclassifyd(HUGE_VAL));
  ASSERT_EQ(FP_NAN, __fpclassifyd(nan("")));
  ASSERT_EQ(FP_NORMAL, __fpclassifyd(1.0));
  ASSERT_EQ(FP_SUBNORMAL, __fpclassifyd(double_subnormal()));
  ASSERT_EQ(FP_ZERO, __fpclassifyd(0.0));
}
    void nanPayloadsUnitTest() {
        REQUIRE_START(testNanPayloads);
        REQUIRE(nanPayloadf(nanf("0"))    == 0); 
        REQUIRE(nanPayloadf(nanf("1954")) == 1954); 
        REQUIRE(nanPayloadf(nanf("0") + 99) == 0); 
        REQUIRE(nanPayloadf(nanf("1954")+ 99) == 1954); 

        REQUIRE(nanPayload (nan("0"))    == 0); 
        REQUIRE(nanPayload (nan("1954")) == 1954); 
        REQUIRE(nanPayload (nan("0") + 99) == 0); 
        REQUIRE(nanPayload (nan("1954")+ 99) == 1954); 

        // something wrong with nanPayloadl() at the moment
        //REQUIRE(nanPayloadl(nan("0")).low    == 0); 
        //REQUIRE(nanPayloadl(nan("1954")).low == 1954); 
        //REQUIRE(nanPayloadl(nan("0") + 99).low == 0); 
        //REQUIRE(nanPayloadl(nan("1954")+ 99).low == 1954); 
        //int errs = REQUIRE_END(testnanPayloads);
    }
Exemplo n.º 3
0
float *parse_fields(char *line, int n)
{
    float *field = calloc(n, sizeof(float));
    char *c, *p, *end;
    int count = 0;
    int done = 0;
    for(c = line, p = line; !done; ++c) {
        done = (*c == '\0');
        if(*c == ',' || done) {
            *c = '\0';
            field[count] = strtod(p, &end);
            if(p == c) field[count] = nan("");
            if(end != c && (end != c-1 || *end != '\r')) field[count] = nan(""); //DOS file formats!
            p = c+1;
            ++count;
        }
    }
    return field;
}
Exemplo n.º 4
0
void ValuesTable::ResetValue(int i) {
	ValueInfo& v = m_values.at(i);
	m_values.at(i).state = ValueInfo::EMPTY;
	if (m_stats.Start() <= i && i <= m_stats.End()) {
		m_probes_count -= v.max_probes;
		if (m_probes_count)
			m_data_probes_ratio = double(m_data_probes_count) / m_probes_count;
		else
			m_data_probes_ratio = nan("");
	}
}
Exemplo n.º 5
0
double
VNUM(const char *p)
{
	const char *t;
	double r;

	r = VNUMpfx(p, &t);
	if (t != NULL)
		r = nan("");
	return (r);
}
Exemplo n.º 6
0
double operator * (const Vector& l, const Vector& r)
{
	if (l.size != r.size) return nan(0);
	double res = 0;
	for (size_t i = 0; i < l.size; i++)
	{
		res += l.values[i] * r.values[i];
	}
	return res;

}
Exemplo n.º 7
0
TEST(math, __fpclassifyd) {
#if defined(__BIONIC__)
  ASSERT_EQ(FP_INFINITE, __fpclassifyd(HUGE_VAL));
  ASSERT_EQ(FP_NAN, __fpclassifyd(nan("")));
  ASSERT_EQ(FP_NORMAL, __fpclassifyd(1.0));
  ASSERT_EQ(FP_SUBNORMAL, __fpclassifyd(double_subnormal()));
  ASSERT_EQ(FP_ZERO, __fpclassifyd(0.0));
#else // __BIONIC__
  GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
Exemplo n.º 8
0
double VisualNavbar::addressToLocalX(RVA address)
{
    for (auto x2a : xToAddress) {
        if ((x2a.address_from <= address) && (address < x2a.address_to)) {
            double offset = (double)(address - x2a.address_from) / (double)(x2a.address_to - x2a.address_from);
            double size = x2a.x_end - x2a.x_start;
            return x2a.x_start + (offset * size);
        }
    }
    return nan("");
}
Exemplo n.º 9
0
double MatCTECat( EXPR *name, EXPR *nothing )
    {
    char *string ;

    string = ExprValueString( name ) ;
    if( !string )
	{
	IOerror( MatBomb, "MatCTECat", "cannot evaluate name" ) ;
	return nan("") ;
	}
    return ExprValue( DbaseGetExpr( string, "CTE" ) ) ;
    }
Exemplo n.º 10
0
TEST(math, round) {
  auto guard = make_scope_guard([]() {
    fesetenv(FE_DFL_ENV);
  });
  fesetround(FE_TOWARDZERO); // round ignores the rounding mode and always rounds away from zero.
  ASSERT_DOUBLE_EQ(1.0, round(0.5));
  ASSERT_DOUBLE_EQ(-1.0, round(-0.5));
  ASSERT_DOUBLE_EQ(0.0, round(0.0));
  ASSERT_DOUBLE_EQ(-0.0, round(-0.0));
  ASSERT_TRUE(isnan(round(nan(""))));
  ASSERT_DOUBLE_EQ(HUGE_VAL, round(HUGE_VAL));
}
Exemplo n.º 11
0
static void
irt_rpf_mdim_drm_paramInfo(const double *spec, const int param,
			   const char **type, double *upper, double *lower)
{
	int numDims = spec[RPF_ISpecDims];
	*upper = nan("unset");
	*lower = nan("unset");
	if (numDims == 0) {
		*type = "intercept";
		return;
	}
	*type = NULL;
	if (param >= 0 && param < numDims) {
		*type = "slope";
		*lower = 1e-6;
	} else if (param == numDims) {
		*type = "intercept";
	} else if (param == numDims+1 || param == numDims+2) {
		*type = "bound";
	}
}
Exemplo n.º 12
0
double calcCombinations(int n, int k){
	if(n == k)
		return (double)nan("");
	else if(n < k)
		return (double)INFINITY;
	else{
		double result;
		result = sequentialMultiply(k+1, n);
		result /= sequentialMultiply(1,n-k);
		return result;
	}
}
Exemplo n.º 13
0
TEST(math, trunc) {
  auto guard = make_scope_guard([]() {
    fesetenv(FE_DFL_ENV);
  });
  fesetround(FE_UPWARD); // trunc ignores the rounding mode and always rounds toward zero.
  ASSERT_DOUBLE_EQ(1.0, trunc(1.5));
  ASSERT_DOUBLE_EQ(-1.0, trunc(-1.5));
  ASSERT_DOUBLE_EQ(0.0, trunc(0.0));
  ASSERT_DOUBLE_EQ(-0.0, trunc(-0.0));
  ASSERT_TRUE(isnan(trunc(nan(""))));
  ASSERT_DOUBLE_EQ(HUGE_VAL, trunc(HUGE_VAL));
}
Exemplo n.º 14
0
double solution::euclideanDistance(solution &s2) {
    double sum = 0;

    if(getNumObjectives() != s2.getNumObjectives())
        return nan("");

    int i;
    for(i=0;i<getNumObjectives();i++)
        sum += (getObjective(i) - s2.getObjective(i)) * (getObjective(i) - s2.getObjective(i));

    return sqrt(sum);
}
Exemplo n.º 15
0
bool			bunny_configuration_get_double(const t_bunny_configuration *config,
						       double			*val)
{
  SmallConf		*conf = (SmallConf*)config;
  bool			ret;

  ret = conf->GetDouble(val);
  scream_log_if
    ("%p conf, %p target  -> %s (%f)", "configuration",
     config, val, ret ? "true" : "false", ret ? *val : nan(""));
  return (ret);
}
Exemplo n.º 16
0
static void
irt_rpf_nominal_paramInfo(const double *spec, const int param,
			  const char **type, double *upper, double *lower)
{
	int numDims = spec[RPF_ISpecDims];
	const int numOutcomes = spec[RPF_ISpecOutcomes];
	*upper = nan("unset");
	*lower = nan("unset");
	if (numDims == 0) {
		*type = "intercept";
		return;
	}
	*type = NULL;
	if (param >= 0 && param < numDims) {
		*type = "slope";
		*lower = 1e-6;
	} else if (param < numDims + numOutcomes - 1) {
		*type = "slope";
	} else {
		*type = "intercept";
	}
}
Exemplo n.º 17
0
double sequentialMultiply(int start, int end) {
	double result;
	if(start == end)
		return (double)start;
	if(start > end)
		return (double)nan("");
	result = (double)start++;
	while(start <= end){
		result *= start;
		start++;
	}
	return result;
}
Exemplo n.º 18
0
void ValuesTable::ClearStats() {
	m_count = 0;
	m_probes_count = 0;
	m_data_probes_count = 0;

	m_sum = 
	m_sum2 = 
	m_sdev = 
	m_max = 
	m_min = 
	m_hsum = 
	m_data_probes_ratio = 
		nan("");
}	
Exemplo n.º 19
0
  double readBranchLength(std::istream &iss)
  {
    bool foundNext = false; 
    while(not foundNext)
      {
	int ch = iss.get(); 

	foundNext = ( ch == ')'
		      || ch == ';'
		      || ch == ',' ) ; 
      }
    iss.unget();
    return nan("");
  }
Exemplo n.º 20
0
// the callback function for the timer event
void SumAndAverageNode::timerCallback(ros::TimerEvent const& event)
{
// create the message containing the moving average
    std_msgs::Float32 moving_average_msg;
    if (moving_average_count_ > 0)
        moving_average_msg.data = moving_average_sum_ / moving_average_count_;
    else
        moving_average_msg.data = nan("");
// publish the moving average
    moving_average_pub_.publish(moving_average_msg);
// reset the moving average
    moving_average_sum_ = 0;
    moving_average_count_ = 0;
}
Exemplo n.º 21
0
static void update_control(uint32_t comm_period, float dt)
{
	/*
	 * Start/stop management
	 */
	const enum motor_rtctl_state new_rtctl_state = motor_rtctl_get_state();

	const bool just_stopped =
		new_rtctl_state == MOTOR_RTCTL_STATE_IDLE &&
		_state.rtctl_state != MOTOR_RTCTL_STATE_IDLE;
	if (just_stopped) {
		handle_unexpected_stop();
	}

	_state.rtctl_state = new_rtctl_state;
	if (comm_period == 0 || _state.rtctl_state != MOTOR_RTCTL_STATE_RUNNING) {
		update_control_non_running();
		return;
	}

	/*
	 * Primary control logic; can return NAN to stop the motor
	 */
	float new_duty_cycle = nan("");
	if (_state.mode == MOTOR_CONTROL_MODE_OPENLOOP) {
		new_duty_cycle = update_control_open_loop(comm_period);
	}
	else if (_state.mode == MOTOR_CONTROL_MODE_RPM) {
		new_duty_cycle = update_control_rpm(comm_period, dt);
	}
	else { assert(0); }

	if (!isfinite(new_duty_cycle)) {
		stop(true);
		return;
	}

	/*
	 * Limiters
	 */
	new_duty_cycle = update_control_current_limit(new_duty_cycle);
	new_duty_cycle = update_control_dc_slope(new_duty_cycle, dt);

	/*
	 * Update
	 */
	_state.dc_actual = new_duty_cycle;
	motor_rtctl_set_duty_cycle(_state.dc_actual);
}
Exemplo n.º 22
0
void CheckInfNan(int snprintf_fn(T*, size_t, const T*, ...),
                 const T* fmt, const T* fmt_plus,
                 const T* minus_inf, const T* inf_, const T* plus_inf,
                 const T* minus_nan, const T* nan_, const T* plus_nan) {
  T buf[BUFSIZ];

  snprintf_fn(buf, sizeof(buf), fmt, nan(""));
  EXPECT_STREQ(nan_, buf) << fmt;
  snprintf_fn(buf, sizeof(buf), fmt, -nan(""));
  EXPECT_STREQ(minus_nan, buf) << fmt;
  snprintf_fn(buf, sizeof(buf), fmt_plus, nan(""));
  EXPECT_STREQ(plus_nan, buf) << fmt_plus;
  snprintf_fn(buf, sizeof(buf), fmt_plus, -nan(""));
  EXPECT_STREQ(minus_nan, buf) << fmt_plus;

  snprintf_fn(buf, sizeof(buf), fmt, HUGE_VAL);
  EXPECT_STREQ(inf_, buf) << fmt;
  snprintf_fn(buf, sizeof(buf), fmt, -HUGE_VAL);
  EXPECT_STREQ(minus_inf, buf) << fmt;
  snprintf_fn(buf, sizeof(buf), fmt_plus, HUGE_VAL);
  EXPECT_STREQ(plus_inf, buf) << fmt_plus;
  snprintf_fn(buf, sizeof(buf), fmt_plus, -HUGE_VAL);
  EXPECT_STREQ(minus_inf, buf) << fmt_plus;
}
Exemplo n.º 23
0
void Read_Parameter(int i_iArg_Count,const char * i_lpszArg_Values[], const char * i_lpszOption_Name, const double &i_dDefault_Decay, PARAMETER_SET	& o_cParameter)
{
	double dNan = nan("");
	char lpszOption_String[64];
	char	lpszType[32];

	o_cParameter.dRef25 =	xParse_Command_Line_Dbl(i_iArg_Count,i_lpszArg_Values,i_lpszOption_Name,dNan);
	sprintf(lpszOption_String,"%s-decay",i_lpszOption_Name);
	o_cParameter.dDecay =	xParse_Command_Line_Dbl(i_iArg_Count,i_lpszArg_Values,lpszOption_String,i_dDefault_Decay);
	sprintf(lpszOption_String,"%s-law",i_lpszOption_Name);
	xParse_Command_Line_String(i_iArg_Count,i_lpszArg_Values,lpszOption_String,lpszType,sizeof(lpszType),NULL);
	o_cParameter.Set_Type(lpszType);
	sprintf(lpszOption_String,"%s-extreme",i_lpszOption_Name);
	o_cParameter.dRef_Extreme =	xParse_Command_Line_Dbl(i_iArg_Count,i_lpszArg_Values,lpszOption_String,0.0);

}
Exemplo n.º 24
0
TEST(math, fpclassify) {
  ASSERT_EQ(FP_INFINITE, fpclassify(INFINITY));
  ASSERT_EQ(FP_INFINITE, fpclassify(HUGE_VALF));
  ASSERT_EQ(FP_INFINITE, fpclassify(HUGE_VAL));

  ASSERT_EQ(FP_NAN, fpclassify(nanf("")));
  ASSERT_EQ(FP_NAN, fpclassify(nan("")));

  ASSERT_EQ(FP_NORMAL, fpclassify(1.0f));
  ASSERT_EQ(FP_NORMAL, fpclassify(1.0));

  ASSERT_EQ(FP_SUBNORMAL, fpclassify(float_subnormal()));
  ASSERT_EQ(FP_SUBNORMAL, fpclassify(double_subnormal()));

  ASSERT_EQ(FP_ZERO, fpclassify(0.0f));
  ASSERT_EQ(FP_ZERO, fpclassify(0.0));
}
Exemplo n.º 25
0
double RPNParser::evaluate(double x)
{
    size_t last_match_start = 0;
    size_t last_match_end = 0;
    while(last_match_end != std::string::npos)
    {
        last_match_end = m_expression.find(' ', last_match_start);
        std::string token = m_expression.substr(last_match_start, last_match_end - last_match_start);
        last_match_start = last_match_end + 1;
        // Evaluate it
        if( ! handle_token(token, x))
        {
            return nan("");
        }
    }
    return m_stack.top();
}
Exemplo n.º 26
0
static float update_control_rpm(uint32_t comm_period, float dt)
{
	if (_state.rpm_setpoint <= 0) {
		return nan("");
	}
	if (_state.rpm_setpoint < _params.rpm_min) {
		_state.rpm_setpoint = _params.rpm_min;
	}

	const struct rpmctl_input input = {
		_state.limit_mask,
		dt,
		(float)comm_period_to_rpm(comm_period),
		_state.rpm_setpoint
	};
	return rpmctl_update(&input);
}
Exemplo n.º 27
0
    TEST(ExpressionAlgoIsSubsetOf, Compare_NaN) {
        ParsedMatchExpression nan("{x: NaN}");
        ParsedMatchExpression lt("{x: {$lt: 5}}");
        ParsedMatchExpression lte("{x: {$lte: 5}}");
        ParsedMatchExpression gte("{x: {$gte: 5}}");
        ParsedMatchExpression gt("{x: {$gt: 5}}");

        ASSERT_TRUE(expression::isSubsetOf(nan.get(), nan.get()));
        ASSERT_FALSE(expression::isSubsetOf(nan.get(), lt.get()));
        ASSERT_FALSE(expression::isSubsetOf(lt.get(), nan.get()));
        ASSERT_FALSE(expression::isSubsetOf(nan.get(), lte.get()));
        ASSERT_FALSE(expression::isSubsetOf(lte.get(), nan.get()));
        ASSERT_FALSE(expression::isSubsetOf(nan.get(), gte.get()));
        ASSERT_FALSE(expression::isSubsetOf(gte.get(), nan.get()));
        ASSERT_FALSE(expression::isSubsetOf(nan.get(), gt.get()));
        ASSERT_FALSE(expression::isSubsetOf(gt.get(), nan.get()));
    }
Exemplo n.º 28
0
static double nloptObjectiveFunction(unsigned n, const double *x, double *grad, void *f_data)
{
	GradientOptimizerContext *goc = (GradientOptimizerContext *) f_data;
	nlopt_opt opt = (nlopt_opt) goc->extraData;
	FitContext *fc = goc->fc;
	assert(n == fc->numParam);
	int mode = 0;
	double fit = goc->solFun((double*) x, &mode);
	if (grad) {
		fc->iterations += 1;
		if (goc->maxMajorIterations != -1 && fc->iterations >= goc->maxMajorIterations) {
			nlopt_force_stop(opt);
		}
	}
	if (grad && goc->verbose >= 2) {
		mxLog("major iteration fit=%.12f", fit);
	}
	if (mode == -1) {
		if (!goc->feasible) {
			nlopt_force_stop(opt);
		}
		return nan("infeasible");
	}
	if (!grad) return fit;

	Eigen::Map< Eigen::VectorXd > Epoint((double*) x, n);
	Eigen::Map< Eigen::VectorXd > Egrad(grad, n);
	if (fc->wanted & FF_COMPUTE_GRADIENT) {
		Egrad = fc->grad;
	} else if (fc->CI && fc->CI->varIndex >= 0) {
		Egrad.setZero();
		Egrad[fc->CI->varIndex] = fc->lowerBound? 1 : -1;
		fc->grad = Egrad;
	} else {
		if (goc->verbose >= 3) mxLog("fd_gradient start");
		fit_functional ff(*goc);
		gradient_with_ref(goc->gradientAlgo, goc->gradientIterations, goc->gradientStepSize,
				  ff, fit, Epoint, Egrad);
		fc->grad = Egrad;
	}
	if (goc->verbose >= 3) {
		mxPrintMat("gradient", Egrad);
	}
	return fit;
}
Exemplo n.º 29
0
static DecimalFormatSymbols* makeDecimalFormatSymbols(JNIEnv* env,
        jstring currencySymbol0, jchar decimalSeparator, jchar digit,
        jstring exponentSeparator0, jchar groupingSeparator0,
        jstring infinity0, jstring internationalCurrencySymbol0,
        jchar minusSign, jchar monetaryDecimalSeparator, jstring nan0,
        jchar patternSeparator, jchar percent, jchar perMill, jchar zeroDigit) {
    ScopedJavaUnicodeString currencySymbol(env, currencySymbol0);
    ScopedJavaUnicodeString exponentSeparator(env, exponentSeparator0);
    ScopedJavaUnicodeString infinity(env, infinity0);
    ScopedJavaUnicodeString internationalCurrencySymbol(env,
            internationalCurrencySymbol0);
    ScopedJavaUnicodeString nan(env, nan0);
    UnicodeString groupingSeparator(groupingSeparator0);

    DecimalFormatSymbols* result = new DecimalFormatSymbols;
    result->setSymbol(DecimalFormatSymbols::kCurrencySymbol,
                      currencySymbol.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol,
                      UnicodeString(decimalSeparator));
    result->setSymbol(DecimalFormatSymbols::kDigitSymbol, UnicodeString(digit));
    result->setSymbol(DecimalFormatSymbols::kExponentialSymbol,
                      exponentSeparator.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol,
                      groupingSeparator);
    result->setSymbol(DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol,
                      groupingSeparator);
    result->setSymbol(DecimalFormatSymbols::kInfinitySymbol,
                      infinity.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol,
                      internationalCurrencySymbol.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kMinusSignSymbol,
                      UnicodeString(minusSign));
    result->setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol,
                      UnicodeString(monetaryDecimalSeparator));
    result->setSymbol(DecimalFormatSymbols::kNaNSymbol, nan.unicodeString());
    result->setSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol,
                      UnicodeString(patternSeparator));
    result->setSymbol(DecimalFormatSymbols::kPercentSymbol,
                      UnicodeString(percent));
    result->setSymbol(DecimalFormatSymbols::kPerMillSymbol,
                      UnicodeString(perMill));
    result->setSymbol(DecimalFormatSymbols::kZeroDigitSymbol,
                      UnicodeString(zeroDigit));
    return result;
}
Exemplo n.º 30
0
_WMRTLINK double log1p(double x)
{
double array[] = {ALNRCS1,  ALNRCS2,  ALNRCS3,  ALNRCS4,  ALNRCS5,
                  ALNRCS6,  ALNRCS7,  ALNRCS8,  ALNRCS9,  ALNRCS10,
                  ALNRCS11, ALNRCS12, ALNRCS13, ALNRCS14, ALNRCS15,
                  ALNRCS16, ALNRCS17, ALNRCS18, ALNRCS19, ALNRCS20,
                  ALNRCS21, ALNRCS22, ALNRCS23};

    if(x == -1.0)
        return XINF;
    else if(x < -1.0)
        return nan("ignore");
        
    if(fabs(x) <= 0.375) 
        return x * (1.0 - x*_Chebyshev_Evaluate(x/0.375, array, 23));
    else
        return log(1.0 + x);
}