예제 #1
0
        public void Equals()
        {
            DoubleType type = (DoubleType)NHibernateUtil.Double;

            Assert.IsTrue(type.IsEqual(1.5e20, 1.5e20));
            Assert.IsFalse(type.IsEqual(1.5e20, 1.4e20));
        }
        public void TestGetDoubleTypeDataType()
        {
            DataTypesFactory dataTypesFactory = GetDataTypesFactory();
            DoubleType       doubleType       = DoubleType.GetDoubleType();

            Assert.AreEqual(doubleType, dataTypesFactory.GetDataType(TypesKeyConstants.DoubleTypeKey));
        }
예제 #3
0
        static void Main(string[] args)
        {
            List <double> valores = new List <double>();

            string valor = "";

            while (!valor.Contains('S'))
            {
                Console.WriteLine("Digite o valor ou S para terminar:");
                valor = Console.ReadLine();
                if (!valor.Contains('S'))
                {
                    valores.Add(DoubleType.FromString(valor));
                }
            }

            Console.WriteLine("Crescente");
            foreach (var item in valores.OrderBy(v => v))
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("Decrescente");
            foreach (var item in valores.OrderByDescending(v => v))
            {
                Console.WriteLine(item);
            }
        }
        public override object Exec(DoubleType firstOperand, object arg)
        {
            // * Double type and bounded type variable
            if (TypeExpression.As <DoubleType>(this.secondOperand) != null)
            {
                return(0);
            }
            // * WriteType variable
            TypeVariable typeVariable = this.secondOperand as TypeVariable;

            if (typeVariable != null && typeVariable.Substitution == null)
            {
                // * A free variable is complete promotion
                return(0);
            }
            // * Union type
            UnionType unionType = TypeExpression.As <UnionType>(this.secondOperand);

            if (unionType != null)
            {
                return(unionType.SuperType(firstOperand));
            }
            // * Field type and bounded type variable
            FieldType fieldType = TypeExpression.As <FieldType>(this.secondOperand);

            if (fieldType != null)
            {
                return(firstOperand.AcceptOperation(new PromotionLevelOperation(fieldType.FieldTypeExpression), arg));
            }
            // * Use the BCL object oriented approach
            return(firstOperand.AsClassType().AcceptOperation(this, arg));
        }
        private IExpressionData getVariable(IObject Data)
        {
            IExpressionData expressionData = null;

            if (Data is VariableData)
            {
                VariableData data = (VariableData)Data;
                if (typeof(Double) == data.type)
                {
                    expressionData = new DoubleType((double)data.value);
                }
                else if (data.type == typeof(String))
                {
                    expressionData = new StringType((string)data.value);
                }
                else if (data.type == typeof(Boolean))
                {
                    expressionData = new BoolType((bool)data.value);
                }
                else
                {
                    throw new Exception("Unknown data type, Expression evaluate");
                }
            }
            else if (Data is ArrayIndex || Data is ArrayObject)
            {
                expressionData = new ObjectType(Data);
            }
            return(expressionData);
        }
