Пример #1
0
        private void ValidateResult(Double[] firstOp, Double[] secondOp, Double[] thirdOp, Double[] result, [CallerMemberName] string method = "")
        {
            bool succeeded = true;

            if (((BitConverter.DoubleToInt64Bits(thirdOp[0]) >> 63) & 1) == 1 ? BitConverter.DoubleToInt64Bits(secondOp[0]) != BitConverter.DoubleToInt64Bits(result[0]) : BitConverter.DoubleToInt64Bits(firstOp[0]) != BitConverter.DoubleToInt64Bits(result[0]))
            {
                succeeded = false;
            }
            else
            {
                for (var i = 1; i < RetElementCount; i++)
                {
                    if (((BitConverter.DoubleToInt64Bits(thirdOp[i]) >> 63) & 1) == 1 ? BitConverter.DoubleToInt64Bits(secondOp[i]) != BitConverter.DoubleToInt64Bits(result[i]) : BitConverter.DoubleToInt64Bits(firstOp[i]) != BitConverter.DoubleToInt64Bits(result[i]))
                    {
                        succeeded = false;
                        break;
                    }
                }
            }

            if (!succeeded)
            {
                TestLibrary.TestFramework.LogInformation($"{nameof(Sse41)}.{nameof(Sse41.BlendVariable)}<Double>(Vector128<Double>, Vector128<Double>, Vector128<Double>): {method} failed:");
                TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
                TestLibrary.TestFramework.LogInformation($"secondOp: ({string.Join(", ", secondOp)})");
                TestLibrary.TestFramework.LogInformation($" thirdOp: ({string.Join(", ", thirdOp)})");
                TestLibrary.TestFramework.LogInformation($"  result: ({string.Join(", ", result)})");
                TestLibrary.TestFramework.LogInformation(string.Empty);

                Succeeded = false;
            }
        }
 public static string ConvertToBitStringBuiltIn(double value) => // при помощи конвентатора
 Convert.ToString(BitConverter.DoubleToInt64Bits(value), 2);
        private void ValidateResult(Double[] firstOp, Double[] result, [CallerMemberName] string method = "")
        {
            if (BitConverter.DoubleToInt64Bits(firstOp[0]) != BitConverter.DoubleToInt64Bits(result[0]))
            {
                Succeeded = false;
            }
            else
            {
                for (var i = 1; i < RetElementCount; i++)
                {
                    if (BitConverter.DoubleToInt64Bits(result[i]) != (i < 2 ? BitConverter.DoubleToInt64Bits(firstOp[i]) : BitConverter.DoubleToInt64Bits(firstOp[i - 2])))
                    {
                        Succeeded = false;
                        break;
                    }
                }
            }

            if (!Succeeded)
            {
                TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.BroadcastVector128ToVector256)}<Double>(Vector128<Double>): {method} failed:");
                TestLibrary.TestFramework.LogInformation($"  firstOp: ({string.Join(", ", firstOp)})");
                TestLibrary.TestFramework.LogInformation($"   result: ({string.Join(", ", result)})");
                TestLibrary.TestFramework.LogInformation(string.Empty);
            }
        }
Пример #4
0
        private void ValidateResult(Double[] firstOp, Double[] thirdOp, Double[] result, [CallerMemberName] string method = "")
        {
            bool succeeded = true;

            for (var i = 0; i < RetElementCount; i++)
            {
                if (BitConverter.DoubleToInt64Bits(Helpers.Insert(firstOp, ElementIndex, thirdOp[0], i)) != BitConverter.DoubleToInt64Bits(result[i]))
                {
                    succeeded = false;
                    break;
                }
            }

            if (!succeeded)
            {
                TestLibrary.TestFramework.LogInformation($"{nameof(AdvSimd)}.{nameof(AdvSimd.InsertScalar)}<Double>(Vector128<Double>, 1, Vector64<Double>): {method} failed:");
                TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
                TestLibrary.TestFramework.LogInformation($" thirdOp: ({string.Join(", ", thirdOp)})");
                TestLibrary.TestFramework.LogInformation($"  result: ({string.Join(", ", result)})");
                TestLibrary.TestFramework.LogInformation(string.Empty);

                Succeeded = false;
            }
        }
 public IByteBuffer SetDouble(int index, double value)
 {
     this.SetLong(index, BitConverter.DoubleToInt64Bits(value));
     return(this);
 }
