Пример #1
0
	bool AxisAlignedBox::contains(const Vector3& v) const
	{
		if (isNull())
			return false;
		if (isInfinite())
			return true;

		return mMinimum.x <= v.x && v.x <= mMaximum.x &&
			mMinimum.y <= v.y && v.y <= mMaximum.y &&
			mMinimum.z <= v.z && v.z <= mMaximum.z;
	}
Пример #2
0
 // Inlined on other architectures
 double MathUtils::exp(double value)
 {
     switch (isInfinite(value)) {
     case 1:
         return kInfinity;
     case -1:
         return +0;
     default:
         return expInternal(value);
     }
 }
Пример #3
0
		static inline double ulp(double const & x)
		{
			if (isInfinite(x))
			{
				return POS_INFTY();
			}
			else if (isNaN(x))
			{
				return x;
			}
			else
			{
				a_diee ulpx;
				ulpx.f = x;
				ulpx.ieee.sign = 0;

				/**
				 * x is zero or denormalized
				 **/
				if (ulpx.ieee.expo == 0)
				{
					ulpx.ieee.mant0 = 0;
					ulpx.ieee.mant1 = 1;
					return ulpx.f;
				}
				/**
				 * non-underflow case
				 **/
				else if (ulpx.ieee.expo > 52)
				{
					ulpx.ieee.expo -= 52;
					ulpx.ieee.mant0 = 0;
					ulpx.ieee.mant1 = 0;
					return ulpx.f;
				}
				/**
				 * underflow case
				 **/
				else
				{
					unsigned int n = 52-ulpx.ieee.expo;
					ulpx.ieee.expo = 0;
					if (n < 20)
					{
						ulpx.ieee.mant0 = (0x80000 >> n);
						ulpx.ieee.mant1 = 0;
					}
					else
					{
						ulpx.ieee.mant0 = 0;
						ulpx.ieee.mant1 = (0x80000000 >> (n-20));
					}
					return ulpx.f;
				}
Пример #4
0
Cardinality::CardinalityComparison Cardinality::compare(const Cardinality& c) const throw() {
  if(isUnknown() || c.isUnknown()) {
    return UNKNOWN;
  } else if(isLargeFinite()) {
    if(c.isLargeFinite()) {
      return UNKNOWN;
    } else if(c.isFinite()) {
        return GREATER;
    } else {
      Assert(c.isInfinite());
      return LESS;
    }
  } else if(c.isLargeFinite()) {
    if(isLargeFinite()) {
      return UNKNOWN;
    } else if(isFinite()) {
      return LESS;
    } else {
      Assert(isInfinite());
      return GREATER;
    }
  } else if(isInfinite()) {
    if(c.isFinite()) {
      return GREATER;
    } else {
      return d_card < c.d_card ? GREATER :
               (d_card == c.d_card ? EQUAL : LESS);
    }
  } else if(c.isInfinite()) {
    Assert(isFinite());
    return LESS;
  } else {
    Assert(isFinite() && !isLargeFinite());
    Assert(c.isFinite() && !c.isLargeFinite());
    return d_card < c.d_card ? LESS :
             (d_card == c.d_card ? EQUAL : GREATER);
  }

  Unreachable();
}
Пример #5
0
    double MathUtils::exp(double value)
    {
#ifdef X86_MATH
        switch (isInfinite(value)) {
        case 1:
            return kInfinity;
        case -1:
            return +0;
        default:
            return expInternal(value);
        }
#else
        return ::exp(value);
#endif /* X86_MATH */
    }
Пример #6
0
bool Event::isCompleted()
{
    if(!isStarted())
    {
        return true;
    }

    if(isInfinite())
    {
        return false;
    }

    unsigned long end = _start + _duration;
    bool completed = end < _pClock->getCurrent();
    if(completed)
    {
        _start = EVENT_STOPPED;
    }

    return completed;
}
Пример #7
0
Timestamp::operator bool() const
{
    return !isInfinite();
}
Пример #8
0
double
DigitList::getDouble() const
{
    // TODO:  fix thread safety.  Can probably be finessed some by analyzing
    //        what public const functions can see which DigitLists.
    //        Like precompute fDouble for DigitLists coming in from a parse
    //        or from a Formattable::set(), but not for any others.
    if (fHaveDouble) {
        return fDouble;
    }
    DigitList *nonConstThis = const_cast<DigitList *>(this);

    if (gDecimal == 0) {
        char rep[MAX_DIGITS];
        // For machines that decide to change the decimal on you,
        // and try to be too smart with localization.
        // This normally should be just a '.'.
        sprintf(rep, "%+1.1f", 1.0);
        gDecimal = rep[2];
    }

    if (isZero()) {
        nonConstThis->fDouble = 0.0;
        if (decNumberIsNegative(fDecNumber)) {
            nonConstThis->fDouble /= -1;
        }
    } else if (isInfinite()) {
        // BEGIN android-changed
        // There is no numeric_limits template member in Android std.
        nonConstThis->fDouble = INFINITY;
        /*
        if (std::numeric_limits<double>::has_infinity) {
            nonConstThis->fDouble = std::numeric_limits<double>::infinity();
        } else {
            nonConstThis->fDouble = std::numeric_limits<double>::max();
        }
        */
        // END android-changed
       
        if (!isPositive()) {
            nonConstThis->fDouble = -fDouble;
        } 
    } else {
        MaybeStackArray<char, MAX_DBL_DIGITS+18> s;
           // Note:  14 is a  magic constant from the decNumber library documentation,
           //        the max number of extra characters beyond the number of digits 
           //        needed to represent the number in string form.  Add a few more
           //        for the additional digits we retain.

        // Round down to appx. double precision, if the number is longer than that.
        // Copy the number first, so that we don't modify the original.
        if (getCount() > MAX_DBL_DIGITS + 3) {
            DigitList numToConvert(*this);
            numToConvert.reduce();    // Removes any trailing zeros, so that digit count is good.
            numToConvert.round(MAX_DBL_DIGITS+3);
            uprv_decNumberToString(numToConvert.fDecNumber, s);
            // TODO:  how many extra digits should be included for an accurate conversion?
        } else {
            uprv_decNumberToString(this->fDecNumber, s);
        }
        U_ASSERT(uprv_strlen(&s[0]) < MAX_DBL_DIGITS+18);
        
        if (gDecimal != '.') {
            char *decimalPt = strchr(s, '.');
            if (decimalPt != NULL) {
                *decimalPt = gDecimal;
            }
        }
        char *end = NULL;
        nonConstThis->fDouble = uprv_strtod(s, &end);
    }
    nonConstThis->fHaveDouble = TRUE;
    return fDouble;
}
Пример #9
0
TEST(GTestMath, TestIsInfinite) {
    ASSERT_TRUE(isInfinite(POSITIVE_INFINITY));
    ASSERT_TRUE(isInfinite(NEGATIVE_INFINITY));
    ASSERT_FALSE(isInfinite(1.0));
}
Пример #10
0
/**
 * Currently, getDouble() depends on strtod() to do its conversion.
 *
 * WARNING!!
 * This is an extremely costly function. ~1/2 of the conversion time
 * can be linked to this function.
 */
double
DigitList::getDouble() const
{
    static char gDecimal = 0;
    char decimalSeparator;
    {
        Mutex mutex;
        if (fHave == kDouble) {
            return fUnion.fDouble;
        } else if(fHave == kInt64) {
            return (double)fUnion.fInt64;
        }
        decimalSeparator = gDecimal;
    }

    if (decimalSeparator == 0) {
        // We need to know the decimal separator character that will be used with strtod().
        // Depends on the C runtime global locale.
        // Most commonly is '.'
        // TODO: caching could fail if the global locale is changed on the fly.
        char rep[MAX_DIGITS];
        sprintf(rep, "%+1.1f", 1.0);
        decimalSeparator = rep[2];
    }

    double tDouble = 0.0;
    if (isZero()) {
        tDouble = 0.0;
        if (decNumberIsNegative(fDecNumber)) {
            tDouble /= -1;
        }
    } else if (isInfinite()) {
        if (std::numeric_limits<double>::has_infinity) {
            tDouble = std::numeric_limits<double>::infinity();
        } else {
            tDouble = std::numeric_limits<double>::max();
        }
        if (!isPositive()) {
            tDouble = -tDouble; //this was incorrectly "-fDouble" originally.
        } 
    } else {
        MaybeStackArray<char, MAX_DBL_DIGITS+18> s;
           // Note:  14 is a  magic constant from the decNumber library documentation,
           //        the max number of extra characters beyond the number of digits 
           //        needed to represent the number in string form.  Add a few more
           //        for the additional digits we retain.

        // Round down to appx. double precision, if the number is longer than that.
        // Copy the number first, so that we don't modify the original.
        if (getCount() > MAX_DBL_DIGITS + 3) {
            DigitList numToConvert(*this);
            numToConvert.reduce();    // Removes any trailing zeros, so that digit count is good.
            numToConvert.round(MAX_DBL_DIGITS+3);
            uprv_decNumberToString(numToConvert.fDecNumber, s);
            // TODO:  how many extra digits should be included for an accurate conversion?
        } else {
            uprv_decNumberToString(this->fDecNumber, s);
        }
        U_ASSERT(uprv_strlen(&s[0]) < MAX_DBL_DIGITS+18);
        
        if (decimalSeparator != '.') {
            char *decimalPt = strchr(s, '.');
            if (decimalPt != NULL) {
                *decimalPt = decimalSeparator;
            }
        }
        char *end = NULL;
        tDouble = uprv_strtod(s, &end);
    }
    {
        Mutex mutex;
        DigitList *nonConstThis = const_cast<DigitList *>(this);
        nonConstThis->internalSetDouble(tDouble);
        gDecimal = decimalSeparator;
    }
    return tDouble;
}
Пример #11
0
double iterateMarginalsAt(int row, int col, double *negLogLikelihood, double *probs, int nrows, int ncols, 
                        int nclasses, double lambdaParam, double mu, double *N, double *D, double *prev){
    double *v=&negLogLikelihood[nclasses*(row*ncols+col)];
    for(int k=0;k<nclasses;++k){
        if(v[k]<EPSILON){
            double mse=0;
            double *p=&probs[nclasses*(row*ncols+col)];
            for(int i=0;i<nclasses;++i){
                if(i==k){
                    mse+=(p[i]-1)*(p[i]-1);
                    p[i]=1;
                }else{
                    mse+=(p[i]*p[i]);
                    p[i]=0;
                }
            }
            return mse/nclasses;
        }
        double num=0;
        int cnt=0;
        for(int n=0;n<NEIGH_SIZE;++n){
            int rr=row+dRow[n];
            int cc=col+dCol[n];
            if((rr<0)||(cc<0)||(rr>=nrows)||(cc>=ncols)){
                continue;
            }
            double *p=&probs[nclasses*(rr*ncols+cc)];
            num+=p[k];
            ++cnt;
        }
        N[k]=lambdaParam*num;
        if(isInfinite(v[k])){
            D[k]=INF64;
        }else{
            D[k]=v[k] - mu + lambdaParam*cnt;
        }
    }
    double sNum=0, sDen=0;
    for(int k=0;k<nclasses;k++){
        if(!isInfinite(D[k])){
            sNum+=N[k]/D[k];
            sDen+=1.0/D[k];
        }
    }
    double *p=&probs[nclasses*(row*ncols+col)];
    memcpy(prev, p, sizeof(double)*nclasses);
    double ss=0;
    for(int k=0;k<nclasses;k++){
        if(isInfinite(D[k])){
            p[k]=0;
            continue;
        }
        p[k]=(1-sNum)/(D[k]*sDen) + N[k]/D[k];
        if(p[k]<0){
            p[k]=0;
        }            
        if(p[k]>1){
            p[k]=1;
        }
        ss+=p[k];
    }
    double mse=0;
    for(int k=0;k<nclasses;k++){
        p[k]/=ss;
        mse+=(p[k]-prev[k])*(p[k]-prev[k]);
    }
    return mse/nclasses;
}
Пример #12
0
		static inline bool isRegular(double const & x)
		{
			return !(isInfinite(x) || isNaN(x));
		}
Пример #13
0
/*
 * Converts the value of the given double to a String, and places
 * The result into the destination String.
 * @return the given dest string
 */
void Double::toString(double aValue, nsAString& aDest)
{

    // check for special cases

    if (isNaN(aValue)) {
        aDest.AppendLiteral("NaN");
        return;
    }
    if (isInfinite(aValue)) {
        if (aValue < 0)
            aDest.Append(PRUnichar('-'));
        aDest.AppendLiteral("Infinity");
        return;
    }

    // Mantissa length is 17, so this is plenty
    const int buflen = 20;
    char buf[buflen];

    PRIntn intDigits, sign;
    char* endp;
    PR_dtoa(aValue, 0, 0, &intDigits, &sign, &endp, buf, buflen - 1);

    // compute length
    PRInt32 length = endp - buf;
    if (length > intDigits) {
        // decimal point needed
        ++length;
        if (intDigits < 1) {
            // leading zeros, -intDigits + 1
            length += 1 - intDigits;
        }
    }
    else {
        // trailing zeros, total length given by intDigits
        length = intDigits;
    }
    if (aValue < 0)
        ++length;
    // grow the string
    PRUint32 oldlength = aDest.Length();
    if (!EnsureStringLength(aDest, oldlength + length))
        return; // out of memory
    nsAString::iterator dest;
    aDest.BeginWriting(dest).advance(PRInt32(oldlength));
    if (aValue < 0) {
        *dest = '-'; ++dest;
    }
    int i;
    // leading zeros
    if (intDigits < 1) {
        *dest = '0'; ++dest;
        *dest = '.'; ++dest;
        for (i = 0; i > intDigits; --i) {
            *dest = '0'; ++dest;
        }
    }
    // mantissa
    int firstlen = PR_MIN(intDigits, endp - buf);
    for (i = 0; i < firstlen; i++) {
        *dest = buf[i]; ++dest;
    }
    if (i < endp - buf) {
        if (i > 0) {
            *dest = '.'; ++dest;
        }
        for (; i < endp - buf; i++) {
            *dest = buf[i]; ++dest;
        }
    }
    // trailing zeros
    for (; i < intDigits; i++) {
        *dest = '0'; ++dest;
    }
}
Пример #14
0
/*PLONK_INLINE_LOW*/ bool TimeStamp::isFinite() const throw()
{
    return ! isInfinite();
}
Пример #15
0
					inline std::string getUsageStr() const override
					{
						return "(PACK " + getName() + " " + "[" + toStr(min) + "/" + (isInfinite() ? "..." : toStr(max)) + "])";
					}