Ejemplo n.º 1
0
void CStringEx::PutFloatS(float f, int len)
{
	// Code From
	// Copyright SOCABIM 1999
	// Pierre Caussin
	// Jean-Paul Retru
	switch	(_fpclass(f))
	{
		case _FPCLASS_SNAN:
		case _FPCLASS_QNAN:
			Format("%s", m_csNAN); // "NaN"
			return;
		case _FPCLASS_NINF:
			Format("%s", m_csNINF);// "-Inf"
			return;
		case _FPCLASS_PINF:
			Format("%s", m_csPINF);// "+Inf"
			return;
	}
	PutDoubleS((double) f, len);
	int acc = 8;
	if(len< acc+1) return;
	Accuracy(acc);
	return;
}
Ejemplo n.º 2
0
    void XmlResultGenerator::generateAtom (StringBuffer& output, float value) const {
      if (value == 0.0) {
        output.appendText("0.0", 3);
        return;
      }

      int intType = _fpclass(value);

      switch (intType) {
        case _FPCLASS_PN:
        case _FPCLASS_NN:
        case _FPCLASS_NZ:
        case _FPCLASS_PZ: {
          output.appendDecimal(value);
          break;
        }
        case _FPCLASS_NINF: {
          generateAtom(output, "-INF");
          break;
        }
        case _FPCLASS_PINF: {
          generateAtom(output, "INF");
          break;
        }
        default: {
          generateAtom(output, "NAN");
          break;
        }
      }
    }
Ejemplo n.º 3
0
int sc_fpclassify(float x) {
    int result;
    int kind = _fpclass((double)x);
    switch (kind)
    {
    case _FPCLASS_NINF:
        result = FP_INFINITE;
        break;
    case _FPCLASS_PINF:
        result = FP_INFINITE;
        break;
    case _FPCLASS_SNAN:
        result = FP_NAN;
        break;
    case _FPCLASS_QNAN:
        result = FP_NAN;
        break;
    case _FPCLASS_ND:
        result = FP_SUBNORMAL;
        break;
    case _FPCLASS_PD:
        result = FP_SUBNORMAL;
        break;
    default:
        result = FP_NORMAL;
    };
    return result;

}
Ejemplo n.º 4
0
enum {FP_NAN, FP_INFINITE, FP_ZERO, FP_SUBNORMAL, FP_NORMAL}
fpclassify(double x)
{
    switch(_fpclass(x)) {
        case _FPCLASS_SNAN: /* signaling NaN */
        case _FPCLASS_QNAN: /* quiet NaN */
            return FP_NAN;
        case _FPCLASS_NINF: /* negative infinity */
        case _FPCLASS_PINF: /* positive infinity */
            return FP_INFINITE;
        case _FPCLASS_NN:   /* negative normal */
        case _FPCLASS_PN:   /* positive normal */
            return FP_NORMAL;
        case _FPCLASS_ND:   /* negative denormalized */
        case _FPCLASS_PD:   /* positive denormalized */
            return FP_SUBNORMAL;
        case _FPCLASS_NZ:   /* negative zero */
        case _FPCLASS_PZ:   /* positive zero */
            return FP_ZERO;
        default:
            /* Should never get here; but if we do, this will guarantee
             * that the pattern is not treated like a number.
             */
            return FP_NAN;
    }
}
Ejemplo n.º 5
0
/*
 * @implemented
 */
