Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/System.Private.CoreLib/shared/System/Double.cs')
-rw-r--r--src/System.Private.CoreLib/shared/System/Double.cs79
1 files changed, 39 insertions, 40 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Double.cs b/src/System.Private.CoreLib/shared/System/Double.cs
index 146ee4600..d85b4bca9 100644
--- a/src/System.Private.CoreLib/shared/System/Double.cs
+++ b/src/System.Private.CoreLib/shared/System/Double.cs
@@ -24,9 +24,9 @@ namespace System
[Serializable]
[StructLayout(LayoutKind.Sequential)]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct Double : IComparable, IConvertible, IFormattable, IComparable<Double>, IEquatable<Double>, ISpanFormattable
+ public readonly struct Double : IComparable, IConvertible, IFormattable, IComparable<double>, IEquatable<double>, ISpanFormattable
{
- private double m_value; // Do not rename (binary serialization)
+ private readonly double m_value; // Do not rename (binary serialization)
//
// Public Constants
@@ -47,7 +47,7 @@ namespace System
/// <summary>Determines whether the specified value is finite (zero, subnormal, or normal).</summary>
[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public unsafe static bool IsFinite(double d)
+ public static unsafe bool IsFinite(double d)
{
var bits = BitConverter.DoubleToInt64Bits(d);
return (bits & 0x7FFFFFFFFFFFFFFF) < 0x7FF0000000000000;
@@ -56,7 +56,7 @@ namespace System
/// <summary>Determines whether the specified value is infinite.</summary>
[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public unsafe static bool IsInfinity(double d)
+ public static unsafe bool IsInfinity(double d)
{
var bits = BitConverter.DoubleToInt64Bits(d);
return (bits & 0x7FFFFFFFFFFFFFFF) == 0x7FF0000000000000;
@@ -65,7 +65,7 @@ namespace System
/// <summary>Determines whether the specified value is NaN.</summary>
[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public unsafe static bool IsNaN(double d)
+ public static unsafe bool IsNaN(double d)
{
var bits = BitConverter.DoubleToInt64Bits(d);
return (bits & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000;
@@ -74,10 +74,9 @@ namespace System
/// <summary>Determines whether the specified value is negative.</summary>
[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public unsafe static bool IsNegative(double d)
+ public static unsafe bool IsNegative(double d)
{
- var bits = unchecked((ulong)BitConverter.DoubleToInt64Bits(d));
- return (bits & 0x8000000000000000) == 0x8000000000000000;
+ return BitConverter.DoubleToInt64Bits(d) < 0;
}
/// <summary>Determines whether the specified value is negative infinity.</summary>
@@ -91,7 +90,7 @@ namespace System
/// <summary>Determines whether the specified value is normal.</summary>
[NonVersionable]
// This is probably not worth inlining, it has branches and should be rarely called
- public unsafe static bool IsNormal(double d)
+ public static unsafe bool IsNormal(double d)
{
var bits = BitConverter.DoubleToInt64Bits(d);
bits &= 0x7FFFFFFFFFFFFFFF;
@@ -109,7 +108,7 @@ namespace System
/// <summary>Determines whether the specified value is subnormal.</summary>
[NonVersionable]
// This is probably not worth inlining, it has branches and should be rarely called
- public unsafe static bool IsSubnormal(double d)
+ public static unsafe bool IsSubnormal(double d)
{
var bits = BitConverter.DoubleToInt64Bits(d);
bits &= 0x7FFFFFFFFFFFFFFF;
@@ -123,13 +122,13 @@ namespace System
//
// Returns a value less than zero if this object
//
- public int CompareTo(Object value)
+ public int CompareTo(object value)
{
if (value == null)
{
return 1;
}
- if (value is Double)
+ if (value is double)
{
double d = (double)value;
if (m_value < d) return -1;
@@ -145,7 +144,7 @@ namespace System
throw new ArgumentException(SR.Arg_MustBeDouble);
}
- public int CompareTo(Double value)
+ public int CompareTo(double value)
{
if (m_value < value) return -1;
if (m_value > value) return 1;
@@ -160,13 +159,13 @@ namespace System
// True if obj is another Double with the same value as the current instance. This is
// a method of object equality, that only returns true if obj is also a double.
- public override bool Equals(Object obj)
+ public override bool Equals(object obj)
{
- if (!(obj is Double))
+ if (!(obj is double))
{
return false;
}
- double temp = ((Double)obj).m_value;
+ double temp = ((double)obj).m_value;
// This code below is written this way for performance reasons i.e the != and == check is intentional.
if (temp == m_value)
{
@@ -176,42 +175,42 @@ namespace System
}
[NonVersionable]
- public static bool operator ==(Double left, Double right)
+ public static bool operator ==(double left, double right)
{
return left == right;
}
[NonVersionable]
- public static bool operator !=(Double left, Double right)
+ public static bool operator !=(double left, double right)
{
return left != right;
}
[NonVersionable]
- public static bool operator <(Double left, Double right)
+ public static bool operator <(double left, double right)
{
return left < right;
}
[NonVersionable]
- public static bool operator >(Double left, Double right)
+ public static bool operator >(double left, double right)
{
return left > right;
}
[NonVersionable]
- public static bool operator <=(Double left, Double right)
+ public static bool operator <=(double left, double right)
{
return left <= right;
}
[NonVersionable]
- public static bool operator >=(Double left, Double right)
+ public static bool operator >=(double left, double right)
{
return left >= right;
}
- public bool Equals(Double obj)
+ public bool Equals(double obj)
{
if (obj == m_value)
{
@@ -226,7 +225,7 @@ namespace System
[MethodImpl(MethodImplOptions.AggressiveInlining)] // 64-bit constants make the IL unusually large that makes the inliner to reject the method
public override int GetHashCode()
{
- var bits = Unsafe.As<double, long>(ref m_value);
+ var bits = Unsafe.As<double, long>(ref Unsafe.AsRef(in m_value));
// Optimized check for IsNan() || IsZero()
if (((bits - 1) & 0x7FFFFFFFFFFFFFFF) >= 0x7FF0000000000000)
@@ -238,22 +237,22 @@ namespace System
return unchecked((int)bits) ^ ((int)(bits >> 32));
}
- public override String ToString()
+ public override string ToString()
{
return Number.FormatDouble(m_value, null, NumberFormatInfo.CurrentInfo);
}
- public String ToString(String format)
+ public string ToString(string format)
{
return Number.FormatDouble(m_value, format, NumberFormatInfo.CurrentInfo);
}
- public String ToString(IFormatProvider provider)
+ public string ToString(IFormatProvider provider)
{
return Number.FormatDouble(m_value, null, NumberFormatInfo.GetInstance(provider));
}
- public String ToString(String format, IFormatProvider provider)
+ public string ToString(string format, IFormatProvider provider)
{
return Number.FormatDouble(m_value, format, NumberFormatInfo.GetInstance(provider));
}
@@ -263,26 +262,26 @@ namespace System
return Number.TryFormatDouble(m_value, format, NumberFormatInfo.GetInstance(provider), destination, out charsWritten);
}
- public static double Parse(String s)
+ public static double Parse(string s)
{
if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
return Number.ParseDouble(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo);
}
- public static double Parse(String s, NumberStyles style)
+ public static double Parse(string s, NumberStyles style)
{
NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
return Number.ParseDouble(s, style, NumberFormatInfo.CurrentInfo);
}
- public static double Parse(String s, IFormatProvider provider)
+ public static double Parse(string s, IFormatProvider provider)
{
if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
return Number.ParseDouble(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.GetInstance(provider));
}
- public static double Parse(String s, NumberStyles style, IFormatProvider provider)
+ public static double Parse(string s, NumberStyles style, IFormatProvider provider)
{
NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
@@ -297,7 +296,7 @@ namespace System
// PositiveInfinity or NegativeInfinity for a number that is too
// large or too small.
- public static double Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
+ public static double Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Float | NumberStyles.AllowThousands, IFormatProvider provider = null)
{
NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
return Number.ParseDouble(s, style, NumberFormatInfo.GetInstance(provider));
@@ -305,7 +304,7 @@ namespace System
- public static bool TryParse(String s, out double result)
+ public static bool TryParse(string s, out double result)
{
if (s == null)
{
@@ -321,7 +320,7 @@ namespace System
return TryParse(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo, out result);
}
- public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out double result)
+ public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out double result)
{
NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
@@ -346,15 +345,15 @@ namespace System
if (!success)
{
ReadOnlySpan<char> sTrim = s.Trim();
- if (StringSpanHelpers.Equals(sTrim, info.PositiveInfinitySymbol))
+ if (sTrim.EqualsOrdinal(info.PositiveInfinitySymbol))
{
result = PositiveInfinity;
}
- else if (StringSpanHelpers.Equals(sTrim, info.NegativeInfinitySymbol))
+ else if (sTrim.EqualsOrdinal(info.NegativeInfinitySymbol))
{
result = NegativeInfinity;
}
- else if (StringSpanHelpers.Equals(sTrim, info.NaNSymbol))
+ else if (sTrim.EqualsOrdinal(info.NaNSymbol))
{
result = NaN;
}
@@ -435,7 +434,7 @@ namespace System
return m_value;
}
- Decimal IConvertible.ToDecimal(IFormatProvider provider)
+ decimal IConvertible.ToDecimal(IFormatProvider provider)
{
return Convert.ToDecimal(m_value);
}
@@ -445,7 +444,7 @@ namespace System
throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Double", "DateTime"));
}
- Object IConvertible.ToType(Type type, IFormatProvider provider)
+ object IConvertible.ToType(Type type, IFormatProvider provider)
{
return Convert.DefaultToType((IConvertible)this, type, provider);
}