예제 #6
0
        /// <summary> 解析字符串 </summary>
        public override void Build(List <string> newStr)
        {
            this.ID = Guid.NewGuid().ToString();

            for (int i = 0; i < newStr.Count; i++)
            {
                switch (i)
                {
                case 0:
                    this.nl0 = newStr[0];
                    break;

                case 1:
                    this.nwp1 = newStr[1];
                    break;

                case 2:
                    this.np2 = newStr[2];
                    break;

                default:
                    break;
                }
            }


            // HTodo  :将解析的孔隙类型增加到主文件中
            if (this.BaseFile != null)
            {
                this.BaseFile.DoubleType = this.DoubleType;
            }
        }
        /// <summary>
        /// Tries a promotion to a double. We have to generate the promotion code for a char and a int, as both can be
        /// promoted to a double
        /// </summary>
        /// <param name="operand"></param>
        /// <returns></returns>
        public override object Exec(DoubleType operand, object arg)
        {
            // * char to double or int to double
            // * If we must promote to an double, a Char or a Int32 could be on the stack
            this.codeGenerator.dup(this.indent);
            this.codeGenerator.isinst(this.indent, CharType.Instance);

            string notACharLabel = this.codeGenerator.NewLabel;

            this.codeGenerator.brfalse(this.indent, notACharLabel);
            this.codeGenerator.UnboxAny(this.indent, CharType.Instance);
            this.codeGenerator.convToDouble(this.indent);

            string endLabel = codeGenerator.NewLabel;

            this.codeGenerator.br(this.indent, endLabel);
            this.codeGenerator.WriteLabel(this.indent, notACharLabel);
            this.codeGenerator.dup(this.indent);
            this.codeGenerator.isinst(this.indent, IntType.Instance);

            string notAInt32Label = this.codeGenerator.NewLabel;

            this.codeGenerator.brfalse(this.indent, notAInt32Label);
            this.codeGenerator.UnboxAny(this.indent, IntType.Instance);
            this.codeGenerator.convToDouble(this.indent);
            this.codeGenerator.br(this.indent, endLabel);
            this.codeGenerator.WriteLabel(this.indent, notAInt32Label);
            this.codeGenerator.UnboxAny(this.indent, DoubleType.Instance);
            this.codeGenerator.WriteLabel(this.indent, endLabel);

            return(null);
        }
        public static bool CanConvert(Type fromType, Type toType)
        {
            if (fromType == toType)
            {
                return(true);
            }

            if (toType.IsAssignableFrom(fromType))
            {
                return(true);
            }

            if (toType.Name == "Nullable`1")
            {
                var genericTypes = toType.GetGenericArguments();
                var genericType  = genericTypes[0];

                toType = genericType;
            }

            if (toType.IsEnum)
            {
                return(true);
            }

            var doubleType = new DoubleType(fromType, toType);

            return(_converters.ContainsKey(doubleType));
        }
 public override object Exec(DoubleType firstOperand, object arg)
 {
     if ((int)this.secondOperand.AcceptOperation(new PromotionLevelOperation(DoubleType.Instance), arg) != -1)
     {
         return(BoolType.Instance);
     }
     return(this.secondOperand.AcceptOperation(new RelationalOperation(firstOperand, this.relationalOperator, this.methodAnalyzed, this.showErrorMessage, this.location), arg));
 }
예제 #10
0
 public override object Exec(DoubleType d, object arg)
 {
     if (TypeExpression.Is <StringType>(this.secondTypeExpression))
     {
         return(d.AcceptOperation(new CGToStringOperation <ILCodeGenerator>(this.codeGenerator, this.indent), true)); // we force a box
     }
     return(null);
 }
예제 #11
0
        public void IsValidDataType_StringifiedInt_ReturnTrue()
        {
            DoubleType doubleType   = CreateDoubleType();
            string     textNoDouble = "1";

            Assert.IsTrue(double.TryParse(textNoDouble, out double parsedNumber));
            Assert.IsTrue(doubleType.IsAValidDataType(textNoDouble));
        }
예제 #12
0
        public void WriteDoubleType_WritesAtLeastOneDecimalPoint()
        {
            // Arrange
            var ft = new DoubleType() { D = 123 };

            // Act
            var s = Toml.WriteString(ft);

            // Assert
            s.Trim().Should().Be("D = 123.0");
        }
예제 #13
0
        public void ParseWithNumberStylesShouldReturnOptionDoubleNone()
        {
            // Arrange
            var             s        = "not a double";
            Option <double> expected = None;

            // Act
            var result = DoubleType.Parse(s, NumberStyles.Number);

            // Assert
            result.Should().Be(expected);
        }
        public static void AddConverter(Type fromType, Type toType, ConvertDelegate converter)
        {
            var doubleType = new DoubleType(fromType, toType);

            lock (_lockObject)
            {
                if (!_converters.ContainsKey(doubleType))
                {
                    _converters.Add(doubleType, converter);
                }
            }
        }
예제 #15
0
 public void Clear()
 {
     this.pNext      = (AppMain.AMS_TRAIL_EFFECT)null;
     this.pPrev      = (AppMain.AMS_TRAIL_EFFECT)null;
     this.Procedure  = (DoubleType <AppMain.AMTREffectProc, int>)(AppMain.AMTREffectProc) null;
     this.Destractor = (DoubleType <AppMain.AMTREffectProc, int>)(AppMain.AMTREffectProc) null;
     this.fFrame     = this.fEndFrame = 0.0f;
     this.drawState  = 0U;
     this.handleId   = (ushort)0;
     this.flag       = (short)0;
     this.Work.Clear();
 }
예제 #16
0
        public void ParseWithNumberStylesShouldReturnOptionDoubleNoneWhenStringIsNotExpectedHexNumber()
        {
            // Arrange
            var             s        = "1.0";
            Option <double> expected = None;

            // Act
            var result = DoubleType.Parse(s, NumberStyles.HexNumber);

            // Assert
            result.Should().Be(expected);
        }