Пример #6
0
        public override async Task WriteDoubleAsync(double d, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            await WriteI64Async(BitConverter.DoubleToInt64Bits(d), cancellationToken);
        }
Пример #7
0
        // NOTE: Consider duplicating any tests added here in SingleTests.cs

        private static ulong DoubleToUInt64Bits(double value)
        {
            return((ulong)(BitConverter.DoubleToInt64Bits(value)));
        }
Пример #8
0
        /// <summary>
        /// Fills the array with eight bytes of the specified double-precision floating point value beginning at <paramref name="startIndex"/>.
        /// </summary>
        /// <param name="value">The number to convert.</param>
        /// <param name="buffer">The array of bytes to store converted value at.</param>
        /// <param name="startIndex">The start index where converted value is to be stored at <paramref name="buffer"/>.</param>
        public static void FillBytes(double value, byte[] buffer, int startIndex)
        {
            BitConverterServices.ValidateFillArguments(buffer, startIndex, 8);

            FillBytes(BitConverter.DoubleToInt64Bits(value), buffer, startIndex);
        }
Пример #9
0
        /**
         * <summary>
         * Calculate Java hash code for the passed object.</summary>
         *
         * <param name="val">Object to calculate Java hash code for.</param>
         * <returns>Java hash code for passed object.</returns>
         */
        public static int GetJavaHashCode(Object val)
        {
            if (val == null)
            {
                return(0);
            }

            if (val is byte)
            {
                return((byte)val);
            }

            if (val is sbyte)
            {
                return((sbyte)val);
            }

            // Bytes order (from lowest to highest) is specific only for consistent hash.
            // So we use standart bit converter instead of GridClientUtils byte converters.

            if (val is char)
            {
                return((char)val);
            }

            if (val is short)
            {
                return((short)val);
            }

            if (val is ushort)
            {
                return((ushort)val);
            }

            if (val is int)
            {
                return((int)val);
            }

            if (val is uint)
            {
                return((int)(uint)val);
            }

            // Should be checked BEFORE double.
            if (val is float)
            {
                val = (double)val;
            }

            // Should be checked BEFORE long.
            if (val is double)
            {
                val = BitConverter.DoubleToInt64Bits((double)val);
            }

            if (val is long)
            {
                return((int)(((long)val) ^ (((long)val) >> 32)));
            }

            if (val is ulong)
            {
                return((int)(((ulong)val) ^ (((ulong)val) >> 32)));
            }

            if (val is Guid)
            {
                return(HashCodeForGuid((Guid)val));
            }

            String str = val as String;

            if (str != null)
            {
                return(HashCodeForString(str));
            }

            var hashObj = val as IGridClientConsistentHashObject;

            if (hashObj != null)
            {
                return(hashObj.GetHashCode());
            }

            throw new InvalidOperationException("Unsupported value (does object implement GridCLientConsistentHashObject?)" +
                                                " [obj=" + val + ", type=" + val.GetType() + "]");
        }
Пример #10
0
 public static bool Equals(double x, double y)
 {
     return(BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y));
 }