double _y1(double num)
{
    double retval;
    int fpclass = _fpclass(num);

    if (!_finite(num) || fpclass == _FPCLASS_NN ||
            fpclass == _FPCLASS_ND || fpclass == _FPCLASS_NZ)
        *_errno() = EDOM;

    retval  = __ieee754_y1(num);
    if (_fpclass(retval) == _FPCLASS_NINF)
    {
        *_errno() = EDOM;
        retval = sqrt(-1);
    }
    return retval;
}
Ejemplo n.º 6
0
void test_infinity (FloatT inf, FloatT max, const char *tname)
{
    if (!std::numeric_limits<FloatT>::traps) {

        // infinity must be even greater than the maximum value
        rw_assert (inf > max, 0, __LINE__,
                   "numeric_limits<%s>::infinity() > "
                   "numeric_limits<%s>::max()", tname, tname);

        // multiplying infinity by anything other than 0.0 yields infinity
        rw_assert (inf == inf * inf, 0, __LINE__,
                   "numeric_limits<%s>::infinity()", tname);
    }

#ifdef _MSC_VER

    const int fpc = _fpclass (inf);
    rw_assert (_FPCLASS_PINF == fpc, 0, __LINE__,
               "_fpclass (numeric_limits<%s>::infinity()) == "
               "%d (_FPCLASS_PINF), got %d (%s)",
               tname, _FPCLASS_PINF, fpc, fpclass_name (fpc));

#elif defined (_RWSTD_OS_SUNOS)

    rw_assert (!finite (inf), 0, __LINE__,
               "finite (numeric_limits<%s>::infinity()) == 0, "
               "got non-zero", tname);

    const fpclass_t fpc = fpclass (inf);
    rw_assert (FP_PINF == fpclass (inf), 0, __LINE__,
               "fpclass (numeric_limits<%s>::infinity()) == %d (FP_PINF), "
               "got %d (%s)", tname, FP_PINF, fpc, fpclass_name (fpc));

#else

#  ifdef isinf

    rw_assert (isinf (inf), 0, __LINE__,
               "isinf (numeric_limits<%s>::infinity()) != 0, got 0",
               tname);

#  endif   // isinf

#  ifdef fpclassify

    const int fpc = fpclassify (inf);
    rw_assert (FP_INFINITE == fpc, 0, __LINE__,
               "fpclassify(numeric_limits<%s>::infinity()) == "
               "%d (FP_INFINITE), got %d (%s)", tname,
               FP_INFINITE, fpc, fpclass_name (fpc));

#  endif   // fpclassify

#endif

}
Ejemplo n.º 7
0
void print_dB(double v)
{
    int fpc = _fpclass(v);
    if (fpc == _FPCLASS_NINF)
        printf("    -INF");
    else if (fpc == _FPCLASS_PINF)
        printf("    +INF");
    else
        printf("%8.2f", v);
}
//ボール発射待機中の処理
void Standby_Update(Gamedata& gameData){
	gameData.intervalVisibleObjs["ready_logo"].Update();
	CharaObjs& balls = gameData.charaInfo.balls;
	CharaObjs& bars = gameData.charaInfo.bars;
	if( IsPressedOK() ){
		
		if(0 < bars.size() ){
			
			CharaObj ball;
			/*ball.p = bars[0].p;
			ball.p.y(ball.p.y() - 50);
			ball.pl.angle = 45;
			ball.pl.speed = BALL_FIRST_SPEED;	
			gameData.charaInfo.balls.push_back(ball);
			*/
			
			for(int i = 0; i < BALL_FIRST_N; i++){
				CharaObj ball;
				Polar pl;

				ball.p = bars[0].p;
				ball.p.y(ball.p.y() - 50);
				
				pl.speed = BALL_FIRST_SPEED;
				
				//割り算したときに0で割ってしまうのを防ぐ
				if(i == 0){
					pl.angle = BALL_FIRST_ANGLE_END - BALL_FIRST_ANGLE_BEGIN;
					ConvertPolarToCartesian(ball.v, pl);
					//ball.pl.angle = BALL_FIRST_ANGLE_END - BALL_FIRST_ANGLE_BEGIN;
				}
				else{
					pl.angle = (BALL_FIRST_ANGLE_END - BALL_FIRST_ANGLE_BEGIN) / static_cast<float>(i) + BALL_FIRST_ANGLE_BEGIN;
					ConvertPolarToCartesian(ball.v, pl);
					//ball.pl.angle = (BALL_FIRST_ANGLE_END - BALL_FIRST_ANGLE_BEGIN) / static_cast<float>(i) + BALL_FIRST_ANGLE_BEGIN;
				}

				int fp_state = _fpclass(pl.angle);

				if(fp_state == _FPCLASS_SNAN || fp_state == _FPCLASS_QNAN || fp_state == _FPCLASS_NINF || fp_state == _FPCLASS_PINF){
					throw std::runtime_error("Maybe, It diveded by 0.");
				}

				//ball.pl.speed = BALL_FIRST_SPEED;	
				
				gameData.charaInfo.balls.push_back(ball);
			}
			
			//ball.pl.angle = BALL_FIRST_ANGLE;
			//ball.pl.speed = BALL_FIRST_SPEED;	
		}
		gameData.sm = PLAYING;
	}
	UpdateBars(gameData);
}
Ejemplo n.º 9
0
int
gsl_isinf (const double x)
{
  int fpc = _fpclass(x);

  if (fpc == _FPCLASS_PINF)
    return +1;
  else if (fpc == _FPCLASS_NINF)
    return -1;
  else 
    return 0;
}
Ejemplo n.º 10
0
/* Returns -1 if value equals negative infinity, +1 if it is equal to
   positive infinity, or 0 if the number is not infinite.

   Note that on some systems, this method will always return 0
   (i.e. false positives).
*/
int
coin_isinf(double value)
{
#ifdef HAVE_ISINF
  return isinf(value);
#elif defined(HAVE_FPCLASS)
  if (fpclass(value) == FP_NINF) { return -1; }
  if (fpclass(value) == FP_PINF) { return +1; }
  return 0;
#elif defined(HAVE__FPCLASS)
  if (_fpclass(value) == _FPCLASS_NINF) { return -1; }
  if (_fpclass(value) == _FPCLASS_PINF) { return +1; }
  return 0;
#else
  /* FIXME: it might be possible to investigate the fp bits and decide
     in a portable manner whether or not they represent an infinite. A
     groups.google.com search turned up inconclusive. 20030919
     mortene. */
  return 0;
#endif
}
Ejemplo n.º 11
0
  void checkFinite(const double tmp) throw(std::range_error) {
    if (_finite(tmp)) {
      if(_isnan(tmp)) {
	    printf("ERROR: we have encountered a nan!\n");
      } else if (_fpclass(tmp) == _FPCLASS_PINF) {
	    printf("ERROR: we have encountered a pos inf!\n");
      } else {
	  	printf("ERROR: we have encountered a neg inf!\n");
      }
      const std::string s = "checkFinite()";
      throw std::range_error(s);
    }
  }
