unsafe public void ParseNumberString_Works_Scnenarios() { Skip.If(base.NoDiffToolDetected(), "No diff tool detected"); Dictionary <string, string> sut = new Dictionary <string, string>(); sut.Add("leading zeros", "001"); sut.Add("leading zeros neg", "-001"); sut.Add("zero", "0"); sut.Add("double", "0.00000000000000212312312"); sut.Add("double neg", "-0.00000000000000212312312"); sut.Add("int", "1"); sut.Add("int neg", "-1"); sut.Add("autreint ", "123124"); sut.Add("autreint neg", "-123124"); sut.Add("notation scientifique", "4.56E+2"); sut.Add("notation scientifique neg", "-4.56E-2"); sut.Add("notation scientifique 2", "4.5644E+2"); sut.Add("notation scientifique 2 neg", "-4.5644E-2"); sut.Add("notation scientifique 3", "4424.5644E+22"); sut.Add("notation scientifique 3 neg", "-4424.5644E-22"); sut.Add("notation scientifique 4", "4424.5644E+223"); sut.Add("notation scientifique 4 neg", "-4424.5644E-223"); StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, string> kv in sut) { sb.AppendLine($"Scenario : {kv.Key} "); sb.AppendLine($"Valeur : {kv.Value} "); fixed(char *p = kv.Value) { char *pend = p + kv.Value.Length; var res = ParsedNumberString.ParseNumberString(p, pend); sb.AppendLine($"Resultat : {res.exponent} {res.mantissa} {res.negative} {res.valid}"); sb.AppendLine(); } } // We do not want to fail the tests when the user has not // configured a diff tool. try { VerifyData(sb.ToString()); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } }
unsafe public void ParseNumberString_Works_Scnenarios() { Dictionary <string, string> sut = new Dictionary <string, string>(); sut.Add("leading zeros", "001"); sut.Add("leading zeros neg", "-001"); sut.Add("zero", "0"); sut.Add("zero neg", "-0"); sut.Add("double", "0.00000000000000212312312"); sut.Add("double neg", "-0.00000000000000212312312"); sut.Add("int", "1"); sut.Add("int neg", "-1"); sut.Add("autreint ", "123124"); sut.Add("autreint neg", "-123124"); sut.Add("notation scientifique", "4.56E+2"); sut.Add("notation scientifique neg", "-4.56E-2"); sut.Add("notation scientifique 2", "4.5644E+2"); sut.Add("notation scientifique 2 neg", "-4.5644E-2"); sut.Add("notation scientifique 3", "4424.5644E+22"); sut.Add("notation scientifique 3 neg", "-4424.5644E-22"); sut.Add("notation scientifique 4", "4424.5644E+223"); sut.Add("notation scientifique 4 neg", "-4424.5644E-223"); StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, string> kv in sut) { sb.AppendLine($"Scenario : {kv.Key} "); sb.AppendLine($"Valeur : {kv.Value} "); fixed(char *p = kv.Value) { char *pend = p + kv.Value.Length; var res = ParsedNumberString.ParseNumberString(p, pend); sb.AppendLine($"Resultat : {res.exponent} {res.mantissa} {res.negative} {res.valid}"); sb.AppendLine(); } } VerifyData(sb.ToString()); }
// SKIP [Benchmark(Description = "ParseNumberString() only")] public double FastParser_PNS() { double max = double.MinValue; foreach (string l in _lines) { unsafe { fixed(char *p = l) { var pni = ParsedNumberString.ParseNumberString(p, p + l.Length); max = pni.exponent > max ? pni.exponent : max; } } } return(max); }
unsafe static internal Double ParseNumber(char *first, char *last, chars_format expectedFormat = chars_format.is_general, char decimal_separator = '.') { while ((first != last) && Utils.is_space((byte)(*first))) { first++; } if (first == last) { throw new ArgumentException(); } ParsedNumberString pns = ParsedNumberString.ParseNumberString(first, last, expectedFormat); if (!pns.valid) { return(HandleInvalidInput(first, last)); } // Next is Clinger's fast path. if (DoubleBinaryConstants.min_exponent_fast_path <= pns.exponent && pns.exponent <= DoubleBinaryConstants.max_exponent_fast_path && pns.mantissa <= DoubleBinaryConstants.max_mantissa_fast_path && !pns.too_many_digits) { return(FastPath(pns)); } AdjustedMantissa am = ComputeFloat(pns.exponent, pns.mantissa); if (pns.too_many_digits) { if (am != ComputeFloat(pns.exponent, pns.mantissa + 1)) { am.power2 = -1; // value is invalid. } } // If we called compute_float<binary_format<T>>(pns.exponent, pns.mantissa) and we have an invalid power (am.power2 < 0), // then we need to go the long way around again. This is very uncommon. if (am.power2 < 0) { am = ParseLongMantissa(first, last, decimal_separator); } return(ToFloat(pns.negative, am)); }