Пример #11
0
        private void ValidateResult(Double[] firstOp, Double[] secondOp, Double[] thirdOp, Double[] result, [CallerMemberName] string method = "")
        {
            bool succeeded = true;

            for (var i = 0; i < RetElementCount; i += 2)
            {
                if (BitConverter.DoubleToInt64Bits(Math.Round((firstOp[i] * secondOp[i]) - thirdOp[i], 9)) != BitConverter.DoubleToInt64Bits(Math.Round(result[i], 9)))
                {
                    succeeded = false;
                    break;
                }

                if (BitConverter.DoubleToInt64Bits(Math.Round((firstOp[i + 1] * secondOp[i + 1]) + thirdOp[i + 1], 9)) != BitConverter.DoubleToInt64Bits(Math.Round(result[i + 1], 9)))
                {
                    succeeded = false;
                    break;
                }
            }

            if (!succeeded)
            {
                TestLibrary.TestFramework.LogInformation($"{nameof(Fma)}.{nameof(Fma.MultiplyAddSubtract)}<Double>(Vector128<Double>, Vector128<Double>, Vector128<Double>): {method} failed:");
                TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
                TestLibrary.TestFramework.LogInformation($"secondOp: ({string.Join(", ", secondOp)})");
                TestLibrary.TestFramework.LogInformation($" thirdOp: ({string.Join(", ", thirdOp)})");
                TestLibrary.TestFramework.LogInformation($"  result: ({string.Join(", ", result)})");
                TestLibrary.TestFramework.LogInformation(string.Empty);

                Succeeded = false;
            }
        }
Пример #12
0
 /// <summary>
 /// Writes Int64 bits of given <see cref="Double"/> value in big-endian order to given array starting at specified offset.
 /// </summary>
 /// <param name="array">The byte array.</param>
 /// <param name="idx">The offset to start writing. Will be incremented by 8.</param>
 /// <param name="value">The <see cref="Double"/> value to write.</param>
 /// <returns>The <paramref name="array"/>.</returns>
 public static ResizableArray <Byte> WriteDoubleBEToBytes(this ResizableArray <Byte> array, ref Int32 idx, Double value)
 {
     return(array.WriteInt64BEToBytes(ref idx, BitConverter.DoubleToInt64Bits(value)));
 }
Пример #13
0
 /// <summary>
 /// Returns a hash code for this SiliconStudio.Core.Mathematics.AngleSingle instance.
 /// </summary>
 /// <returns>A 32-bit signed integer hash code.</returns>
 public override int GetHashCode()
 {
     return((int)(BitConverter.DoubleToInt64Bits(radians) % int.MaxValue));
 }
Пример #14
0
        static MappedWriter()
        {
            WriteMapper <bool> .WriteValue   = (w, v) => w.Write(v);
            WriteMapper <byte> .WriteValue   = (w, v) => w.Write(v);
            WriteMapper <sbyte> .WriteValue  = (w, v) => w.Write(v);
            WriteMapper <short> .WriteValue  = (w, v) => w.Write(BinaryPrimitives.ReverseEndianness(v));
            WriteMapper <ushort> .WriteValue = (w, v) => w.Write(BinaryPrimitives.ReverseEndianness(v));
            WriteMapper <int> .WriteValue    = (w, v) => w.Write(BinaryPrimitives.ReverseEndianness(v));
            WriteMapper <uint> .WriteValue   = (w, v) => w.Write(BinaryPrimitives.ReverseEndianness(v));
            WriteMapper <long> .WriteValue   = (w, v) => w.Write(BinaryPrimitives.ReverseEndianness(v));
            WriteMapper <ulong> .WriteValue  = (w, v) => w.Write(BinaryPrimitives.ReverseEndianness(v));

            WriteMapper <float> .WriteValue = (w, v) =>
                                              w.Write(BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(v)));

            WriteMapper <double> .WriteValue = (w, v)
                                               => w.Write(BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(v)));

            WriteMapper <byte> .WriteValues = (w, v) => w.Write(v);

            WriteMapper <sbyte> .WriteValues = (w, v) =>
            {
                for (var i = 0; i < v.Length; i++)
                {
                    w.Write(v[i]);
                }
            };

            WriteMapper <short> .WriteValues = (w, v) =>
            {
                for (var i = 0; i < v.Length; i++)
                {
                    w.Write(BinaryPrimitives.ReverseEndianness(v[i]));
                }
            };

            WriteMapper <ushort> .WriteValues = (w, v) =>
            {
                for (var i = 0; i < v.Length; i++)
                {
                    w.Write(BinaryPrimitives.ReverseEndianness(v[i]));
                }
            };

            WriteMapper <int> .WriteValues = (w, v) =>
            {
                for (var i = 0; i < v.Length; i++)
                {
                    w.Write(BinaryPrimitives.ReverseEndianness(v[i]));
                }
            };

            WriteMapper <uint> .WriteValues = (w, v) =>
            {
                for (var i = 0; i < v.Length; i++)
                {
                    w.Write(BinaryPrimitives.ReverseEndianness(v[i]));
                }
            };

            WriteMapper <long> .WriteValues = (w, v) =>
            {
                for (var i = 0; i < v.Length; i++)
                {
                    w.Write(BinaryPrimitives.ReverseEndianness(v[i]));
                }
            };

            WriteMapper <ulong> .WriteValues = (w, v) =>
            {
                for (var i = 0; i < v.Length; i++)
                {
                    w.Write(BinaryPrimitives.ReverseEndianness(v[i]));
                }
            };

            WriteMapper <float> .WriteValues = (w, v) =>
            {
                for (var i = 0; i < v.Length; i++)
                {
                    w.Write(BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(v[i])));
                }
            };

            WriteMapper <double> .WriteValues = (w, v) =>
            {
                for (var i = 0; i < v.Length; i++)
                {
                    w.Write(BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(v[i])));
                }
            };
        }
