本文整理匯總了C#中BigInteger.IsZero方法的典型用法代碼示例。如果您正苦於以下問題:C# BigInteger.IsZero方法的具體用法?C# BigInteger.IsZero怎麽用?C# BigInteger.IsZero使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類BigInteger
的用法示例。
在下文中一共展示了BigInteger.IsZero方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: __format__
//.........這裏部分代碼省略.........
} else {
digits = val.ToString();
}
break;
case 'G':
if (val >= 1000000) {
digits = ToExponent(val, false, 0, 6);
} else {
digits = val.ToString();
}
break;
#else
case null:
case 'd':
if (spec.ThousandsComma) {
digits = val.ToString("#,0", CultureInfo.InvariantCulture);
} else {
digits = val.ToString("D", CultureInfo.InvariantCulture);
}
break;
case '%':
if (spec.ThousandsComma) {
digits = val.ToString("#,0.000000%", CultureInfo.InvariantCulture);
} else {
digits = val.ToString("0.000000%", CultureInfo.InvariantCulture);
}
break;
case 'e':
if (spec.ThousandsComma) {
digits = val.ToString("#,0.000000e+00", CultureInfo.InvariantCulture);
} else {
digits = val.ToString("0.000000e+00", CultureInfo.InvariantCulture);
}
break;
case 'E':
if (spec.ThousandsComma) {
digits = val.ToString("#,0.000000E+00", CultureInfo.InvariantCulture);
} else {
digits = val.ToString("0.000000E+00", CultureInfo.InvariantCulture);
}
break;
case 'f':
case 'F':
if (spec.ThousandsComma) {
digits = val.ToString("#,########0.000000", CultureInfo.InvariantCulture);
} else {
digits = val.ToString("#########0.000000", CultureInfo.InvariantCulture);
}
break;
case 'g':
if (val >= 1000000) {
digits = val.ToString("0.#####e+00", CultureInfo.InvariantCulture);
} else if (spec.ThousandsComma) {
digits = val.ToString("#,0", CultureInfo.InvariantCulture);
} else {
digits = val.ToString(CultureInfo.InvariantCulture);
}
break;
case 'G':
if (val >= 1000000) {
digits = val.ToString("0.#####E+00", CultureInfo.InvariantCulture);
} else if (spec.ThousandsComma) {
digits = val.ToString("#,0", CultureInfo.InvariantCulture);
} else {
digits = val.ToString(CultureInfo.InvariantCulture);
}
break;
#endif
case 'X':
digits = AbsToHex(val, false);
break;
case 'x':
digits = AbsToHex(val, true);
break;
case 'o': // octal
digits = ToOctal(val, true);
break;
case 'b': // binary
digits = ToBinary(val, false, true);
break;
case 'c': // single char
int iVal;
if (spec.Sign != null) {
throw PythonOps.ValueError("Sign not allowed with integer format specifier 'c'");
} else if (!self.AsInt32(out iVal)) {
throw PythonOps.OverflowError("long int too large to convert to int");
} else if(iVal < 0 || iVal > 0xFF) {
throw PythonOps.OverflowError("%c arg not in range(0x10000)");
}
digits = ScriptingRuntimeHelpers.CharToString((char)iVal);
break;
default:
throw PythonOps.ValueError("Unknown format code '{0}'", spec.Type.ToString());
}
Debug.Assert(digits[0] != '-');
return spec.AlignNumericText(digits, self.IsZero(), self.IsPositive());
}
示例2: ToDigits
private static string/*!*/ ToDigits(BigInteger/*!*/ val, int radix, bool lower) {
if (val.IsZero()) {
return "0";
}
StringBuilder str = new StringBuilder();
while (val != 0) {
int digit = (int)(val % radix);
if (digit < 10) str.Append((char)((digit) + '0'));
else if (lower) str.Append((char)((digit - 10) + 'a'));
else str.Append((char)((digit - 10) + 'A'));
val /= radix;
}
StringBuilder res = new StringBuilder(str.Length);
for (int i = str.Length - 1; i >= 0; i--) {
res.Append(str[i]);
}
return res.ToString();
}
示例3: __nonzero__
public static bool __nonzero__(BigInteger x) {
return !x.IsZero();
}
示例4: BitLength
// Like GetBitCount(Abs(x)), except 0 maps to 0
public static int BitLength(BigInteger x)
{
if (x.IsZero())
{
return 0;
}
return x.Abs().GetBitCount();
}