Changeset View
Changeset View
Standalone View
Standalone View
libraries/source/spidermonkey/include-win32-debug/mozilla/Decimal.h
Show All 24 Lines | |||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
*/ | */ | ||||
/** | /** | ||||
* Imported from: | * Imported from: | ||||
* http://src.chromium.org/viewvc/blink/trunk/Source/core/platform/Decimal.h | * https://chromium.googlesource.com/chromium/src.git/+/master/third_party/WebKit/Source/platform/Decimal.h | ||||
* Check hg log for the svn rev of the last update from Blink core. | * Check UPSTREAM-GIT-SHA for the commit ID of the last update from Blink core. | ||||
*/ | */ | ||||
#ifndef Decimal_h | #ifndef Decimal_h | ||||
#define Decimal_h | #define Decimal_h | ||||
#include "mozilla/Assertions.h" | #include "mozilla/Assertions.h" | ||||
#include <stdint.h> | #include <stdint.h> | ||||
#include "mozilla/Types.h" | #include "mozilla/Types.h" | ||||
#include <string> | #include <string> | ||||
#ifndef ASSERT | #ifndef ASSERT | ||||
#define DEFINED_ASSERT_FOR_DECIMAL_H 1 | #define DEFINED_ASSERT_FOR_DECIMAL_H 1 | ||||
#define ASSERT MOZ_ASSERT | #define ASSERT MOZ_ASSERT | ||||
#endif | #endif | ||||
// To use WTF_MAKE_FAST_ALLOCATED we'd need: | #define PLATFORM_EXPORT | ||||
// http://src.chromium.org/viewvc/blink/trunk/Source/wtf/FastMalloc.h | |||||
// To use USING_FAST_MALLOC we'd need: | |||||
// https://chromium.googlesource.com/chromium/src.git/+/master/third_party/WebKit/Source/wtf/Allocator.h | |||||
// Since we don't allocate Decimal objects, no need. | // Since we don't allocate Decimal objects, no need. | ||||
#define WTF_MAKE_FAST_ALLOCATED \ | #define USING_FAST_MALLOC(type) \ | ||||
void ignore_this_dummy_method() = delete | void ignore_this_dummy_method() = delete | ||||
namespace WebCore { | #define DISALLOW_NEW() \ | ||||
private: \ | |||||
void* operator new(size_t) = delete; \ | |||||
void* operator new(size_t, void*) = delete; \ | |||||
public: | |||||
namespace blink { | |||||
namespace DecimalPrivate { | namespace DecimalPrivate { | ||||
class SpecialValueHandler; | class SpecialValueHandler; | ||||
} // namespace DecimalPrivate | } | ||||
// This class represents decimal base floating point number. | // This class represents decimal base floating point number. | ||||
// | // | ||||
// FIXME: Once all C++ compiler support decimal type, we should replace this | // FIXME: Once all C++ compiler support decimal type, we should replace this | ||||
// class to compiler supported one. See below URI for current status of decimal | // class to compiler supported one. See below URI for current status of decimal | ||||
// type for C++: // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1977.html | // type for C++: // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1977.html | ||||
class Decimal { | class PLATFORM_EXPORT Decimal { | ||||
WTF_MAKE_FAST_ALLOCATED; | USING_FAST_MALLOC(Decimal); | ||||
public: | public: | ||||
enum Sign { | enum Sign { | ||||
Positive, | Positive, | ||||
Negative, | Negative, | ||||
}; | }; | ||||
// You should not use EncodedData other than unit testing. | // You should not use EncodedData other than unit testing. | ||||
class EncodedData { | class EncodedData { | ||||
DISALLOW_NEW(); | |||||
// For accessing FormatClass. | // For accessing FormatClass. | ||||
friend class Decimal; | friend class Decimal; | ||||
friend class DecimalPrivate::SpecialValueHandler; | friend class DecimalPrivate::SpecialValueHandler; | ||||
public: | public: | ||||
EncodedData(Sign, int exponent, uint64_t coefficient); | EncodedData(Sign, int exponent, uint64_t coefficient); | ||||
bool operator==(const EncodedData&) const; | bool operator==(const EncodedData&) const; | ||||
bool operator!=(const EncodedData& another) const { return !operator==(another); } | bool operator!=(const EncodedData& another) const { return !operator==(another); } | ||||
uint64_t coefficient() const { return m_coefficient; } | uint64_t coefficient() const { return m_coefficient; } | ||||
int countDigits() const; | int countDigits() const; | ||||
int exponent() const { return m_exponent; } | int exponent() const { return m_exponent; } | ||||
bool isFinite() const { return !isSpecial(); } | bool isFinite() const { return !isSpecial(); } | ||||
bool isInfinity() const { return m_formatClass == ClassInfinity; } | bool isInfinity() const { return m_formatClass == ClassInfinity; } | ||||
bool isNaN() const { return m_formatClass == ClassNaN; } | bool isNaN() const { return m_formatClass == ClassNaN; } | ||||
bool isSpecial() const { return m_formatClass == ClassInfinity || m_formatClass == ClassNaN; } | bool isSpecial() const { return m_formatClass == ClassInfinity || m_formatClass == ClassNaN; } | ||||
bool isZero() const { return m_formatClass == ClassZero; } | bool isZero() const { return m_formatClass == ClassZero; } | ||||
Sign sign() const { return m_sign; } | Sign sign() const { return m_sign; } | ||||
void setSign(Sign aSign) { m_sign = aSign; } | void setSign(Sign sign) { m_sign = sign; } | ||||
private: | private: | ||||
enum FormatClass { | enum FormatClass { | ||||
ClassInfinity, | ClassInfinity, | ||||
ClassNormal, | ClassNormal, | ||||
ClassNaN, | ClassNaN, | ||||
ClassZero, | ClassZero, | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | public: | ||||
bool isInfinity() const { return m_data.isInfinity(); } | bool isInfinity() const { return m_data.isInfinity(); } | ||||
bool isNaN() const { return m_data.isNaN(); } | bool isNaN() const { return m_data.isNaN(); } | ||||
bool isNegative() const { return sign() == Negative; } | bool isNegative() const { return sign() == Negative; } | ||||
bool isPositive() const { return sign() == Positive; } | bool isPositive() const { return sign() == Positive; } | ||||
bool isSpecial() const { return m_data.isSpecial(); } | bool isSpecial() const { return m_data.isSpecial(); } | ||||
bool isZero() const { return m_data.isZero(); } | bool isZero() const { return m_data.isZero(); } | ||||
MFBT_API Decimal abs() const; | MFBT_API Decimal abs() const; | ||||
MFBT_API Decimal ceiling() const; | MFBT_API Decimal ceil() const; | ||||
MFBT_API Decimal floor() const; | MFBT_API Decimal floor() const; | ||||
MFBT_API Decimal remainder(const Decimal&) const; | MFBT_API Decimal remainder(const Decimal&) const; | ||||
MFBT_API Decimal round() const; | MFBT_API Decimal round() const; | ||||
MFBT_API double toDouble() const; | MFBT_API double toDouble() const; | ||||
// Note: toString method supports infinity and nan but fromString not. | // Note: toString method supports infinity and nan but fromString not. | ||||
MFBT_API std::string toString() const; | MFBT_API std::string toString() const; | ||||
MFBT_API bool toString(char* strBuf, size_t bufLength) const; | MFBT_API bool toString(char* strBuf, size_t bufLength) const; | ||||
Show All 28 Lines | private: | ||||
static MFBT_API AlignedOperands alignOperands(const Decimal& lhs, const Decimal& rhs); | static MFBT_API AlignedOperands alignOperands(const Decimal& lhs, const Decimal& rhs); | ||||
static inline Sign invertSign(Sign sign) { return sign == Negative ? Positive : Negative; } | static inline Sign invertSign(Sign sign) { return sign == Negative ? Positive : Negative; } | ||||
Sign sign() const { return m_data.sign(); } | Sign sign() const { return m_data.sign(); } | ||||
EncodedData m_data; | EncodedData m_data; | ||||
}; | }; | ||||
} // namespace WebCore | } // namespace blink | ||||
namespace mozilla { | namespace mozilla { | ||||
typedef WebCore::Decimal Decimal; | typedef blink::Decimal Decimal; | ||||
} // namespace mozilla | } // namespace mozilla | ||||
#undef WTF_MAKE_FAST_ALLOCATED | #undef USING_FAST_MALLOC | ||||
#ifdef DEFINED_ASSERT_FOR_DECIMAL_H | #ifdef DEFINED_ASSERT_FOR_DECIMAL_H | ||||
#undef DEFINED_ASSERT_FOR_DECIMAL_H | #undef DEFINED_ASSERT_FOR_DECIMAL_H | ||||
#undef ASSERT | #undef ASSERT | ||||
#endif | #endif | ||||
#endif // Decimal_h | #endif // Decimal_h | ||||
Wildfire Games · Phabricator