Ejemplo n.º 12
0
/* Returns 0 if the bitpattern of the \a value argument is not a valid
   floating point number, otherwise returns non-zero.

   Note that on some systems, this method will always return 0
   (i.e. false positives).
*/
int
coin_isnan(double value)
{
#ifdef HAVE_ISNAN
  return isnan(value);
#elif defined(HAVE__ISNAN)
  return _isnan(value);
#elif defined(HAVE_FPCLASS)
  if (fpclass(value) == FP_SNAN) { return 1; }
  if (fpclass(value) == FP_QNAN) { return 1; }
  return 0;
#elif defined(HAVE__FPCLASS)
  if (_fpclass(value) == _FPCLASS_SNAN) { return 1; }
  if (_fpclass(value) == _FPCLASS_QNAN) { return 1; }
  return 0;
#else
  /* FIXME: it might be possible to investigate the fp bits and decide
     in a portable manner whether or not they represent a NaN. A
     groups.google.com search turned up inconclusive. 20030919
     mortene. */
  return 0;
#endif
}
Ejemplo n.º 13
0
bool MgFeatureNumericFunctions::IsInf(double x)
{
    bool isInfinity = false;
#ifdef _WIN32
    int code = _fpclass(x);
    if ((code == _FPCLASS_NINF) || (code == _FPCLASS_PINF))
    {
        isInfinity = true;
    }
#else
    isInfinity = isinf(x);
#endif

    return isInfinity;
}
Ejemplo n.º 14
0
bool isPosInf(double d)
{
    // FIXME: should be HAVE(_FPCLASS)
#if PLATFORM(WIN_OS)
    return _FPCLASS_PINF == _fpclass(d);
#elif HAVE(FUNC_ISINF) && !PLATFORM(SOLARIS_OS)
    return (isinf(d) == 1);
#elif HAVE(FUNC_FINITE)
    return !finite(d) && d == d; // ### can we distinguish between + and - ?
#elif HAVE(FUNC__FINITE)
    return !_finite(d) && d == d; // ###
#else
    return false;
#endif
}
Ejemplo n.º 15
0
bool isNegInf(double d)
{
    // FIXME: should be HAVE(_FPCLASS)
#if PLATFORM(WIN_OS)
    return _FPCLASS_NINF == _fpclass(d);
#elif HAVE(FUNC_ISINF) && !PLATFORM(SOLARIS_OS)
    return (isinf(d) == -1);
#elif HAVE(FUNC_FINITE)
    return finite(d) == 0 && d == d; // ###
#elif HAVE(FUNC__FINITE)
    return _finite(d) == 0 && d == d; // ###
#else
    return false;
#endif
}
Ejemplo n.º 16
0
// FIXME: Merge with isinf in MathExtras.h and remove this one entirely.
bool isInf(double d)
{
    // FIXME: should be HAVE(_FPCLASS)
#if PLATFORM(WIN_OS)
    int fpClass = _fpclass(d);
    return _FPCLASS_PINF == fpClass || _FPCLASS_NINF == fpClass;
#elif HAVE(FUNC_ISINF) && !PLATFORM(SOLARIS_OS)
    return isinf(d);
#elif HAVE(FUNC_FINITE)
    return finite(d) == 0 && d == d;
#elif HAVE(FUNC__FINITE)
    return _finite(d) == 0 && d == d;
#else
    return false;
#endif
}
Ejemplo n.º 17
0
void checkZeroFinite(const double tmp) throw(std::range_error) {
    if ((tmp == 0.0) || (! _finite(tmp))) {
      if (tmp == 0.0) {
	    printf("ERROR: we have encountered a zero!\n");
      } else if(_isnan(tmp)) {
	    printf("ERROR: we have encountered a nan!\n");
      } else if (_fpclass(tmp) == _FPCLASS_PINF) {
        printf("ERROR: we have encountered a pos inf!\n");
      } else {
        printf("ERROR: we have encountered a neg inf!\n");
      }
      char sbuf[64];
      sprintf(sbuf, "checkZeroFinite: zero or indef exceeded: %g\n",
              tmp);
      throw std::range_error(sbuf);
    }
  }
