Example #1
0
 public override AType ExecutePrimitive(AFloat argument, Aplus environment = null)
 {
     int result;
     if(argument.ConvertToRestrictedWholeNumber(out result))
     {
         return calculateNot(result);
     }
     throw new Error.Type(TypeErrorText);
 }
Example #2
0
        /// <summary>
        /// Returns AInteger or AFloat based on the input number.
        /// If the number can be represented as an integer return AInteger
        /// otherwise return AFloat.
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public static AType CreateATypeResult(double number)
        {
            int result;

            if (ConvertDoubleToInteger(number, out result))
            {
                return(AInteger.Create(result));
            }
            return(AFloat.Create(number));
        }
Example #3
0
        public override AType ExecutePrimitive(AFloat argument, Aplus environment = null)
        {
            int number;
            if (!argument.ConvertToRestrictedWholeNumber(out number))
            {
                throw new Error.Type("Bitwise not");
            }

            return AInteger.Create(~number);
        }
Example #4
0
        public override AType ExecutePrimitive(AFloat argument, Aplus environment)
        {
            int seed = GetSeed(environment);
            int result;
            if (!argument.ConvertToRestrictedWholeNumber(out result))
            {
                throw new Error.Type(TypeErrorText);
            }

            return generateRandomNumber(seed, result);
            
        }
Example #5
0
        public override AType ExecutePrimitive(AFloat argument, Aplus environment = null)
        {
            double result;

            if (Utils.TryComprasionTolarence(argument.asFloat, out result))
            {
                return Utils.CreateATypeResult(result);
            }

            result = Math.Ceiling(argument.asFloat);
            return Utils.CreateATypeResult(result);
        }
Example #6
0
        public override bool Equals(object obj)
        {
            if (obj is AInteger)
            {
                AInteger other = (AInteger)obj;
                return(this.asInteger == other.asInteger);
            }
            else if (obj is AFloat)
            {
                AFloat other = (AFloat)obj;
                return(other.IsTolerablyWholeNumber && (this.asInteger == other.asInteger));
            }

            return(false);
        }
Example #7
0
        private static void PerformIndexAssign(AType target, AType value)
        {
            if (target.Rank > 0)
            {
                for (int i = 0; i < target.Length; i++)
                {
                    PerformIndexAssign(target[i], value.IsArray ? value[i] : value);
                }
            }
            else
            {
                AValue result;

                if (target.Type == value.Type)
                {
                    result = value.Clone().Data;
                }
                else if (target.Type == ATypes.AInteger && value.Type == ATypes.AFloat)
                {
                    int number;
                    if (!value.ConvertToRestrictedWholeNumber(out number))
                    {
                        throw new Error.Type("assign");
                    }

                    result = AInteger.Create(number).Data;
                }
                else if (target.Type == ATypes.AFloat && value.Type == ATypes.AInteger)
                {
                    result = AFloat.Create(value.asInteger).Data;
                }
                else
                {
                    throw new Error.Type("Assign");
                }

                if (target.IsMemoryMappedFile)
                {
                    ((IMapped)target.Data).Update(result);
                }
                else
                {
                    target.Data = result;
                }
            }
        }
Example #8
0
        /// <summary>
        /// AArray generated by type and shape with Reshape dyadic nonscalar function.
        /// If shape list is null, we give back the filler elemenet.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="shape"></param>
        internal static AType FillElement(ATypes type, AType shape = null)
        {
            AType filler = null;

            switch (type)
            {
            case ATypes.ABox:
            case ATypes.AFunc:
                filler = ABox.Create(ANull());
                break;

            case ATypes.AChar:
                filler = AChar.Create(' ');
                break;

            case ATypes.AFloat:
                filler = AFloat.Create(0);
                break;

            case ATypes.AInteger:
                filler = AInteger.Create(0);
                break;

            case ATypes.ASymbol:
                filler = ASymbol.Create("");
                break;

            default:
                throw new NotImplementedException("Invalid use-case");
            }

            if (shape != null)
            {
                return(AplusCore.Runtime.Function.Dyadic.DyadicFunctionInstance.Reshape.Execute(filler, shape));
            }
            else
            {
                return(filler);
            }
        }
