本文整理汇总了C#中NumberBuffer类的典型用法代码示例。如果您正苦于以下问题:C# NumberBuffer类的具体用法?C# NumberBuffer怎么用?C# NumberBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NumberBuffer类属于命名空间,在下文中一共展示了NumberBuffer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: HexNumberToInt64
private static bool HexNumberToInt64(ref NumberBuffer number, ref long value)
{
ulong num = 0L;
bool flag = HexNumberToUInt64(ref number, ref num);
value = (long) num;
return flag;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:Number.cs
示例2: HexNumberToInt64
private static Boolean HexNumberToInt64(ref NumberBuffer number, ref Int64 value)
{
UInt64 passedValue = 0;
Boolean returnValue = HexNumberToUInt64(ref number, ref passedValue);
value = (Int64)passedValue;
return returnValue;
}
开发者ID:nattress,项目名称:corert,代码行数:7,代码来源:FormatProvider.FormatAndParse.cs
示例3: HexNumberToInt32
private static bool HexNumberToInt32(ref NumberBuffer number, ref int value)
{
uint num = 0;
bool flag = HexNumberToUInt32(ref number, ref num);
value = (int) num;
return flag;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:Number.cs
示例4: DoubleToNumber
private static unsafe void DoubleToNumber(double value, int precision, ref NumberBuffer number)
{
number.precision = precision;
if (DoubleHelper.Exponent(value) == 0x7ff)
{
number.scale = DoubleHelper.Mantissa(value) != 0 ? SCALE_NAN : SCALE_INF;
number.sign = DoubleHelper.Sign(value);
number.digits[0] = '\0';
}
else
{
byte* src = stackalloc byte[_CVTBUFSIZE];
int sign;
fixed (NumberBuffer* pNumber = &number)
{
RuntimeImports._ecvt_s(src, _CVTBUFSIZE, value, precision, &pNumber->scale, &sign);
}
number.sign = sign != 0;
char* dst = number.digits;
if ((char)*src != '0')
{
while (*src != 0)
*dst++ = (char)*src++;
}
*dst = '\0';
}
}
开发者ID:tijoytom,项目名称:corert,代码行数:28,代码来源:FormatProvider.FormatAndParse.Windows.cs
示例5: HexNumberToUInt32
private unsafe static Boolean HexNumberToUInt32(ref NumberBuffer number, ref UInt32 value)
{
Int32 i = number.scale;
if (i > UINT32_PRECISION || i < number.precision)
{
return false;
}
Char* p = number.digits;
Debug.Assert(p != null, "");
UInt32 n = 0;
while (--i >= 0)
{
if (n > ((UInt32)0xFFFFFFFF / 16))
{
return false;
}
n *= 16;
if (*p != '\0')
{
UInt32 newN = n;
if (*p != '\0')
{
if (*p >= '0' && *p <= '9')
{
newN += (UInt32)(*p - '0');
}
else
{
if (*p >= 'A' && *p <= 'F')
{
newN += (UInt32)((*p - 'A') + 10);
}
else
{
Debug.Assert(*p >= 'a' && *p <= 'f', "");
newN += (UInt32)((*p - 'a') + 10);
}
}
p++;
}
// Detect an overflow here...
if (newN < n)
{
return false;
}
n = newN;
}
}
value = n;
return true;
}
开发者ID:nattress,项目名称:corert,代码行数:53,代码来源:FormatProvider.FormatAndParse.cs
示例6: HexNumberToUInt32
private static unsafe bool HexNumberToUInt32(ref NumberBuffer number, ref uint value)
{
int scale = number.scale;
if ((scale > 10) || (scale < number.precision))
{
return false;
}
char* digits = number.digits;
uint num2 = 0;
while (--scale >= 0)
{
if (num2 > 0xfffffff)
{
return false;
}
num2 *= 0x10;
if (digits[0] != '\0')
{
uint num3 = num2;
if (digits[0] != '\0')
{
if ((digits[0] >= '0') && (digits[0] <= '9'))
{
num3 += digits[0] - '0';
}
else if ((digits[0] >= 'A') && (digits[0] <= 'F'))
{
num3 += (uint) ((digits[0] - 'A') + 10);
}
else
{
num3 += (uint) ((digits[0] - 'a') + 10);
}
digits++;
}
if (num3 < num2)
{
return false;
}
num2 = num3;
}
}
value = num2;
return true;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:45,代码来源:Number.cs
示例7: FormatGeneral
private static unsafe void FormatGeneral(StringBuilder sb, NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info, char expChar, bool bSuppressScientific)
{
int digPos = number.scale;
bool scientific = false;
if (!bSuppressScientific)
{
// Don't switch to scientific notation
if (digPos > nMaxDigits || digPos < -3)
{
digPos = 1;
scientific = true;
}
}
char* dig = number.digits;
if (digPos > 0)
{
do
{
sb.Append((*dig != 0) ? *dig++ : '0');
} while (--digPos > 0);
}
else
{
sb.Append('0');
}
if (*dig != 0 || digPos < 0)
{
sb.Append(info.NumberDecimalSeparator);
while (digPos < 0)
{
sb.Append('0');
digPos++;
}
while (*dig != 0)
sb.Append(*dig++);
}
if (scientific)
FormatExponent(sb, info, number.scale - 1, expChar, 2, true);
}
开发者ID:chcosta,项目名称:corefx,代码行数:46,代码来源:FormatProvider.Number.cs
示例8: TryStringToNumber
internal static bool TryStringToNumber(string str, NumberStyles options, ref NumberBuffer number, NumberFormatInfo numfmt, bool parseDecimal)
{
return TryStringToNumber(str, options, ref number, null, numfmt, parseDecimal);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:4,代码来源:Number.cs
示例9: TryParseSingle
internal static unsafe bool TryParseSingle(string value, NumberStyles options, NumberFormatInfo numfmt, out float result)
{
byte* stackBuffer = stackalloc byte[0x72];
NumberBuffer number = new NumberBuffer(stackBuffer);
result = 0f;
double num = 0.0;
if (!TryStringToNumber(value, options, ref number, numfmt, false))
{
return false;
}
if (!NumberBufferToDouble(number.PackForNative(), ref num))
{
return false;
}
float f = (float) num;
if (float.IsInfinity(f))
{
return false;
}
result = f;
return true;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:22,代码来源:Number.cs
示例10: TryParseUInt64
internal static unsafe bool TryParseUInt64(string s, NumberStyles style, NumberFormatInfo info, out ulong result)
{
byte* stackBuffer = stackalloc byte[0x72];
NumberBuffer number = new NumberBuffer(stackBuffer);
result = 0L;
if (!TryStringToNumber(s, style, ref number, info, false))
{
return false;
}
if ((style & NumberStyles.AllowHexSpecifier) != NumberStyles.None)
{
if (!HexNumberToUInt64(ref number, ref result))
{
return false;
}
}
else if (!NumberToUInt64(ref number, ref result))
{
return false;
}
return true;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:22,代码来源:Number.cs
示例11: ParseDecimal
internal static unsafe decimal ParseDecimal(string value, NumberStyles options, NumberFormatInfo numfmt)
{
byte* stackBuffer = stackalloc byte[0x72];
NumberBuffer number = new NumberBuffer(stackBuffer);
decimal num = 0M;
StringToNumber(value, options, ref number, numfmt, true);
if (!NumberBufferToDecimal(number.PackForNative(), ref num))
{
throw new OverflowException(Environment.GetResourceString("Overflow_Decimal"));
}
return num;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:12,代码来源:Number.cs
示例12: TryParseDouble
internal static unsafe bool TryParseDouble(string value, NumberStyles options, NumberFormatInfo numfmt, out double result)
{
byte* stackBuffer = stackalloc byte[0x72];
NumberBuffer number = new NumberBuffer(stackBuffer);
result = 0.0;
if (!TryStringToNumber(value, options, ref number, numfmt, false))
{
return false;
}
if (!NumberBufferToDouble(number.PackForNative(), ref result))
{
return false;
}
return true;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:15,代码来源:Number.cs
示例13: NumberToString
internal static unsafe string NumberToString(NumberBuffer number, char format, int nMaxDigits, NumberFormatInfo info, bool isDecimal)
{
int nMinDigits = -1;
StringBuilder sb = new StringBuilder(MIN_SB_BUFFER_SIZE);
switch (format)
{
case 'C':
case 'c':
{
nMinDigits = nMaxDigits >= 0 ? nMaxDigits : info.CurrencyDecimalDigits;
if (nMaxDigits < 0)
nMaxDigits = info.CurrencyDecimalDigits;
RoundNumber(ref number, number.scale + nMaxDigits); // Don't change this line to use digPos since digCount could have its sign changed.
FormatCurrency(sb, number, nMinDigits, nMaxDigits, info);
break;
}
case 'F':
case 'f':
{
if (nMaxDigits < 0)
nMaxDigits = nMinDigits = info.NumberDecimalDigits;
else
nMinDigits = nMaxDigits;
RoundNumber(ref number, number.scale + nMaxDigits);
if (number.sign)
sb.Append(info.NegativeSign);
FormatFixed(sb, number, nMinDigits, nMaxDigits, info, null, info.NumberDecimalSeparator, null);
break;
}
case 'N':
case 'n':
{
if (nMaxDigits < 0)
nMaxDigits = nMinDigits = info.NumberDecimalDigits; // Since we are using digits in our calculation
else
nMinDigits = nMaxDigits;
RoundNumber(ref number, number.scale + nMaxDigits);
FormatNumber(sb, number, nMinDigits, nMaxDigits, info);
break;
}
case 'E':
case 'e':
{
if (nMaxDigits < 0)
nMaxDigits = nMinDigits = 6;
else
nMinDigits = nMaxDigits;
nMaxDigits++;
RoundNumber(ref number, nMaxDigits);
if (number.sign)
sb.Append(info.NegativeSign);
FormatScientific(sb, number, nMinDigits, nMaxDigits, info, format);
break;
}
case 'G':
case 'g':
{
bool enableRounding = true;
if (nMaxDigits < 1)
{
if (isDecimal && (nMaxDigits == -1))
{
// Default to 29 digits precision only for G formatting without a precision specifier
// This ensures that the PAL code pads out to the correct place even when we use the default precision
nMaxDigits = nMinDigits = DECIMAL_PRECISION;
enableRounding = false; // Turn off rounding for ECMA compliance to output trailing 0's after decimal as significant
}
else
{
// This ensures that the PAL code pads out to the correct place even when we use the default precision
nMaxDigits = nMinDigits = number.precision;
}
}
else
nMinDigits = nMaxDigits;
if (enableRounding) // Don't round for G formatting without precision
RoundNumber(ref number, nMaxDigits); // This also fixes up the minus zero case
else
{
//.........这里部分代码省略.........
开发者ID:chcosta,项目名称:corefx,代码行数:101,代码来源:FormatProvider.Number.cs
示例14: FormatNumber
private static void FormatNumber(StringBuilder sb, NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info)
{
string fmt = number.sign ?
s_negNumberFormats[info.NumberNegativePattern] :
s_posNumberFormat;
foreach (char ch in fmt)
{
switch (ch)
{
case '#':
FormatFixed(sb, number, nMinDigits, nMaxDigits, info, info.NumberGroupSizes, info.NumberDecimalSeparator, info.NumberGroupSeparator);
break;
case '-':
sb.Append(info.NegativeSign);
break;
default:
sb.Append(ch);
break;
}
}
}
开发者ID:chcosta,项目名称:corefx,代码行数:22,代码来源:FormatProvider.Number.cs
示例15: NumberToInt32
private static unsafe bool NumberToInt32(ref NumberBuffer number, ref int value)
{
int scale = number.scale;
if ((scale > 10) || (scale < number.precision))
{
return false;
}
char* digits = number.digits;
int num2 = 0;
while (--scale >= 0)
{
if (num2 > 0xccccccc)
{
return false;
}
num2 *= 10;
if (digits[0] != '\0')
{
digits++;
num2 += digits[0] - '0';
}
}
if (number.sign)
{
num2 = -num2;
if (num2 > 0)
{
return false;
}
}
else if (num2 < 0)
{
return false;
}
value = num2;
return true;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:37,代码来源:Number.cs
示例16: ParseNumber
private static unsafe bool ParseNumber(ref char* str, NumberStyles options, ref NumberBuffer number, StringBuilder sb, NumberFormatInfo numfmt, bool parseDecimal)
{
const int StateSign = 0x0001;
const int StateParens = 0x0002;
const int StateDigits = 0x0004;
const int StateNonZero = 0x0008;
const int StateDecimal = 0x0010;
const int StateCurrency = 0x0020;
number.scale = 0;
number.sign = false;
string decSep; // Decimal separator from NumberFormatInfo.
string groupSep; // Group separator from NumberFormatInfo.
string currSymbol = null; // Currency symbol from NumberFormatInfo.
bool parsingCurrency = false;
if ((options & NumberStyles.AllowCurrencySymbol) != 0)
{
currSymbol = numfmt.CurrencySymbol;
// The idea here is to match the currency separators and on failure match the number separators to keep the perf of VB's IsNumeric fast.
// The values of decSep are setup to use the correct relevant separator (currency in the if part and decimal in the else part).
decSep = numfmt.CurrencyDecimalSeparator;
groupSep = numfmt.CurrencyGroupSeparator;
parsingCurrency = true;
}
else
{
decSep = numfmt.NumberDecimalSeparator;
groupSep = numfmt.NumberGroupSeparator;
}
int state = 0;
bool bigNumber = (sb != null); // When a StringBuilder is provided then we use it in place of the number.digits char[50]
int maxParseDigits = bigNumber ? int.MaxValue : NumberMaxDigits;
char* p = str;
char ch = *p;
char* next;
char* dig = number.digits;
while (true)
{
// Eat whitespace unless we've found a sign which isn't followed by a currency symbol.
// "-Kr 1231.47" is legal but "- 1231.47" is not.
if (!IsWhite(ch) || (options & NumberStyles.AllowLeadingWhite) == 0 || ((state & StateSign) != 0 && ((state & StateCurrency) == 0 && numfmt.NumberNegativePattern != 2)))
{
if ((((options & NumberStyles.AllowLeadingSign) != 0) && (state & StateSign) == 0) && ((next = MatchChars(p, numfmt.PositiveSign)) != null || ((next = MatchChars(p, numfmt.NegativeSign)) != null && (number.sign = true))))
{
state |= StateSign;
p = next - 1;
}
else if (ch == '(' && ((options & NumberStyles.AllowParentheses) != 0) && ((state & StateSign) == 0))
{
state |= StateSign | StateParens;
number.sign = true;
}
else if (currSymbol != null && (next = MatchChars(p, currSymbol)) != null)
{
state |= StateCurrency;
currSymbol = null;
// We already found the currency symbol. There should not be more currency symbols. Set
// currSymbol to NULL so that we won't search it again in the later code path.
p = next - 1;
}
else
{
break;
}
}
ch = *++p;
}
int digCount = 0;
int digEnd = 0;
while (true)
{
if ((ch >= '0' && ch <= '9') || (((options & NumberStyles.AllowHexSpecifier) != 0) && ((ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F'))))
{
state |= StateDigits;
if (ch != '0' || (state & StateNonZero) != 0 || (bigNumber && ((options & NumberStyles.AllowHexSpecifier) != 0)))
{
if (digCount < maxParseDigits)
{
if (bigNumber)
sb.Append(ch);
else
dig[digCount++] = ch;
if (ch != '0' || parseDecimal)
{
digEnd = digCount;
}
}
if ((state & StateDecimal) == 0)
{
number.scale++;
}
state |= StateNonZero;
//.........这里部分代码省略.........
开发者ID:chcosta,项目名称:corefx,代码行数:101,代码来源:FormatProvider.Number.cs
示例17: ParseNumber
private static unsafe bool ParseNumber(ref char* str, NumberStyles options, ref NumberBuffer number, StringBuilder sb, NumberFormatInfo numfmt, bool parseDecimal)
{
string currencyDecimalSeparator;
string currencyGroupSeparator;
char* chPtr2;
number.scale = 0;
number.sign = false;
string currencySymbol = null;
string ansiCurrencySymbol = null;
string numberDecimalSeparator = null;
string numberGroupSeparator = null;
bool flag = false;
if ((options & NumberStyles.AllowCurrencySymbol) != NumberStyles.None)
{
currencySymbol = numfmt.CurrencySymbol;
if (numfmt.ansiCurrencySymbol != null)
{
ansiCurrencySymbol = numfmt.ansiCurrencySymbol;
}
numberDecimalSeparator = numfmt.NumberDecimalSeparator;
numberGroupSeparator = numfmt.NumberGroupSeparator;
currencyDecimalSeparator = numfmt.CurrencyDecimalSeparator;
currencyGroupSeparator = numfmt.CurrencyGroupSeparator;
flag = true;
}
else
{
currencyDecimalSeparator = numfmt.NumberDecimalSeparator;
currencyGroupSeparator = numfmt.NumberGroupSeparator;
}
int num = 0;
bool flag2 = false;
bool flag3 = sb != null;
bool flag4 = flag3 && ((options & NumberStyles.AllowHexSpecifier) != NumberStyles.None);
int num2 = flag3 ? 0x7fffffff : 50;
char* p = str;
char ch = p[0];
while (true)
{
if ((!IsWhite(ch) || ((options & NumberStyles.AllowLeadingWhite) == NumberStyles.None)) || (((num & 1) != 0) && (((num & 1) == 0) || (((num & 0x20) == 0) && (numfmt.numberNegativePattern != 2)))))
{
if ((flag2 = ((options & NumberStyles.AllowLeadingSign) != NumberStyles.None) && ((num & 1) == 0)) && ((chPtr2 = MatchChars(p, numfmt.positiveSign)) != null))
{
num |= 1;
p = chPtr2 - 1;
}
else if (flag2 && ((chPtr2 = MatchChars(p, numfmt.negativeSign)) != null))
{
num |= 1;
number.sign = true;
p = chPtr2 - 1;
}
else if (((ch == '(') && ((options & NumberStyles.AllowParentheses) != NumberStyles.None)) && ((num & 1) == 0))
{
num |= 3;
number.sign = true;
}
else
{
if (((currencySymbol == null) || ((chPtr2 = MatchChars(p, currencySymbol)) == null)) && ((ansiCurrencySymbol == null) || ((chPtr2 = MatchChars(p, ansiCurrencySymbol)) == null)))
{
break;
}
num |= 0x20;
currencySymbol = null;
ansiCurrencySymbol = null;
p = chPtr2 - 1;
}
}
ch = *(++p);
}
int num3 = 0;
int index = 0;
while (true)
{
if (((ch >= '0') && (ch <= '9')) || (((options & NumberStyles.AllowHexSpecifier) != NumberStyles.None) && (((ch >= 'a') && (ch <= 'f')) || ((ch >= 'A') && (ch <= 'F')))))
{
num |= 4;
if (((ch != '0') || ((num & 8) != 0)) || flag4)
{
if (num3 < num2)
{
if (flag3)
{
sb.Append(ch);
}
else
{
number.digits[num3++] = ch;
}
if ((ch != '0') || parseDecimal)
{
index = num3;
}
}
if ((num & 0x10) == 0)
{
number.scale++;
}
num |= 8;
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:Number.cs
示例18: NumberToInt64
private static unsafe bool NumberToInt64(ref NumberBuffer number, ref long value)
{
int scale = number.scale;
if ((scale > 0x13) || (scale < number.precision))
{
return false;
}
char* digits = number.digits;
long num2 = 0L;
while (--scale >= 0)
{
if (num2 > 0xcccccccccccccccL)
{
return false;
}
num2 *= 10L;
if (digits[0] != '\0')
{
digits++;
num2 += digits[0] - '0';
}
}
if (number.sign)
{
num2 = -num2;
if (num2 > 0L)
{
return false;
}
}
else if (num2 < 0L)
{
return false;
}
value = num2;
return true;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:37,代码来源:Number.cs
示例19: ParseInt32
internal static unsafe int ParseInt32(string s, NumberStyles style, NumberFormatInfo info)
{
byte* stackBuffer = stackalloc byte[0x72];
NumberBuffer number = new NumberBuffer(stackBuffer);
int num = 0;
StringToNumber(s, style, ref number, info, false);
if ((style & NumberStyles.AllowHexSpecifier) != NumberStyles.None)
{
if (!HexNumberToInt32(ref number, ref num))
{
throw new OverflowException(Environment.GetResourceString("Overflow_Int32"));
}
return num;
}
if (!NumberToInt32(ref number, ref num))
{
throw new OverflowException(Environment.GetResourceString("Overflow_Int32"));
}
return num;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:20,代码来源:Number.cs
示例20: RoundNumber
private static unsafe void RoundNumber(ref NumberBuffer number, int pos)
{
char* dig = number.digits;
int i = 0;
while (i < pos && dig[i] != 0)
i++;
if (i == pos && dig[i] >= '5')
{
while (i > 0 && dig[i - 1] == '9')
i--;
if (i > 0)
{
dig[i - 1]++;
}
else
{
number.scale++;
dig[0] = '1';
i = 1;
}
}
else
{
while (i > 0 && dig[i - 1] == '0')
i--;
}
if (i == 0)
{
number.scale = 0;
number.sign = false;
}
dig[i] = '\0';
}
开发者ID:chcosta,项目名称:corefx,代码行数:36,代码来源:FormatProvider.Number.cs
注:本文中的NumberBuffer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论