예제 #17
0
        public void ParseShouldReturnOptionDoubleSome()
        {
            // Arrange
            var             s        = "1.1";
            Option <double> expected = Some(1.1);

            // Act
            var result = DoubleType.Parse(s);

            // Assert
            result.Should().Be(expected);
        }
예제 #18
0
        private static string word2(string numb, string param)
        {
            string[] textArray1;
            string   text2 = "";

            if (Strings.Len(numb) == 1)
            {
                textArray1 = new string[] { text2, Word(numb), " ", param, " " };
                return(string.Concat(textArray1));
            }
            if (Strings.Len(numb) == 2)
            {
                if (Conversion.Val(numb) == 0)
                {
                    return(text2);
                }
                if ((DoubleType.FromString(numb) > 0) & (DoubleType.FromString(numb) < 20))
                {
                    textArray1 = new string[] { text2, Word(numb), " ", param, " " };
                    return(string.Concat(textArray1));
                }
                textArray1 = new string[] { text2, Word(StringType.FromDouble(DoubleType.FromString(Strings.Left(numb, 1)) * 10)), " ", Word(Strings.Mid(numb, 2, 1)), " ", param, " " };
                return(string.Concat(textArray1));
            }
            if (Strings.Len(numb) == 3)
            {
                string text1 = Strings.Mid(numb, 1, 1);
                if (Conversion.Int(Conversion.Val(text1)) != 0)
                {
                    text2 = text2 + Word(Strings.Mid(numb, 1, 1)) + " hundred ";
                }
                text1 = Strings.Mid(numb, 2, 2);
                if (Conversion.Val(text1) == 0)
                {
                    if (DoubleType.FromString(Strings.Mid(numb, 1, 1)) != 0)
                    {
                        text2 = text2 + " " + param + " ";
                    }
                }
                else if (((Conversion.Val(text1) > 0) & (Conversion.Val(text1) < 20)) | ((DoubleType.FromString(text1) % 10) == 0))
                {
                    textArray1 = new string[] { text2, Word(Strings.Mid(numb, 2, 2)), " ", param, " " };
                    text2      = string.Concat(textArray1);
                }
                else
                {
                    textArray1 = new string[] { text2, Word(StringType.FromDouble(DoubleType.FromString(Strings.Mid(numb, 2, 1)) * 10)), " ", Word(Strings.Mid(numb, 3, 1)), " ", param, " " };
                    text2      = string.Concat(textArray1);
                }
            }
            return(text2);
        }
예제 #19
0
        public override LiteralNode VisitNumber([NotNull] NumberContext context)
        {
            var   doub = context.Double();
            var   txt  = context.GetText();
            IType typ  = new IntType();

            if (doub != null)
            {
                typ = new DoubleType();
            }

            return(new LiteralNode(context.GetText(), typ, GetLocation(context)));
        }
예제 #20
0
 private void btnBusqNom_Click(object sender, EventArgs e)
 {
     new frmBusqClixNom().ShowDialog();
     if (DoubleType.FromString(Variables.gCodCli) == 0.0)
     {
         this.editCodCli.Text = "";
     }
     else
     {
         this.editCodCli.Text = Variables.gCodCli;
     }
     this.editDescCli.Text = Variables.gNomCli;
 }
        /// <summary>
        /// Checks if the Double Type parameter passed (operand) matches with the proper argument.
        /// It makes to 3calls to CGRuntimeCheckTypeExpressionOperation operation. One using a CharType object, second
        /// with IntType object, and last usint a double type, all of them trying a convert to double (toDouble parameter = true)
        /// </summary>
        /// <param name="operand">DoubleType parameter to check</param>
        /// <returns></returns>
        public override object Exec(DoubleType operand, object arg)
        {
            string nextArgument = this.codeGenerator.NewLabel;

            CharType.Instance.AcceptOperation(new CGRuntimeCheckTypeExpressionOperation <T>(this.indent, this.codeGenerator, nextArgument, true), arg);
            IntType.Instance.AcceptOperation(new CGRuntimeCheckTypeExpressionOperation <T>(this.indent, this.codeGenerator, nextArgument, true), arg);
            DoubleType.Instance.AcceptOperation(new CGRuntimeCheckTypeExpressionOperation <T>(this.indent, this.codeGenerator, nextArgument, true), arg);

            nextMethod.Add(this.codeGenerator.NewLabel);
            this.codeGenerator.br(this.indent, this.nextMethod[this.nextMethod.Count - 1]);
            this.codeGenerator.WriteLabel(this.indent, nextArgument);
            return(null);
        }
 /// <summary>
 /// The first Operand is a Double so the second must be promotable to a DoubleType so the whole operation must have sense.
 /// Implements a double dispatch pattern.
 /// </summary>
 /// <param name="firstOperand">A double type to perform a binary arithmetica operation with. The second operate have to be promotable
 /// to Double, cause is the grater integral value.</param>
 /// <returns>A TypeExpression if the operation makes sense, otherwise if showMessages is true, an error is raised</returns>
 public override object Exec(DoubleType firstOperand, object arg)
 {
     if ((int)this.secondOperand.AcceptOperation(new PromotionLevelOperation(firstOperand), arg) != -1)
     {
         return(DoubleType.Instance);
     }
     if (this.binaryOperator.Equals(ArithmeticOperator.Plus) && (bool)this.secondOperand.AcceptOperation(new EquivalentOperation(StringType.Instance), arg))
     {
         return(StringType.Instance);
     }
     // We rely in arithmetic conmutativiness to perform a cross recursion. Could it be dangerous?
     return(secondOperand.AcceptOperation(ArithmeticalOperation.Create(firstOperand, this.binaryOperator, this.methodAnalyzed, this.showErrorMessage, this.location), arg));
 }
