public override (object, int) Decode(byte[] data, int position) { Array result = Array.CreateInstance(_elementType.CSharpType, Length); if (_elementType.IsDynamic) { BigInteger currentOffset = (Length - 1) * UInt.LengthInBytes; int lengthsPosition = position; for (int i = 0; i < Length; i++) { if (i != 0) { (currentOffset, lengthsPosition) = UInt.DecodeUInt(data, lengthsPosition); } object element; (element, currentOffset) = _elementType.Decode(data, position + (int)currentOffset); result.SetValue(element, i); } position = (int)currentOffset; } else { for (int i = 0; i < Length; i++) { (object element, int newPosition) = _elementType.Decode(data, position); result.SetValue(element, i); position = newPosition; } } return(result, position); }
public static ULong BigSqrtRem(ULong lo, UInt hi, out ULong remainder) { unchecked { if (0u == hi) { return(Mathematics.Elementary.Math.SqrtRem(lo, out remainder)); } var old = (ULong)Math.Sqrt((0.0 + ((ULong)1u << (Misc.ULong.BitSize - 1)) + ((ULong)1u << (Misc.ULong.BitSize - 1))) * hi + lo); ULong h; var l = MathEx.BigSquare(old, out h); l += lo; h += hi; if (l < lo) { ++h; } var @new = MathEx.BigDivNoThrow(l, h, old) >> 1; l = MathEx.BigSquare(@new, out h); if ((h > hi) || ((h == hi) && (l > lo))) { remainder = lo - l - ((@new << 1) - 1u); return(@new - (ULong)1u); } else { remainder = lo - l; return(@new); } } }
public static ULong BigSqrt(ULong lo, UInt hi) { unchecked { if (0u == hi) { return(Mathematics.Elementary.Math.Sqrt(lo)); } var old = (ULong)Math.Sqrt((0.0 + ((ULong)1u << (ULong_Misc.BitSizeAsIntUnchecked - 1)) + ((ULong)1u << (ULong_Misc.BitSizeAsIntUnchecked - 1))) * hi + lo); ULong h; var l = MathEx.BigSquare(old, out h); l += lo; h += hi; if (l < lo) { ++h; } var @new = MathEx.BigDivUnchecked(l, h, old) >> 1; l = MathEx.BigSquare(@new, out h); if ((h > hi) || ((h == hi) && (l > lo))) { return(@new - (ULong)1u); } else { return(@new); } } }
public override (object, int) Decode(byte[] data, int position, bool packed) { (BigInteger length, int currentPosition) = UInt.DecodeUInt(data, position, packed); int paddingSize = packed ? (int)length : (1 + (int)length / PaddingMultiple) * PaddingMultiple; return(data.Slice(currentPosition, (int)length), currentPosition + paddingSize); }
public override int GetHashCode() { var hashCode = 291051517; hashCode = hashCode * -1521134295 + Int.GetHashCode(); hashCode = hashCode * -1521134295 + Long.GetHashCode(); hashCode = hashCode * -1521134295 + Short.GetHashCode(); hashCode = hashCode * -1521134295 + UInt.GetHashCode(); hashCode = hashCode * -1521134295 + ULong.GetHashCode(); hashCode = hashCode * -1521134295 + UShort.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <int?> .Default.GetHashCode(NullableInt); hashCode = hashCode * -1521134295 + Byte.GetHashCode(); hashCode = hashCode * -1521134295 + SByte.GetHashCode(); hashCode = hashCode * -1521134295 + Bool.GetHashCode(); hashCode = hashCode * -1521134295 + Float.GetHashCode(); hashCode = hashCode * -1521134295 + Double.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <byte[]> .Default.GetHashCode(ByteArray); hashCode = hashCode * -1521134295 + Decimal.GetHashCode(); hashCode = hashCode * -1521134295 + DateTime.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(String); return(hashCode); }
public void GetUIntSetting() { var expected = SettingResponse <uint> .Create(true, 7); var actual = UInt.TryGetUIntSetting(); Assert.AreEqual(expected, actual); }
UInt32 getBitsSafe(UInt nbits) { if (nbits > Math.Math.Min((_GET_BITS) throw new IOException("Too many bits requested"); fill(); checkPos(); return getBitsNoFill(nbits); }
// Free the data in this object. public void Free() { if (data != IntPtr.Zero) { Marshal.FreeHGlobal(data); data = IntPtr.Zero; size = (UInt)0; } }
void setAbsoluteOffset(UInt offset) { if (offset >= size) throw IOException("Offset set out of buffer"); mLeft = 0; off = offset; _fill(); }
public static UInt BigMul_M(ULong first, UInt second, out ULong lowResult) { var lo = unchecked ((ULong)(UInt)first * (UInt)second); var yl = unchecked ((first >> UInt_Misc.BitSizeAsIntUnchecked) * (UInt)second); var yh = unchecked (lo + (yl << UInt_Misc.BitSizeAsIntUnchecked)); lowResult = yh; return(unchecked (((UInt)(yl >> UInt_Misc.BitSizeAsIntUnchecked)) + ((lo > yh ? (UInt)1 : 0)))); }
public void TryParseUIntTest() { Assert.IsTrue(UInt.TryParse("1", out UInt @uint)); Assert.AreEqual(1ul, @uint); Assert.IsTrue(UInt.TryParse("1".GetBytes(), out @uint)); Assert.AreEqual(1ul, @uint); Assert.IsTrue(UInt.TryParse("0", out @uint)); Assert.AreEqual(0ul, @uint); Assert.IsTrue(UInt.TryParse("0".GetBytes(), out @uint)); Assert.AreEqual(0ul, @uint); Assert.IsFalse(UInt.TryParse(ulong.MaxValue.ToString(), out @uint)); Assert.AreEqual(default, @uint);
void skipBits(UInt nbits) { int skipn = nbits; while (skipn) { fill(); checkPos(); int n = Math.Math.Min(((skipn, mLeft); mLeft -= n; skipn -= n; } }
public override int GetHashCode() { var hash = 19; hash = hash * 7 + Bool.GetHashCode(); hash = hash * 7 + Int.GetHashCode(); hash = hash * 7 + UInt.GetHashCode(); hash = hash * 7 + Float.GetHashCode(); hash = hash * 7 + Char.GetHashCode(); hash = hash * 7 + Str.GetHashCode(); return(hash); }
public Reaction(Func<Item> result, uint reactionTime, params Type[] tReagents) { reaction = reagents => { Array.ForEach(reagents, reagent => { reagent.Clear(); }); return result(); }; this.reactionTime = (UInt)reactionTime; this.currentTime = (UInt)reactionTime; this.tReagents = tReagents; }
public void testAtaqueInterfazUINT() { string[] golpe = { "golpe" }; var d = new UInt(3); iAttack <uint> atk = new AttackSimple <uint>(golpe[0], d); var atkcp = atk.copy(); //atq.Ataque queda testeado por iVar Assert.AreEqual(atk.getTypes(), golpe); Assert.AreEqual(atk.getTypes(), atkcp.getTypes()); Assert.AreEqual(atk.getAttack(golpe[0]), 3); Assert.AreEqual(atk.getAttack(golpe[0]), atkcp.getAttack(golpe[0])); }
public override byte[] Encode(object arg, bool packed) { if (arg is BigRational input) { if (_denominator != input.Denominator) { throw new AbiException(AbiEncodingExceptionMessage); } return(UInt.Encode(input.Numerator, packed)); } throw new AbiException(AbiEncodingExceptionMessage); }
public override int GetHashCode() { unchecked { var hashCode = (Byte != null ? Byte.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (SByte != null ? SByte.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Short != null ? Short.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (UShort != null ? UShort.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Int != null ? Int.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (UInt != null ? UInt.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Long != null ? Long.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ULong != null ? ULong.GetHashCode() : 0); return(hashCode); } }
public override byte[] Encode(object arg) { if (arg is Address input) { byte[] bytes = input.Bytes; return UInt.Encode(bytes.ToUnsignedBigInteger()); } if (arg is string stringInput) { return Encode(new Address(stringInput)); } throw new AbiException(AbiEncodingExceptionMessage); }
public override int GetHashCode() { unchecked { var hashCode = Byte.GetHashCode(); hashCode = (hashCode * 397) ^ SByte.GetHashCode(); hashCode = (hashCode * 397) ^ Short.GetHashCode(); hashCode = (hashCode * 397) ^ UShort.GetHashCode(); hashCode = (hashCode * 397) ^ Int.GetHashCode(); hashCode = (hashCode * 397) ^ UInt.GetHashCode(); hashCode = (hashCode * 397) ^ Long.GetHashCode(); hashCode = (hashCode * 397) ^ ULong.GetHashCode(); return(hashCode); } }
public override byte[] Encode(object arg, bool packed) { if (arg is byte[] input) { int paddingSize = (1 + input.Length / PaddingMultiple) * PaddingMultiple; byte[] lengthEncoded = UInt.Encode(new BigInteger(input.Length), packed); return(Bytes.Concat(lengthEncoded, packed ? input : input.PadRight(paddingSize))); } if (arg is string stringInput) { return(Encode(Encoding.ASCII.GetBytes(stringInput), packed)); } throw new AbiException(AbiEncodingExceptionMessage); }
public override byte[] Encode(object arg, bool packed) { if (arg is Array input) { byte[][] encodedItems = new byte[input.Length + 1][]; int i = 0; encodedItems[i++] = UInt.Encode((BigInteger)input.Length, packed); foreach (object o in input) { encodedItems[i++] = _elementType.Encode(o, packed); } return(Bytes.Concat(encodedItems)); } throw new AbiException(AbiEncodingExceptionMessage); }
public override (object, int) Decode(byte[] data, int position, bool packed) { BigInteger length; (length, position) = UInt.DecodeUInt(data, position, packed); Array result = Array.CreateInstance(_elementType.CSharpType, (int)length); for (int i = 0; i < length; i++) { object element; (element, position) = _elementType.Decode(data, position, packed); result.SetValue(element, i); } return(result, position); }
public override byte[] Encode(object arg) { if (arg is Array input) { if (input.Length != Length) { throw new AbiException(AbiEncodingExceptionMessage); } if (_elementType.IsDynamic) { byte[][] encodedItems = new byte[Length * 2 - 1][]; BigInteger currentOffset = (Length - 1) * UInt.LengthInBytes; int i = 0; foreach (object o in input) { encodedItems[Length + i - 1] = _elementType.Encode(o); if (i != 0) { currentOffset += new BigInteger(encodedItems[Length + i - 1].Length); encodedItems[i - 1] = UInt.Encode(currentOffset); } i++; } return(Bytes.Concat(encodedItems)); } else { byte[][] encodedItems = new byte[Length][]; int i = 0; foreach (object o in input) { encodedItems[i++] = _elementType.Encode(o); } return(Bytes.Concat(encodedItems)); } } throw new AbiException(AbiEncodingExceptionMessage); }
public object Apply(object a, object b) { return(a switch { // Integral types byte bt => Byte?.Invoke(bt, Convert.ToByte(b)), sbyte sb => SByte?.Invoke(sb, Convert.ToSByte(b)), short sh => Short?.Invoke(sh, Convert.ToInt16(b)), ushort ush => UShort?.Invoke(ush, Convert.ToUInt16(b)), int i => Int?.Invoke(i, Convert.ToInt32(b)), uint ui => UInt?.Invoke(ui, Convert.ToUInt32(b)), long l => Long?.Invoke(l, Convert.ToInt64(b)), ulong ul => ULong?.Invoke(ul, Convert.ToUInt64(b)), float f => Float?.Invoke(f, Convert.ToSingle(b)), double d => Double?.Invoke(d, Convert.ToDouble(b)), decimal dec => Decimal?.Invoke(dec, Convert.ToDecimal(b)), string str => String?.Invoke(str, Convert.ToString(b)), DateTime dt => DateTime?.Invoke(dt, TimeUtils.TimeSpanOf(b)), TimeSpan ts => TimeSpan?.Invoke(ts, b), _ => throw new ArgumentException($"I don't know how to coercively operate on {a.GetType()} and {b.GetType()}!") } ?? throw DoesNotApply(a, b));
public void testUInt() { var uInt = new UInt(20); var cp = uInt.copy(); Assert.AreEqual(uInt.get(), 20); Assert.AreEqual(uInt.get(), cp.get()); Assert.AreEqual(uInt.nulo(), 0); uInt.add(20); uInt.reduce(10); Assert.AreEqual(uInt.get(), 30); Assert.AreNotEqual(uInt.get(), cp.get()); uInt.mult(10f); Assert.AreEqual(uInt.get(), 300); uInt.set(200); Assert.AreEqual(uInt.get(), 200); }
extern public static UInt jpeg_write_scanlines (ref jpeg_compress_struct cinfo, ref IntPtr scanline, UInt num_lines);
extern private static gnutls_datum *gnutls_certificate_get_peers (IntPtr session, out UInt size);
// Constructor. public gnutls_datum(byte[] value) { data = Marshal.AllocHGlobal(value.Length); Marshal.Copy(value, 0, data, value.Length); size = (UInt)(value.Length); }
extern public static UInt jpeg_read_scanlines (ref jpeg_decompress_struct cinfo, ref IntPtr scanline, UInt max_lines);
public Equipo(uint durabilidadMaxima, PesoEquipo tpPeso, float peso) { durabilidad = new UInt(durabilidadMaxima); this.peso = peso; tipoEquipo = tpPeso; }
void skipBitsNoFill(UInt nbits) { mLeft -= nbits; }
public BodyPart(uint condition = 100) { this.condition = (UInt)condition; }