Example #9
0
        /// <summary>
        /// Converts AType elements to float
        /// </summary>
        public static AType ConvertToFloat(this AType input)
        {
            if (input.Type != ATypes.AFloat && input.Type != ATypes.AInteger && input.Type != ATypes.AArray)
            {
                throw new Error.Type("Conversion");
            }

            if (input.IsArray)
            {
                for (int i = 0; i < input.Length; i++)
                {
                    input[i] = Utils.ConvertToFloat(input[i]);
                }

                input.Type = ATypes.AFloat;
                return(input);
            }
            else
            {
                return(AFloat.Create(input.asFloat));
            }
        }
Example #10
0
 public AType ExecutePrimitive(AInteger rightArgument, AFloat leftArgument)
 {
     return CalculateAnd(rightArgument, leftArgument);
 }
Example #11
0
 public override AType ExecutePrimitive(AFloat argument, Aplus environment = null)
 {
     return calculateReciprocal(argument.asFloat);
 }
Example #12
0
 public AType ExecutePrimitive(AFloat rightArgument, AInteger leftArgument)
 {
     return AFloat.Create(Math.Max(leftArgument.asFloat, rightArgument.asFloat));
 }
Example #13
0
 public AType ExecutePrimitive(AInteger rightArgument, AFloat leftArgument)
 {
     return FloatGT(rightArgument, leftArgument);
 }
Example #14
0
 public AType ExecutePrimitive(AFloat rightArgument, AInteger leftArgument)
 {
     CheckZeroPerZero(rightArgument, leftArgument);
     return AFloat.Create(leftArgument.asInteger / rightArgument.asFloat);
 }
Example #15
0
 public AType ExecutePrimitive(AFloat rightArgument, AInteger leftArgument)
 {
     return AFloat.Create(leftArgument.asInteger - rightArgument.asFloat);
 }
Example #16
0
 public override AType ExecutePrimitive(AFloat argument, Aplus environment = null)
 {
     return AFloat.Create(argument.asFloat);
 }
Example #17
0
 public AType ExecutePrimitive(AFloat rightArgument, AInteger leftArgument)
 {
     DomainCheck(leftArgument.asInteger);
     return Calculate(rightArgument.asFloat, leftArgument.asInteger);
 }
Example #18
0
 public virtual AType ExecutePrimitive(AFloat argument, Aplus environment = null)
 {
     throw new NotImplementedException("Invalid use-case");
 }
Example #19
0
 public AType ExecutePrimitive(AFloat rightArgument, AFloat leftArgument)
 {
     return AFloat.Create(rightArgument.asFloat + leftArgument.asFloat);
 }
Example #20
0
 public AType ExecutePrimitive(AFloat rightArgument, AFloat leftArgument)
 {
     return CalculatePower(rightArgument, leftArgument);
 }
Example #21
0
 public AType ExecutePrimitive(AInteger rightArgument, AFloat leftArgument)
 {
     return AFloat.Create(rightArgument.asInteger * leftArgument.asFloat);
 }
Example #22
0
 public AType ExecutePrimitive(AFloat rightArgument, AInteger leftArgument)
 {
     return CalculateOr(rightArgument, leftArgument);
 }
Example #23
0
 public AType ExecutePrimitive(AFloat rightArgument, ASymbol leftArgument)
 {
     int casenumber = ConvertSymbolName(leftArgument.asString);
     return Calculate(rightArgument.asFloat, casenumber);
 }
Example #24
0
 public AType ExecutePrimitive(AFloat rightArgument, AFloat leftArgument)
 {
     return FloatEqual(rightArgument, leftArgument);
 }
 public AType ExecutePrimitive(AFloat rightArgument, AInteger leftArgument)
 {
     return FloatLTE(rightArgument, leftArgument);
 }