Пример #15
0
 public void writeRawDouble(double d)
 {
     writeRawInt64(BitConverter.DoubleToInt64Bits(d));
 }
Пример #16
0
 /// <summary>
 /// Writes the specified double-precision floating-point number, using the IEEE 754 big-endian format.
 /// </summary>
 public void WriteDouble(double value)
 {
     WriteInt64(BitConverter.DoubleToInt64Bits(value));
 }
Пример #17
0
		public static void Encode(IByteBuffer byteBuffer,  Object value)
		{
			var type = GetType(value); 
			byteBuffer.WriteByte((byte)type); 
			switch (type)
			{
				case AMF0_Type.NUMBER:
					{
						if (value is Double)
						{
							byteBuffer.WriteLong(BitConverter.DoubleToInt64Bits((Double)value));
						}
						else
						{ // this coverts int also
							byteBuffer.WriteLong(BitConverter.DoubleToInt64Bits(Double.Parse(value.ToString())));
						}
						return;
					}
				case AMF0_Type.BOOLEAN:
					{
						byteBuffer.WriteByte((Boolean)value ? BOOLEAN_TRUE : BOOLEAN_FALSE);
						return;
					}
				case AMF0_Type.STRING:
					EncodeString(byteBuffer, (String)value);
					return;
				case AMF0_Type.NULL:
					return;
				case AMF0_Type.Dic:
					byteBuffer.WriteInt(0);
					goto case AMF0_Type.OBJECT;
				// no break; remaining processing same as OBJECT
				case AMF0_Type.OBJECT:
					{
						var dic = (Dictionary<String, Object>)value;
						foreach (var entry in dic)
						{
							EncodeString(byteBuffer, entry.Key);
							Encode(byteBuffer, entry.Value);
						}
						byteBuffer.WriteBytes(OBJECT_END_MARKER);
						return;
					}
				case AMF0_Type.ARRAY:
					{
						var array = (Object[])value;
						byteBuffer.WriteInt(array.Length);
						foreach (Object o in array)
						{
							Encode(byteBuffer, o);
						}
						return;
					}
				case AMF0_Type.DATETIME:
					{
						long time = Utility.CurrentTimeMillis();
						byteBuffer.WriteLong(BitConverter.DoubleToInt64Bits(time));
						byteBuffer.WriteShort((short)0);
						return;
					}
				default:
					throw new ArgumentException("unexpected type: " + type);
			}
		}
