Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #44 from Du-z/more_query_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ProphetLamb authored Sep 21, 2022
2 parents 48ed57b + 60ba7b1 commit d44b53a
Show file tree
Hide file tree
Showing 2 changed files with 350 additions and 57 deletions.
50 changes: 0 additions & 50 deletions src/Json/SpecialNumbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@ internal static class SpecialNumbers {
public const string NUM_NAN = "nan";
public const string NUM_POSINF = "inf";
public const string NUM_NEGINF = "-inf";
public const string NUM_POSEPS = "eps";
public const string NUM_NEGEPS = "-eps";
public const string NUM_MAX = "max";
public const string NUM_MIN = "min";

public static float ToSingle(string special) {
return special switch {
NUM_NAN => Single.NaN,
NUM_POSINF => Single.PositiveInfinity,
NUM_NEGINF => Single.NegativeInfinity,
NUM_POSEPS => Single.Epsilon,
NUM_NEGEPS => -Single.Epsilon,
NUM_MAX => Single.MaxValue,
NUM_MIN => Single.MinValue,
_ => default,
};
}
Expand All @@ -35,18 +27,6 @@ public static float ToSingle(string special) {
return NUM_NEGINF;
}

if (Math.Abs(value) <= Single.Epsilon) {
return value > 0 ? NUM_POSEPS : NUM_NEGEPS;
}

if (value >= Single.MaxValue) {
return NUM_MAX;
}

if (value <= Single.MinValue) {
return NUM_MIN;
}

return null;
}

Expand All @@ -56,10 +36,6 @@ public static double ToDouble(string special) {
NUM_NAN => Double.NaN,
NUM_POSINF => Double.PositiveInfinity,
NUM_NEGINF => Double.NegativeInfinity,
NUM_POSEPS => Double.Epsilon,
NUM_NEGEPS => -Double.Epsilon,
NUM_MAX => Double.MaxValue,
NUM_MIN => Double.MinValue,
_ => default,
};
}
Expand All @@ -77,40 +53,14 @@ public static double ToDouble(string special) {
return NUM_NEGINF;
}

if (Math.Abs(value) <= Double.Epsilon) {
return value > 0 ? NUM_POSEPS : NUM_NEGEPS;
}

if (value >= Double.MaxValue) {
return NUM_MAX;
}

if (value <= Double.MinValue) {
return NUM_MIN;
}

return null;
}

public static decimal ToDecimal(string str) {
if (str == NUM_MAX) {
return Decimal.MaxValue;
}

if (str == NUM_MIN) {
return Decimal.MinValue;
}

return default;
}
public static string? ToSpecial(in decimal value) {
if (value >= Decimal.MaxValue) {
return NUM_MAX;
}

if (value <= Decimal.MinValue) {
return NUM_MIN;
}

return null;
}
Expand Down
Loading

0 comments on commit d44b53a

Please sign in to comment.