public static string __hex__(BigInteger x) { // CPython 2.5 prints letters in lowercase, with a capital L. if (x < 0) { return "-0x" + (-x).ToString(16).ToLower() + "L"; } else { return "0x" + x.ToString(16).ToLower() + "L"; } }
public static RubyArray/*!*/ Coerce(RubyContext/*!*/ context, BigDecimal/*!*/ self, BigInteger/*!*/ other) { return RubyOps.MakeArray2(BigDecimal.Create(GetConfig(context), other.ToString()), self); }
private static string/*!*/ ToExponent(BigInteger/*!*/ self, bool lower, int minPrecision, int maxPrecision) { Debug.Assert(minPrecision <= maxPrecision); // get all the digits string digits = self.ToString(); StringBuilder tmp = new StringBuilder(); tmp.Append(digits[0]); for (int i = 1; i < maxPrecision && i < digits.Length; i++) { // append if we have a significant digit or if we are forcing a minimum precision if (digits[i] != '0' || i <= minPrecision) { if (tmp.Length == 1) { // first time we've appended, add the decimal point now tmp.Append('.'); } while (i > tmp.Length - 1) { // add any digits that we skipped before tmp.Append('0'); } // round up last digit if necessary if (i == maxPrecision - 1 && i != digits.Length - 1 && digits[i + 1] >= '5') { tmp.Append((char)(digits[i] + 1)); } else { tmp.Append(digits[i]); } } } if (digits.Length <= minPrecision) { if (tmp.Length == 1) { // first time we've appended, add the decimal point now tmp.Append('.'); } while (minPrecision >= tmp.Length - 1) { tmp.Append('0'); } } tmp.Append(lower ? "e+" : "E+"); int digitCnt = digits.Length - 1; if (digitCnt < 10) { tmp.Append('0'); tmp.Append((char)('0' + digitCnt)); } else { tmp.Append(digitCnt.ToString()); } digits = tmp.ToString(); return digits; }
public static string __oct__(BigInteger x) { if (x == BigInteger.Zero) { return "0L"; } else if (x > 0) { return "0" + x.ToString(8) + "L"; } else { return "-0" + (-x).ToString(8) + "L"; } }
private static string/*!*/ ToCultureString(BigInteger/*!*/ val, CultureInfo/*!*/ ci) { string digits; string separator = ci.NumberFormat.NumberGroupSeparator; int[] separatorLocations = ci.NumberFormat.NumberGroupSizes; digits = val.ToString(); if (separatorLocations.Length > 0) { StringBuilder res = new StringBuilder(digits); int curGroup = 0, curDigit = digits.Length - 1; while (curDigit > 0) { // insert the seperator int groupLen = separatorLocations[curGroup]; if (groupLen == 0) { break; } curDigit -= groupLen; if (curDigit >= 0) { res.Insert(curDigit + 1, separator); } // advance the group if (curGroup + 1 < separatorLocations.Length) { if (separatorLocations[curGroup + 1] == 0) { // last value doesn't propagate break; } curGroup++; } } digits = res.ToString(); } return digits; }
public static object ToString(BigInteger/*!*/ self, uint radix) { if (radix < 2 || radix > 36) { throw RubyExceptions.CreateArgumentError(String.Format("illegal radix {0}", radix)); } // TODO: Can we do the ToLower in BigInteger? return MutableString.Create(self.ToString((uint)radix).ToLower()); }
public static object ToString(BigInteger/*!*/ self) { return MutableString.Create(self.ToString()); }
public static MutableString/*!*/ ToString(BigInteger/*!*/ self) { return MutableString.CreateAscii(self.ToString()); }
public static MutableString/*!*/ ToString(BigInteger/*!*/ self, int radix) { if (radix < 2 || radix > 36) { throw RubyExceptions.CreateArgumentError("illegal radix {0}", radix); } // TODO: Can we do the ToLower in BigInteger? return MutableString.CreateAscii(self.ToString(radix).ToLowerInvariant()); }