Пример #18
0
 /// <summary>
 /// Writes a double field value, without a tag, to the stream.
 /// </summary>
 /// <param name="value">The value to write</param>
 public void WriteDouble(double value)
 {
     WriteRawLittleEndian64((ulong)BitConverter.DoubleToInt64Bits(value));
 }
Пример #19
0
        static unsafe int Main(string[] args)
        {
            int    testResult          = Pass;
            int    testsCount          = 21;
            string methodUnderTestName = nameof(Sse2.CompareEqual);

            if (Sse2.IsSupported)
            {
                using (var doubleTable = TestTableSse2 <double> .Create(testsCount))
                    using (var intTable = TestTableSse2 <int> .Create(testsCount))
                        using (var uintTable = TestTableSse2 <uint> .Create(testsCount))
                            using (var shortTable = TestTableSse2 <short> .Create(testsCount))
                                using (var ushortTable = TestTableSse2 <ushort> .Create(testsCount))
                                    using (var sbyteTable = TestTableSse2 <sbyte> .Create(testsCount))
                                        using (var byteTable = TestTableSse2 <byte> .Create(testsCount))
                                        {
                                            for (int i = 0; i < testsCount; i++)
                                            {
                                                (Vector128 <double>, Vector128 <double>, Vector128 <double>)value = doubleTable[i];
                                                var result = Sse2.CompareEqual(value.Item1, value.Item2);
                                                doubleTable.SetOutArray(result);
                                            }

                                            for (int i = 0; i < testsCount; i++)
                                            {
                                                (Vector128 <int>, Vector128 <int>, Vector128 <int>)value = intTable[i];
                                                var result = Sse2.CompareEqual(value.Item1, value.Item2);
                                                intTable.SetOutArray(result);
                                            }

                                            for (int i = 0; i < testsCount; i++)
                                            {
                                                (Vector128 <uint>, Vector128 <uint>, Vector128 <uint>)value = uintTable[i];
                                                var result = Sse2.CompareEqual(value.Item1, value.Item2);
                                                uintTable.SetOutArray(result);
                                            }

                                            for (int i = 0; i < testsCount; i++)
                                            {
                                                (Vector128 <short>, Vector128 <short>, Vector128 <short>)value = shortTable[i];
                                                var result = Sse2.CompareEqual(value.Item1, value.Item2);
                                                shortTable.SetOutArray(result);
                                            }

                                            for (int i = 0; i < testsCount; i++)
                                            {
                                                (Vector128 <ushort>, Vector128 <ushort>, Vector128 <ushort>)value = ushortTable[i];
                                                var result = Sse2.CompareEqual(value.Item1, value.Item2);
                                                ushortTable.SetOutArray(result);
                                            }

                                            for (int i = 0; i < testsCount; i++)
                                            {
                                                (Vector128 <sbyte>, Vector128 <sbyte>, Vector128 <sbyte>)value = sbyteTable[i];
                                                var result = Sse2.CompareEqual(value.Item1, value.Item2);
                                                sbyteTable.SetOutArray(result);
                                            }

                                            for (int i = 0; i < testsCount; i++)
                                            {
                                                (Vector128 <byte>, Vector128 <byte>, Vector128 <byte>)value = byteTable[i];
                                                var result = Sse2.CompareEqual(value.Item1, value.Item2);
                                                byteTable.SetOutArray(result);
                                            }

                                            CheckMethod <double> checkDouble = (double x, double y, double z, ref double a) =>
                                            {
                                                a = x == y?BitConverter.Int64BitsToDouble(-1) : 0;

                                                return(BitConverter.DoubleToInt64Bits(a) == BitConverter.DoubleToInt64Bits(z));
                                            };

                                            if (!doubleTable.CheckResult(checkDouble))
                                            {
                                                PrintError(doubleTable, methodUnderTestName, "(double x, double y, double z, ref double a) => (a = x == y ? -1l : 0) == z", checkDouble);
                                                testResult = Fail;
                                            }

                                            CheckMethod <int> checkInt32 = (int x, int y, int z, ref int a) => (a = x == y ? -1 : 0) == z;

                                            if (!intTable.CheckResult(checkInt32))
                                            {
                                                PrintError(intTable, methodUnderTestName, "(int x, int y, int z, ref int a) =>  (a = x == y ? -1 : 0) == z);", checkInt32);
                                                testResult = Fail;
                                            }

                                            CheckMethod <uint> checkUInt32 = (uint x, uint y, uint z, ref uint a) => (a = x == y ? 0xffffffff : 0) == z;

                                            if (!uintTable.CheckResult(checkUInt32))
                                            {
                                                PrintError(uintTable, methodUnderTestName, "(uint x, uint y, uint z, ref uint a) => (a = x == y ? 0xffffffff : 0) == z", checkUInt32);
                                                testResult = Fail;
                                            }

                                            CheckMethod <short> checkInt16 = (short x, short y, short z, ref short a) => (a = (short)(x == y ? -1 : 0)) == z;

                                            if (!shortTable.CheckResult(checkInt16))
                                            {
                                                PrintError(shortTable, methodUnderTestName, "(short x, short y, short z, ref short a) => (a = (short)(x == y ? -1 : 0)) == z", checkInt16);
                                                testResult = Fail;
                                            }

                                            CheckMethod <ushort> checkUInt16 = (ushort x, ushort y, ushort z, ref ushort a) => (a = (ushort)(x == y ? 0xffff : 0)) == z;

                                            if (!ushortTable.CheckResult(checkUInt16))
                                            {
                                                PrintError(ushortTable, methodUnderTestName, "(ushort x, ushort y, ushort z, ref ushort a) => (a = (ushort)(x == y ? 0xffff : 0)) == z", checkUInt16);
                                                testResult = Fail;
                                            }

                                            CheckMethod <sbyte> checkSByte = (sbyte x, sbyte y, sbyte z, ref sbyte a) => (a = (sbyte)(x == y ? -1 : 0)) == z;

                                            if (!sbyteTable.CheckResult(checkSByte))
                                            {
                                                PrintError(sbyteTable, methodUnderTestName, "(sbyte x, sbyte y, sbyte z, ref sbyte a) => (a = (sbyte) (x == y ? -1 : 0) == z", checkSByte);
                                                testResult = Fail;
                                            }

                                            CheckMethod <byte> checkByte = (byte x, byte y, byte z, ref byte a) => (a = (byte)(x == y ? 0xff : 0)) == z;

                                            if (!byteTable.CheckResult(checkByte))
                                            {
                                                PrintError(byteTable, methodUnderTestName, "(byte x, byte y, byte z, ref byte a) => (a = (byte)(x == y ? 0xff : 0)) == z", checkByte);
                                                testResult = Fail;
                                            }
                                        }
            }
            else
            {
                Console.WriteLine($"Sse2.IsSupported: {Sse2.IsSupported}, skipped tests of {typeof(Sse2)}.{methodUnderTestName}");
            }
            return(testResult);
        }