Ejemplo n.º 18
0
void CStringEx::PutDoubleS(double value, int nsignificands)
{
	// Code From
	// Copyright SOCABIM 1999
	// Pierre Caussin
	// Jean-Paul Retru
	CString fmt;
	int nk;
	switch	(_fpclass(value))
		{
		case _FPCLASS_SNAN:
		case _FPCLASS_QNAN:
			Format("%s", m_csNAN); // "NaN"
			return;
		case _FPCLASS_NINF:
			Format("%s", m_csNINF);// "-Inf"
			return;
		case _FPCLASS_PINF:
			Format("%s", m_csPINF);// "+Inf"
			return;
		case _FPCLASS_NN:
		case _FPCLASS_PN:
			nk = (int)log10(fabs(value));
			if	(fabs(value)<1) nk--;
			if	(nk > nsignificands+1 || nk < 2-nsignificands)
				{
				fmt.Format("%%.%dfE%d",nsignificands-1,nk);
				Format(fmt,value/pow(10.,nk));
				}
			else
				{
				fmt.Format("%%.%df",nsignificands>nk+1?nsignificands-nk-1:0);
				Format(fmt,value);
				}
			return;
		default:
			fmt.Format("%%.%df",nsignificands);
			Format(fmt,0.);
	}
	int acc = 16;
	Accuracy(acc);
	return;
}
Ejemplo n.º 19
0
void CStringEx::PutDouble(double f, int len)
{
	switch	(_fpclass(f))
	{
		case _FPCLASS_SNAN:
		case _FPCLASS_QNAN:
			Format("%s", m_csNAN); // "NaN"
			return;
		case _FPCLASS_NINF:
			Format("%s", m_csNINF);// "-Inf"
			return;
		case _FPCLASS_PINF:
			Format("%s", m_csPINF);// "+Inf"
			return;
	}
	dtoan(GetBuffer(len),f,len);
	ReleaseBuffer(len);
	// have we exceeded our acuracy?
	int acc = 16;
	if(len< acc+1) return;
	Accuracy(acc);
}
Ejemplo n.º 20
0
	int fpclassify(double x)
	{
		int result = FP_NORMAL;
		switch (_fpclass(x)) {
		case _FPCLASS_SNAN:  
		case _FPCLASS_QNAN:  
			result = FP_NAN;
			break;
		case _FPCLASS_NINF:  
		case _FPCLASS_PINF:  
			result = FP_INFINITE;
			break;
		case _FPCLASS_NZ: 
		case _FPCLASS_PZ:  
			result = FP_ZERO;
			break;
		case _FPCLASS_ND:  
		case _FPCLASS_PD: 
			result = FP_SUBNORMAL;
			break;
		}
		return result;
	}
