Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions | Static Public Attributes
txDouble Class Reference

Utility class for doubles. More...

#include <txCore.h>

List of all members.

Static Public Member Functions

static PRBool isInfinite (double aDbl)
 Determines whether the given double represents positive or negative inifinity.
static PRBool isNaN (double aDbl)
 Determines whether the given double is NaN.
static PRBool isNeg (double aDbl)
 Determines whether the given double is negative.
static void toString (double aValue, nsAString &aDest)
 Converts the value of the given double to a string, and appends the result to the destination string.
static double toDouble (const nsAString &aStr)
 Converts the given String to a double, if the string value does not represent a double, NaN will be returned.

Static Public Attributes

static const double NaN = *((double*)nanMask)
 Useful constants.
static const double POSITIVE_INFINITY = *((double*)infMask)
static const double NEGATIVE_INFINITY = *((double*)negInfMask)

Detailed Description

Utility class for doubles.

Definition at line 62 of file txCore.h.


Member Function Documentation

MBool Double::isInfinite ( double  aDbl) [static]

Determines whether the given double represents positive or negative inifinity.

Definition at line 139 of file Double.cpp.

Here is the caller graph for this function:

MBool Double::isNaN ( double  aDbl) [static]

Determines whether the given double is NaN.

Definition at line 148 of file Double.cpp.

{
    return ((TX_DOUBLE_HI32(aDbl) & TX_DOUBLE_HI32_EXPMASK) == TX_DOUBLE_HI32_EXPMASK &&
            (TX_DOUBLE_LO32(aDbl) || (TX_DOUBLE_HI32(aDbl) & TX_DOUBLE_HI32_MANTMASK)));
}

Here is the caller graph for this function:

MBool Double::isNeg ( double  aDbl) [static]

Determines whether the given double is negative.

Definition at line 157 of file Double.cpp.

{
    return (TX_DOUBLE_HI32(aDbl) & TX_DOUBLE_HI32_SIGNBIT) != 0;
}
double Double::toDouble ( const nsAString &  aStr) [static]

Converts the given String to a double, if the string value does not represent a double, NaN will be returned.

Definition at line 267 of file Double.cpp.

{
    txStringToDouble sink;
    nsAString::const_iterator fromBegin, fromEnd;
    copy_string(aSrc.BeginReading(fromBegin), aSrc.EndReading(fromEnd), sink);
    return sink.getDouble();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Double::toString ( double  aValue,
nsAString &  aDest 
) [static]

Converts the value of the given double to a string, and appends the result to the destination string.

Definition at line 280 of file Double.cpp.

{

    // 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;
    }
}

Here is the call graph for this function:


Member Data Documentation

const double Double::NaN = *((double*)nanMask) [static]

Useful constants.

Definition at line 68 of file txCore.h.

const double Double::NEGATIVE_INFINITY = *((double*)negInfMask) [static]

Definition at line 70 of file txCore.h.

const double Double::POSITIVE_INFINITY = *((double*)infMask) [static]

Definition at line 69 of file txCore.h.


The documentation for this class was generated from the following files: