/// <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 ConvertSigned(Signed src, TypeDescriptor dstType) { Contract.Requires <ArgumentNullException>(dstType != null, "dstType"); if (dstType.CILType.Equals(typeof(Signed))) { return(src.Resize(SFix.GetFormat(dstType).IntWidth)); } else if (dstType.CILType.Equals(typeof(SFix))) { return(SFix.FromSigned(src.Resize(SFix.GetFormat(dstType).TotalWidth), SFix.GetFormat(dstType).FracWidth)); } else { return(ConvertSigned(src, dstType.CILType)); } }
public static Signed SignedAbs(Signed value) { return(value.BigIntValue.Sign < 0 ? (-value).Resize(value.Size + 1) : value.Resize(value.Size + 1)); }