public Number(string number, NumberKind numberKind) { if (number == null) { throw new ArgumentNullException(nameof(number)); } this.Kind = numberKind; if (numberKind.IsInteger()) { this.State = CheckIntegerString(number, numberKind); if (!this.HasErrors) { this.Value = LLVM.ConstIntOfString(LLVM.Int128Type(), number, 10); } } else { this.State = CheckFloatString(number); if (!this.HasErrors) { this.APFloat = LLVMExt.APFloatZero(GetAPFloatSemantics(this.Kind)); this.State |= (NumberState)LLVMExt.APFloatFromString(this.APFloat, number, RoundingMode); } } }
public Number(ulong number, NumberKind numberKind) { this.Kind = numberKind; if (numberKind.IsInteger()) { var overflows = CheckForOverflow(number, numberKind); if (overflows == 1) { this.State = NumberState.Overflow; } else if (overflows == -1) { this.State = NumberState.Underflow; } if (!HasErrors) { this.Value = LLVM.ConstInt(GetLLVMType(), number, new LLVMBool(0)); } } else { this.APFloat = LLVMExt.APFloatZero(GetAPFloatSemantics(this.Kind)); this.State |= (NumberState)LLVMExt.APFloatFromString(this.APFloat, number.ToString(CultureInfo.InvariantCulture), RoundingMode); } }
static Number() { MaxLongValue = LLVMExt.APFloatZero(APFloatSemantics.IEEEquad); MinLongValue = LLVMExt.APFloatZero(APFloatSemantics.IEEEquad); MaxULongValue = LLVMExt.APFloatZero(APFloatSemantics.IEEEquad); MinULongValue = LLVMExt.APFloatZero(APFloatSemantics.IEEEquad); LLVMExt.APFloatFromString(MaxLongValue, long.MaxValue.ToString(CultureInfo.InvariantCulture), RoundingMode); LLVMExt.APFloatFromString(MinLongValue, long.MinValue.ToString(CultureInfo.InvariantCulture), RoundingMode); LLVMExt.APFloatFromString(MaxULongValue, ulong.MaxValue.ToString(CultureInfo.InvariantCulture), RoundingMode); LLVMExt.APFloatFromString(MinULongValue, ulong.MinValue.ToString(CultureInfo.InvariantCulture), RoundingMode); MaxLongLLVMValue = LLVM.ConstInt(LLVM.Int128Type(), long.MaxValue, new LLVMBool(1)); MinLongLLVMValue = LLVM.ConstInt(LLVM.Int128Type(), unchecked ((ulong)long.MinValue), new LLVMBool(1)); MaxULongLLVMValue = LLVM.ConstInt(LLVM.Int128Type(), ulong.MaxValue, new LLVMBool(0)); }