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)); }
/// <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)); }
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)); }
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)); }
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)); }
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)); }
public static Half Abs(Half half) { return(Half.ToHalf((ushort)(half.value & 0x7fff))); }
public static Half Negate(Half half) { return(Half.ToHalf((ushort)(half.value ^ 0x8000))); }
/// <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))); }
public static Half Abs(Half half) => Half.ToHalf((ushort)(half.value & 0x7fff));
public static Half Negate(Half half) => Half.ToHalf((ushort)(half.value ^ 0x8000));