예제 #23
0
 public void FromObject()
 {
     Assert.Equal(0d, DoubleType.FromObject(null));
     Assert.Equal(-1d, DoubleType.FromObject(true));
     Assert.Equal(123d, DoubleType.FromObject((byte)123));
     Assert.Equal(123d, DoubleType.FromObject((short)123));
     Assert.Equal(123d, DoubleType.FromObject((int)123));
     Assert.Equal(123d, DoubleType.FromObject((long)123));
     Assert.Equal(123d, DoubleType.FromObject((float)123));
     Assert.Equal(123d, DoubleType.FromObject((double)123));
     Assert.Equal(123d, DoubleType.FromObject((decimal)123));
     Assert.Equal(123d, DoubleType.FromObject("123"));
 }
        /// <summary>
        /// It tries to convert the top of the stack to a generic DoubleType indicated by operand.
        /// </summary>
        /// <param name="operand">DoubleType we want to convert to</param>
        /// <returns></returns>
        public override object Exec(DoubleType operand, object arg)
        {
            string notThisType = this.codeGenerator.NewLabel;

            this.codeGenerator.dup(this.indent);
            this.codeGenerator.isinst(this.indent, operand);
            this.codeGenerator.brfalse(this.indent, notThisType);
            this.codeGenerator.UnboxAny(this.indent, operand);
            this.codeGenerator.br(this.indent, endLabel);
            this.codeGenerator.WriteLabel(this.indent, notThisType);

            return(null);
        }
예제 #25
0
        /// <summary>Returns a <see langword="Boolean" /> value indicating whether an expression can be evaluated as a number.</summary>
        /// <param name="Expression">Required. <see langword="Object" /> expression.</param>
        /// <returns>Returns a <see langword="Boolean" /> value indicating whether an expression can be evaluated as a number.</returns>
        public static bool IsNumeric(object Expression)
        {
            IConvertible convertible = Expression as IConvertible;

            if (convertible == null)
            {
                char[] chArray = Expression as char[];
                if (chArray == null)
                {
                    return(false);
                }
                Expression = (object)new string(chArray);
            }
            TypeCode typeCode = convertible.GetTypeCode();

            switch (typeCode)
            {
            case TypeCode.Char:
            case TypeCode.String:
                string str = convertible.ToString((IFormatProvider)null);
                try
                {
                    long i64Value = 0;
                    if (Utils.IsHexOrOctValue(str, ref i64Value))
                    {
                        return(true);
                    }
                }
                catch (StackOverflowException ex)
                {
                    throw ex;
                }
                catch (OutOfMemoryException ex)
                {
                    throw ex;
                }
                catch (ThreadAbortException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    return(false);
                }
                double Result = 0;
                return(DoubleType.TryParse(str, ref Result));

            default:
                return(Information.IsOldNumericTypeCode(typeCode));
            }
        }
