public Number Mult(Number n) { var opKind = OperationKind(this.Kind, n.Kind); if (this.HasErrors || n.HasErrors) { return(new Number(this.State | n.State, opKind)); } if (opKind.IsInteger()) { var result = LLVM.ConstMul(this.Value, n.Value); var state = CheckForOpOverflow(opKind, result); if (state != NumberState.Ok) { return(new Number(state | this.State | n.State, opKind)); } else { return new Number(dummy: string.Empty) { Value = result, State = this.State | n.State, Kind = opKind } }; } else { var op1 = this.Convert(opKind); var op2 = n.Convert(opKind); if (op1 == this) { op1 = op1.Duplicate(); } op1.State |= (NumberState)LLVMExt.APFloatMult(op1.APFloat, op2.APFloat, RoundingMode); return(op1); } }
public Number Neg() { var opKind = OperationKind(this.Kind, NumberKind.UInt8); if (this.HasErrors) { return(new Number(this.State, opKind)); } if (opKind.IsInteger()) { var result = LLVM.ConstNeg(this.Value); var undef = result.IsUndef(); return(new Number(dummy: string.Empty) { Value = result, State = this.State | (undef ? NumberState.Invalid : NumberState.Ok), Kind = opKind }); } else { var dup = this.Duplicate(); var minusOne = new Number(-1.0, this.Kind); var state = (NumberState)LLVMExt.APFloatMult(dup.APFloat, minusOne.APFloat, RoundingMode); var result = dup.APFloat; dup.APFloat = new LLVMAPFloatRef(IntPtr.Zero); return(new Number(dummy: string.Empty) { APFloat = result, State = this.State | state, Kind = opKind }); } }