Example #1
0
        public static unsafe Half SingleToHalf(float single)
        {
            uint   value  = *((uint *)&single);
            ushort result = (ushort)(baseTable[(value >> 23) & 0x1ff] + ((value & 0x007fffff) >> shiftTable[value >> 23]));

            return(Half.ToHalf(result));
        }
Example #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="reader"></param>
 /// <returns></returns>
 public static Half ReadHalf(this BinaryReader reader)
 {
     if (reader is null)
     {
         throw new ArgumentNullException(nameof(reader));
     }
     return(Half.ToHalf(reader.ReadBytes(2), 0));
 }
Example #3
0
        public static Half SingleToHalf(float single)
        {
            uint value = BitConverter.ToUInt32(BitConverter.GetBytes(single), 0);

            ushort result = (ushort)(baseTable[(value >> 23) & 0x1ff] + ((value & 0x007fffff) >> shiftTable[value >> 23]));

            return(Half.ToHalf(result));
        }
Example #4
0
        public static unsafe Half SingleToHalf(float single)
        {
            var value = *(uint *)&single;

            var result = (ushort)(BaseTable[(value >> 23) & 0x1ff] + ((value & 0x007fffff) >> ShiftTable[value >> 23]));

            return(Half.ToHalf(result));
        }
Example #5
0
        public static Half SingleToHalf(float single)
        {
            uint value = new FloatConverter()
            {
                Float = single
            }.Integer;

            ushort result = (ushort)(baseTable[(value >> 23) & 0x1ff] + ((value & 0x007fffff) >> shiftTable[value >> 23]));

            return(Half.ToHalf(result));
        }
Example #6
0
        public static /* unsafe */ Half SingleToHalf(float single)
        {
            /* uint value = *((uint*)&single);
             *
             * ushort result = (ushort)(baseTable[(value >> 23) & 0x1ff] + ((value & 0x007fffff) >> shiftTable[value >> 23]));
             * return Half.ToHalf(result); */

            uint value = System.BitConverter.ToUInt32(System.BitConverter.GetBytes(single), 0);

            ushort result = (ushort)(baseTable[(value >> 23) & 0x1ff] + ((value & 0x007fffff) >> shiftTable[value >> 23]));

            return(Half.ToHalf(result));
        }
Example #7
0
 public static Half Abs(Half half)
 {
     return(Half.ToHalf((ushort)(half.value & 0x7fff)));
 }
Example #8
0
 public static Half Negate(Half half)
 {
     return(Half.ToHalf((ushort)(half.value ^ 0x8000)));
 }
Example #9
0
 /// <summary>
 /// Returns the absolute value of a half-precision floating-point number.
 /// </summary>
 /// <param name="value">A number in the range System.Half.MinValue ≤ value ≤ System.Half.MaxValue.</param>
 /// <returns>A half-precision floating-point number, x, such that 0 ≤ x ≤System.Half.MaxValue.</returns>
 public static Half Abs(Half value)
 {
     return(Half.ToHalf((ushort)(value.value & 0x7fff)));
 }
Example #10
0
 public static Half Abs(Half half) => Half.ToHalf((ushort)(half.value & 0x7fff));
Example #11
0
 public static Half Negate(Half half) => Half.ToHalf((ushort)(half.value ^ 0x8000));