Example #1
0
        /// <summary>
        /// First param is compared all others. If *any* are equal, the function returns true.
        /// </summary>
        private bool ListEquals(double[] list)
        {
            var type = NanTags.TypeOf(list[0]);

            switch (type)
            {
            // Non-comparable types
            case DataType.Invalid:
            case DataType.NoValue:
            case DataType.Opcode:
                return(false);

            // Numeric types
            case DataType.Number:
            case DataType.ValInt32:
            case DataType.ValUInt32:
            {
                var target = _memory.CastDouble(list[0]);
                for (int i = 1; i < list.Length; i++)
                {
                    if (Math.Abs(target - _memory.CastDouble(list[i])) <= ComparisonPrecision)
                    {
                        return(true);
                    }
                }
                return(false);
            }

            // String types
            case DataType.ValSmallString:
            case DataType.PtrStaticString:
            case DataType.PtrString:
            {
                var target = _memory.CastString(list[0]);
                for (int i = 1; i < list.Length; i++)
                {
                    if (target == _memory.CastString(list[i]))
                    {
                        return(true);
                    }
                }
                return(false);
            }

            // Pointer equality
            case DataType.VariableRef:
            case DataType.PtrHashtable:
            case DataType.PtrGrid:
            case DataType.PtrSet:
            case DataType.PtrVector:
            {
                var target = NanTags.DecodeRaw(list[0]);
                for (int i = 1; i < list.Length; i++)
                {
                    if (target == NanTags.DecodeRaw(list[i]))
                    {
                        return(true);
                    }
                }
                return(false);
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }