Example #1
0
        int CheckForULongOverflow()
        {
            switch (this.Kind)
            {
            case NumberKind.Real:
            case NumberKind.Quad:
                int            status;
                LLVMAPFloatRef apFloat       = LLVMExt.APFloatFromAPFloat(APFloat, APFloatSemantics.IEEEquad, out status);
                var            comparisonMax = LLVMExt.APFloatCompare(apFloat, MaxULongValue);
                var            comparisonMin = LLVMExt.APFloatCompare(apFloat, MinULongValue);
                LLVMExt.APFloatDispose(apFloat);

                if (comparisonMax == 2)
                {
                    return(1);
                }
                if (comparisonMin == 0)
                {
                    return(-1);
                }
                return(0);

            default:
                throw new NotSupportedException();
            }
        }
Example #2
0
        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);
            }
        }
Example #3
0
        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);
                }
            }
        }
Example #4
0
        public Number(double 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.ConstReal(LLVM.DoubleType(), number);
                    if (numberKind.IsSigned())
                    {
                        this.Value = LLVM.ConstFPToSI(this.Value, GetLLVMType());
                    }
                    else
                    {
                        this.Value = LLVM.ConstFPToUI(this.Value, GetLLVMType());
                    }
                }
            }
            else
            {
                int state;
                this.APFloat = LLVMExt.APFloatFromDouble(number, GetAPFloatSemantics(this.Kind), out state);
                this.State  |= (NumberState)state;
            }
        }