Ejemplo n.º 21
0
int IsInf(double x)
{
#ifdef _MSC_VER  //doesn't have isinf
    int cls = _fpclass(x);
    if(cls == _FPCLASS_PINF) return 1;
    else if(cls == _FPCLASS_NINF) return -1;
    else return 0;
#elif HAVE_DECL_ISINF
    if(isinf(x)) {
        if(x > 0) return 1;
        else return -1;
    }
    else return 0;
#elif HAVE_IEEE_COMPARISONS
    double y=x-x;
    if(IsNaN(y))
        return (x>0?1:-1);
    else return 0;
#else
#error "IsInf: Neither Microsoft's _fpclass, isinf, or IEEE comparisons defined"
    return 0;
#endif
}
Ejemplo n.º 22
0
BOOL IsFloatValid(float f)
{
#ifdef _WIN32
    int lnResult = _fpclass(f);
    switch (lnResult)
    {
    case _FPCLASS_SNAN:
    case _FPCLASS_QNAN:
    case _FPCLASS_NINF:
    case _FPCLASS_ND:
    case _FPCLASS_PD:
    case _FPCLASS_PINF:
        return FALSE;
        break;
    default:
        return TRUE;
    }
#else

    return TRUE;

#endif // _WIN32

}
Ejemplo n.º 23
0
/*
#ifndef _ieeemisc_.obj
int __cdecl _fpclassf (float x) {
   return _fpclass(double(x));
}
#else
extern int __cdecl _fpclassf (float);
#endif
*/
int __cdecl _fpclassf (float x) {
   return _fpclass(double(x));
}
Ejemplo n.º 24
0
int __cdecl __fpclassify (float x) {
   return _fpclass(double(x));
}
Ejemplo n.º 25
0
inline bool _Stl_is_neg_inf(double x)    { return _fpclass(x) == _FPCLASS_NINF; }
Ejemplo n.º 26
0
inline bool _Stl_is_inf(double x)        { 
  int fclass = _fpclass(x); 
  return fclass == _FPCLASS_NINF || fclass == _FPCLASS_PINF; 
}
Ejemplo n.º 27
0
inline int _fpclass (long double val)
{
    return _fpclass (double (val));
}
Ejemplo n.º 28
0
void test_signaling_NaN (FloatT snan, FloatT snan2, const char *tname)
{
    // NAN never compares equal to self or any other number
    rw_assert (!(snan == snan2), 0, __LINE__,
               "numeric_limits<%s>::signaling_NaN() != "
               "numeric_limits<%1$s>::signaling_NaN()",
               tname);

    const FloatT inf = std::numeric_limits<FloatT>::infinity ();

    rw_assert (!(snan == inf), 0, __LINE__,
               "numeric_limits<%s>::signaling_NaN() != "
               "numeric_limits<%1$s>::infinity()",
                tname);

    rw_assert (!(snan == -inf), 0, __LINE__,
               "numeric_limits<%s>::signaling_NaN() != "
               "-numeric_limits<%1$s>::infinity()",
               tname);

#ifdef _MSC_VER

    rw_assert (0 != _isnan (snan), 0, __LINE__,
               "_isnan (numeric_limits<%s>::signaling_NaN()) != 0, got 0",
               tname);

    const int fpc = _fpclass (snan);
    rw_assert (_FPCLASS_SNAN == fpc, 0, __LINE__,
               "_fpclass(numeric_limits<%s>::signaling_NaN()) == "
               "%d (_FPCLASS_SNAN), got %d (%s)",
               tname, _FPCLASS_SNAN, fpc, fpclass_name (fpc));

#elif defined (_RWSTD_OS_SUNOS)

    rw_assert (!finite (snan), 0, __LINE__,
               "finite(numeric_limits<%s>::signaling_NaN()) == 0, "
               "got non-zero", tname);

    const fpclass_t fpc = fpclass (snan);
    rw_assert (FP_SNAN == fpc, 0, __LINE__,
               "fpclass(numeric_limits<%s>::signaling_NaN()) == %d "
               "(FP_SNAN), got %d (%s)", tname,
               FP_SNAN, fpc, fpclass_name (fpc));
#else

#  ifdef isnan

    rw_assert (0 != isnan (snan), 0, __LINE__,
               "isnan(numeric_limits<%s>::signaling_NaN()) != 0, got 0",
               tname);

#  endif   // isnan

#  ifdef fpclassify

    const int fpc = fpclassify (snan);
    rw_assert (FP_NAN == fpc, 0, __LINE__,
               "fpclassify(numeric_limits<%s>::signaling_NaN()) == "
               "%d (FP_NAN), got %d (%s)", tname,
               FP_NAN, fpc, fpclass_name (fpc));

#  endif   // fpclassify

#endif

}
Ejemplo n.º 29
0
/*************************************************************************
 * trio_isinf
 */