Пример #20
0
 public static Vector128 <float> VectorInsertDouble(double value, Vector128 <float> vector, byte index)
 {
     return(VectorInsertInt((ulong)BitConverter.DoubleToInt64Bits(value), vector, index, 3));
 }
Пример #21
0
        private void ValidateResult(Double[] left, Double[] right, Double[] result, [CallerMemberName] string method = "")
        {
            bool succeeded = true;

            for (var i = 0; i < RetElementCount; i++)
            {
                if (BitConverter.DoubleToInt64Bits(Helpers.OrNot(left[i], right[i])) != BitConverter.DoubleToInt64Bits(result[i]))
                {
                    succeeded = false;
                    break;
                }
            }

            if (!succeeded)
            {
                TestLibrary.TestFramework.LogInformation($"{nameof(AdvSimd)}.{nameof(AdvSimd.OrNot)}<Double>(Vector128<Double>, Vector128<Double>): {method} failed:");
                TestLibrary.TestFramework.LogInformation($"    left: ({string.Join(", ", left)})");
                TestLibrary.TestFramework.LogInformation($"   right: ({string.Join(", ", right)})");
                TestLibrary.TestFramework.LogInformation($"  result: ({string.Join(", ", result)})");
                TestLibrary.TestFramework.LogInformation(string.Empty);

                Succeeded = false;
            }
        }