예제 #26
0
        // Format a percentage value.
        public static String FormatPercent
            (Object Expression,
            [Optional][DefaultValue(-1)] int NumDigitsAfterDecimal,
            [Optional][DefaultValue(TriState.UseDefault)]
            TriState IncludeLeadingDigit,
            [Optional][DefaultValue(TriState.UseDefault)]
            TriState UseParensForNegativeNumbers,
            [Optional][DefaultValue(TriState.UseDefault)]
            TriState GroupDigits)
        {
            NumberFormatInfo nfi        = CultureInfo.CurrentCulture.NumberFormat;
            NumberFormatInfo nfiCurrent = nfi;

            if (NumDigitsAfterDecimal != -1)
            {
                nfi = (NumberFormatInfo)(nfi.Clone());
                nfi.PercentDecimalDigits = NumDigitsAfterDecimal;
            }
            if (UseParensForNegativeNumbers != TriState.UseDefault)
            {
                if (nfi == nfiCurrent)
                {
                    nfi = (NumberFormatInfo)(nfi.Clone());
                }
                if (UseParensForNegativeNumbers == TriState.False)
                {
                    nfi.PercentNegativePattern = 0;
                }
                else
                {
                    nfi.PercentNegativePattern = 1;
                }
            }
            if (GroupDigits != TriState.UseDefault)
            {
                if (nfi == nfiCurrent)
                {
                    nfi = (NumberFormatInfo)(nfi.Clone());
                }
                if (GroupDigits == TriState.False)
                {
                    nfi.PercentGroupSizes = new int [] { 0 };
                }
                else
                {
                    nfi.PercentGroupSizes = new int [] { 3 };
                }
            }
            return(DoubleType.FromObject(Expression).ToString("P", nfi));
        }
예제 #27
0
        public void WriteDoubleType_WritesAtLeastOneDecimalPoint()
        {
            // Arrange
            var ft = new DoubleType()
            {
                D = 123
            };

            // Act
            var s = Toml.WriteString(ft);

            // Assert
            s.Trim().Should().Be("D = 123.0");
        }
예제 #28
0
        public static bool IsNumeric(object Expression)
        {
            double       num;
            IConvertible convertible = Expression as IConvertible;

            if (convertible == null)
            {
                char[] chArray = Expression as char[];
                if (chArray == null)
                {
                    return(false);
                }
                Expression = new string(chArray);
            }
            TypeCode typeCode = convertible.GetTypeCode();

            if ((typeCode != TypeCode.String) && (typeCode != TypeCode.Char))
            {
                return(IsOldNumericTypeCode(typeCode));
            }
            string str = convertible.ToString(null);

            try
            {
                long num2;
                if (Utils.IsHexOrOctValue(str, ref num2))
                {
                    return(true);
                }
            }
            catch (StackOverflowException exception)
            {
                throw exception;
            }
            catch (OutOfMemoryException exception2)
            {
                throw exception2;
            }
            catch (ThreadAbortException exception3)
            {
                throw exception3;
            }
            catch (Exception)
            {
                return(false);
            }
            return(DoubleType.TryParse(str, ref num));
        }
예제 #29
0
        public void ParseWithNumberStylesAndFormatProviderShouldReturnOptionDoubleNone()
        {
            // Arrange
            var             s = "p1$234.5";
            IFormatProvider formatProvider = new NumberFormatInfo()
            {
                PositiveSign = "p"
            };
            Option <double> expected = None;

            // Act
            var result = DoubleType.Parse(s, NumberStyles.Number, formatProvider);

            // Assert
            result.Should().Be(expected);
        }
예제 #30
0
        public static AtomType Consume(Parser parser)
        {
            AtomType atomType = null;

            switch (parser.LookAhead().Type)
            {
            case TokenInfo.TokenType.BOOL:
                parser.Eat(TokenInfo.TokenType.BOOL);
                atomType = new BoolType();
                break;

            case TokenInfo.TokenType.CHAR:
                parser.Eat(TokenInfo.TokenType.CHAR);
                atomType = new CharType();
                break;

            case TokenInfo.TokenType.DOUBLE:
                parser.Eat(TokenInfo.TokenType.DOUBLE);
                atomType = new DoubleType();
                break;

            case TokenInfo.TokenType.INT:
                parser.Eat(TokenInfo.TokenType.INT);
                atomType = new IntType();
                break;

            case TokenInfo.TokenType.STRING:
                parser.Eat(TokenInfo.TokenType.STRING);
                atomType = new StringType();
                break;

            case TokenInfo.TokenType.VOID:
                parser.Eat(TokenInfo.TokenType.VOID);
                atomType = new VoidType();
                break;

            default:
                break;
            }

            if (atomType == null)
            {
                throw new ParserError(new FailedConsumer(), parser.Cursor);
            }

            return(atomType);
        }
예제 #31
0
        public void ParseWithFormatProviderShouldReturnOptionDoubleSome()
        {
            // Arrange
            var             s = "p1234.5";
            IFormatProvider formatProvider = new NumberFormatInfo()
            {
                PositiveSign = "p"
            };

            Option <double> expected = Some(1234.5);

            // Act
            var result = DoubleType.Parse(s, formatProvider);

            // Assert
            result.Should().Be(expected);
        }