TRIO_PUBLIC int
trio_isinf(TRIO_VOLATILE double number)
{
#if defined(TRIO_COMPILER_DECC)
  /*
   * DECC has an isinf() macro, but it works differently than that
   * of C99, so we use the fp_class() function instead.
   */
  return ((fp_class(number) == FP_POS_INF)
	  ? 1
	  : ((fp_class(number) == FP_NEG_INF) ? -1 : 0));
  
#elif defined(isinf)
  /*
   * C99 defines isinf() as a macro.
   */
  return isinf(number);
  
#elif defined(TRIO_COMPILER_MSVC)
  /*
   * MSVC has an _fpclass() function that can be used to detect infinity.
   */
  return ((_fpclass(number) == _FPCLASS_PINF)
	  ? 1
	  : ((_fpclass(number) == _FPCLASS_NINF) ? -1 : 0));

#elif defined(USE_IEEE_754)
  /*
   * Examine IEEE 754 bit-pattern. Infinity must have a special exponent
   * pattern, and an empty mantissa.
   */
  int has_mantissa;
  int is_special_quantity;

  is_special_quantity = trio_is_special_quantity(number, &has_mantissa);
  
  return (is_special_quantity && !has_mantissa)
    ? ((number < 0.0) ? -1 : 1)
    : 0;

#else
  /*
   * Fallback solution.
   */
  int status;
  
# if defined(TRIO_PLATFORM_UNIX)
  void (*signal_handler)(int) = signal(SIGFPE, SIG_IGN);
# endif
  
  double infinity = trio_pinf();
  
  status = ((number == infinity)
	    ? 1
	    : ((number == -infinity) ? -1 : 0));
  
# if defined(TRIO_PLATFORM_UNIX)
  signal(SIGFPE, signal_handler);
# endif
  
  return status;
  
#endif
}
Ejemplo n.º 30
0
int __cdecl _fpclassl (long double x) {
   return _fpclass(double(x));
}