/// <summary> /// Converts <paramref name="src"/> to <paramref name="dstType"/> datatype, possibly with loss of precision or overflow. /// </summary> /// <remarks>Currently, conversions between all primitive numeric CIL types, enum types, and System#-intrinsic datatypes /// Signed, Unsigned, SFix, UFix and StdLogicVector are supported.</remarks> /// <exception cref="ArgumentNullException">if <paramref name="dstType"/> is null</exception> /// <exception cref="NotImplementedException">if there is no known conversion to <paramref name="dstType"/></exception> public static object ConvertLong(long src, TypeDescriptor dstType) { Contract.Requires <ArgumentNullException>(dstType != null, "dstType"); if (dstType.CILType.Equals(typeof(Signed))) { return(Signed.FromLong(src, SFix.GetFormat(dstType).IntWidth)); } else if (dstType.CILType.Equals(typeof(Unsigned))) { return(Unsigned.FromBigInt(new System.Numerics.BigInteger(src), UFix.GetFormat(dstType).IntWidth)); } else if (dstType.CILType.Equals(typeof(SFix))) { return(SFix.FromSigned(Signed.FromLong(src, SFix.GetFormat(dstType).IntWidth), SFix.GetFormat(dstType).FracWidth)); } else if (dstType.CILType.Equals(typeof(StdLogicVector))) { return(StdLogicVector.FromLong(src, StdLogicVector.GetLength(dstType))); } else { return(ConvertLong(src, dstType.CILType)); } }
public static Unsigned Abs(Signed value) { return(value.BigIntValue.Sign < 0 ? Unsigned.FromBigInt(-value.BigIntValue, value.Size) : Unsigned.FromBigInt(value.BigIntValue, value.Size)); }