From 940e1733347c8cd0e626669bb9f3f1ac3e39d5d4 Mon Sep 17 00:00:00 2001 From: Tom Lint Date: Wed, 9 Oct 2013 11:52:41 +0200 Subject: [PATCH] Added Is* methods to Double Updated CultureInfo Added MidpointRounding_t enum Updated file comments --- include/System/Double.h | 3 ++ include/System/Enums.h | 33 +++++++++++++++++----- include/System/Globalization/CultureInfo.h | 17 ++++++++++- src/libmscorlib/Double.cpp | 21 ++++++++++++-- 4 files changed, 63 insertions(+), 11 deletions(-) diff --git a/include/System/Double.h b/include/System/Double.h index e0d53ef..5101c3d 100644 --- a/include/System/Double.h +++ b/include/System/Double.h @@ -36,6 +36,9 @@ namespace System int CompareTo(const Double other) const; bool Equals(const Double other) const; int GetHashCode() const; + static bool IsNaN(const Double& d); + static bool IsNegativeInfinity(const Double& d); + static bool IsPositiveInfinity(const Double& d); static const Type& GetType(); const String ToString() const; static const String ToString(const double value); diff --git a/include/System/Enums.h b/include/System/Enums.h index 204e02c..3fbaffd 100644 --- a/include/System/Enums.h +++ b/include/System/Enums.h @@ -1,10 +1,12 @@ -/**************************************************************** - * Enums.h * - * Defines enumerations used in the System namespace * - * * - * Enumerations are defined inside structs to prevent * - * namespace pollution, and easier distinction. * - ****************************************************************/ +/***************************************************************************** + * Enums.h * + * Defines enumerations used in the System namespace * + * * + * Enumerations are defined inside structs to prevent * + * namespace pollution, and easier distinction. * + * * + * Copyright (c) XFX Team. All rights reserved. * + *****************************************************************************/ #ifndef _SYSTEM_ENUMS_ #define _SYSTEM_ENUMS_ @@ -37,6 +39,22 @@ namespace System }; }; + // Specifies how mathematical rounding methods should process a number that is midway between two numbers. + struct MidpointRounding + { + enum type + { + /** + * When a number is halfway between two others, it is rounded toward the nearest even number. + */ + ToEven, + /** + * When a number is halfway between two others, it is rounded toward the nearest number that is away from zero. + */ + AwayFromZero + }; + }; + // Identifies the operating system, or platform, supported by an assembly. struct PlatformID { @@ -160,6 +178,7 @@ namespace System typedef DateTimeKind::type DateTimeKind_t; typedef DayOfWeek::type DayOfWeek_t; + typedef MidpointRounding::type MidpointRounding_t; typedef PlatformID::type PlatformID_t; typedef StringComparison::type StringComparison_t; typedef StringSplitOptions::type StringSplitOptions_t; diff --git a/include/System/Globalization/CultureInfo.h b/include/System/Globalization/CultureInfo.h index 31af5a4..142cef2 100644 --- a/include/System/Globalization/CultureInfo.h +++ b/include/System/Globalization/CultureInfo.h @@ -2,14 +2,29 @@ #ifndef _SYSTEM_GLOBALIZATION_CULTUREINFO_ #define _SYSTEM_GLOBALIZATION_CULTUREINFO_ +#include + namespace System { + class String; + namespace Globalization { - class CultureInfo + /** + * Provides information about a specific culture (called a "locale" for unmanaged code development). The information includes the names for the culture, the writing system, the calendar used, and formatting for dates and sort strings. + */ + class CultureInfo : public IFormatProvider, public Object { public: + static const CultureInfo InvariantCulture; + + CultureInfo(int culture); + CultureInfo(int culture, bool useUserOverride); + CultureInfo(const String& name); + CultureInfo(const String& name, bool useUserOverride); + void ClearCacheData(); + bool Equals(Object const * const obj) const; }; } } diff --git a/src/libmscorlib/Double.cpp b/src/libmscorlib/Double.cpp index 3e2166e..4bb8f89 100644 --- a/src/libmscorlib/Double.cpp +++ b/src/libmscorlib/Double.cpp @@ -39,9 +39,9 @@ extern "C" int strcasecmp(const char * s1, const char * s2); namespace System { - static unsigned long long rawNaND = 0x7ff8000000000000ULL; - static unsigned long long rawPosInfD = 0x7ff0000000000000ULL; - static unsigned long long rawNegInfD = 0xfff0000000000000ULL; + static ulong rawNaND = 0x7ff8000000000000ULL; + static ulong rawPosInfD = 0x7ff0000000000000ULL; + static ulong rawNegInfD = 0xfff0000000000000ULL; const double Double::Epsilon = 4.94066e-324; const double Double::MaxValue = 1.79769e+308; @@ -92,6 +92,21 @@ namespace System return DoubleTypeInfo; } + bool Double::IsNaN(const Double& d) + { + return (d != d); + } + + bool Double::IsNegativeInfinity(const Double& d) + { + return (d < 0.0 && (double)d == NegativeInfinity); + } + + bool Double::IsPositiveInfinity(const Double& d) + { + return (d > 0.0 && (double)d == PositiveInfinity); + } + bool Double::TryParse(const String& str, out double* result) { sassert(!String::IsNullOrEmpty(str), String::Format("str; %s", FrameworkResources::ArgumentNull_Generic));