Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve System.Single #16

Merged
merged 1 commit into from
Aug 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions source/System/Single.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ namespace System
[Serializable]
public struct Single
{
// this field is required in the native end
#pragma warning disable 0649
internal float _value;
#pragma warning restore 0649

/// <summary>
/// Represents the smallest possible value of Single. This field is constant.
Expand All @@ -37,16 +40,7 @@ public struct Single
/// <returns>The string representation of the value of this instance.</returns>
public override String ToString()
{
var str = ((Double)_value).ToString();
switch (str)
{
case "Infinity":
case "-Infinity":
case "NaN":
return str;
default:
return Number.Format(_value, false, "G", NumberFormatInfo.CurrentInfo);
}
return Number.Format(_value, false, "G", NumberFormatInfo.CurrentInfo);
}

/// <summary>
Expand All @@ -56,16 +50,7 @@ public override String ToString()
/// <returns>The string representation of the value of this instance as specified by format.</returns>
public String ToString(String format)
{
var str = ((Double)_value).ToString();
switch (str)
{
case "Infinity":
case "-Infinity":
case "NaN":
return str;
default:
return Number.Format(_value, false, format, NumberFormatInfo.CurrentInfo);
}
return Number.Format(_value, false, format, NumberFormatInfo.CurrentInfo);
}
}
}