Пример #22
0
        private void ValidateResult(Double[] left, Double[] right, Double[] result, [CallerMemberName] string method = "")
        {
            if (BitConverter.DoubleToInt64Bits(Math.Max(left[0], right[0])) != BitConverter.DoubleToInt64Bits(result[0]))
            {
                Succeeded = false;
            }
            else
            {
                for (var i = 1; i < RetElementCount; i++)
                {
                    if (BitConverter.DoubleToInt64Bits(Math.Max(left[i], right[i])) != BitConverter.DoubleToInt64Bits(result[i]))
                    {
                        Succeeded = false;
                        break;
                    }
                }
            }

            if (!Succeeded)
            {
                TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.Max)}<Double>(Vector256<Double>, Vector256<Double>): {method} failed:");
                TestLibrary.TestFramework.LogInformation($"    left: ({string.Join(", ", left)})");
                TestLibrary.TestFramework.LogInformation($"   right: ({string.Join(", ", right)})");
                TestLibrary.TestFramework.LogInformation($"  result: ({string.Join(", ", result)})");
                TestLibrary.TestFramework.LogInformation(string.Empty);
            }
        }
Пример #23
0
        private MetricsGossipEnvelope MetricsGossipEnvelopeToProto(MetricsGossipEnvelope envelope)
        {
            var allNodeMetrics = envelope.Gossip.Nodes;
            var allAddresses   = allNodeMetrics.Select(m => m.Address).ToImmutableArray();
            var addressMapping = allAddresses.Select((a, i) => (Index: i, Value: a)).ToImmutableDictionary(p => p.Value, p => p.Index);
            var allMetricNames = allNodeMetrics.Aggregate(
                ImmutableHashSet <string> .Empty,
                (set, metrics) => set.Union(metrics.Metrics.Select(m => m.Name))).ToImmutableArray();
            var metricNamesMapping = allMetricNames.Select((a, i) => (Index: i, Value: a)).ToImmutableDictionary(p => p.Value, p => p.Index);

            int MapAddress(Actor.Address address) => MapWithErrorMessage(addressMapping, address, "address");
            int MapName(string name) => MapWithErrorMessage(metricNamesMapping, name, "metric name");

            Option <NodeMetrics.Types.EWMA> EwmaToProto(Option <NodeMetrics.Types.EWMA> ewma)
            => ewma.Select(e => new NodeMetrics.Types.EWMA(e.Value, e.Alpha));

            NodeMetrics.Types.Number NumberToProto(AnyNumber number)
            {
                var proto = new NodeMetrics.Types.Number();

                switch (number.Type)
                {
                case AnyNumber.NumberType.Int:
                    proto.Type    = NodeMetrics.Types.NumberType.Integer;
                    proto.Value32 = Convert.ToUInt32(number.LongValue);
                    break;

                case AnyNumber.NumberType.Long:
                    proto.Type    = NodeMetrics.Types.NumberType.Long;
                    proto.Value64 = Convert.ToUInt64(number.LongValue);
                    break;

                case AnyNumber.NumberType.Float:
                    proto.Type    = NodeMetrics.Types.NumberType.Float;
                    proto.Value32 = (uint)BitConverter.ToInt32(BitConverter.GetBytes((float)number.DoubleValue), 0);
                    break;

                case AnyNumber.NumberType.Double:
                    proto.Type    = NodeMetrics.Types.NumberType.Double;
                    proto.Value64 = (ulong)BitConverter.DoubleToInt64Bits(number.DoubleValue);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                return(proto);
            }

            NodeMetrics.Types.Metric MetricToProto(NodeMetrics.Types.Metric m)
            {
                var metric = new NodeMetrics.Types.Metric()
                {
                    NameIndex = MapName(m.Name),
                    Number    = NumberToProto(m.Value),
                };

                var ewma = EwmaToProto(m.Average);

                if (ewma.HasValue)
                {
                    metric.Ewma = ewma.Value;
                }

                return(metric);
            }

            NodeMetrics NodeMetricsToProto(NodeMetrics nodeMetrics)
            {
                return(new NodeMetrics()
                {
                    AddressIndex = MapAddress(nodeMetrics.Address),
                    Timestamp = nodeMetrics.Timestamp,
                    Metrics = { nodeMetrics.Metrics.Select(MetricToProto) }
                });
            }

            var nodeMetricsProto = allNodeMetrics.Select(NodeMetricsToProto);

            return(new MetricsGossipEnvelope()
            {
                From = AddressToProto(envelope.FromAddress),
                Reply = envelope.Reply,
                Gossip = new MetricsGossip()
                {
                    AllAddresses = { allAddresses.Select(AddressToProto) },
                    AllMetricNames = { allMetricNames },
                    NodeMetrics = { nodeMetricsProto }
                }
            });
        }
Пример #24
0
 /// <summary>
 /// Converts the specified double-precision floating point number to a
 /// 64-bit signed integer. Note: the endianness of this converter does not
 /// affect the returned value.
 /// </summary>
 /// <param name="value">The number to convert. </param>
 /// <returns>A 64-bit signed integer whose value is equivalent to value.</returns>
 public long DoubleToInt64Bits(double value)
 {
     return(BitConverter.DoubleToInt64Bits(value));
 }
 public IByteBuffer WriteDouble(double value)
 {
     this.WriteLong(BitConverter.DoubleToInt64Bits(value));
     return(this);
 }
Пример #26
0
        private void ValidateResult(Double[] left, Double[] right, Double[] result, [CallerMemberName] string method = "")
        {
            bool succeeded = true;

            if (BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits((BitConverter.DoubleToInt64Bits(right[0]) < 0) ? left[0] : 0))
            {
                succeeded = false;
            }
            else
            {
                for (var i = 1; i < RetElementCount; i++)
                {
                    if (BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits((BitConverter.DoubleToInt64Bits(right[i]) < 0) ? left[i] : 0))
                    {
                        succeeded = false;
                        break;
                    }
                }
            }

            if (!succeeded)
            {
                TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.MaskLoad)}<Double>(Double*, Vector128<Double>): {method} failed:");
                TestLibrary.TestFramework.LogInformation($"    left: ({string.Join(", ", left)})");
                TestLibrary.TestFramework.LogInformation($"   right: ({string.Join(", ", right)})");
                TestLibrary.TestFramework.LogInformation($"  result: ({string.Join(", ", result)})");
                TestLibrary.TestFramework.LogInformation(string.Empty);

                Succeeded = false;
            }
        }
Пример #27
0
        /**
         * Converts the supplied <c>value</c> to the text representation that Excel would give if
         * the value were to appear in an unformatted cell, or as a literal number in a formula.<br/>
         * Note - the results from this method differ slightly from those of <c>Double.ToString()</c>
         * In some special cases Excel behaves quite differently.  This function attempts to reproduce
         * those results.
         */

        public static string ToText(double value)
        {
            return(RawDoubleBitsToText(BitConverter.DoubleToInt64Bits(value)));
        }
Пример #28
0
        private static int HashCode(double x)
        {
            long f = BitConverter.DoubleToInt64Bits(x);

            return((int)(f ^ ((long)((ulong)f >> 32))));
        }
Пример #29
0
 public override void WriteDouble(double d)
 {
     WriteI64(BitConverter.DoubleToInt64Bits(d));
 }
Пример #30
0
 public void WriteDouble(double v)
 {
     WriteLong(BitConverter.DoubleToInt64Bits(v));
 }