25 using System.ComponentModel;
26 using System.Globalization;
27 using System.Runtime.InteropServices;
28 using SiliconStudio.Core.Serialization;
30 namespace SiliconStudio.Core.Mathematics
36 [StructLayout(LayoutKind.Sequential, Pack = 2)]
44 public const int PrecisionDigits = 3;
49 public const int MantissaBits = 11;
54 public const int MaximumDecimalExponent = 4;
59 public const int MaximumBinaryExponent = 15;
64 public const int MinimumDecimalExponent = -4;
69 public const int MinimumBinaryExponent = -14;
74 public const int ExponentRadix = 2;
79 public const int AdditionRounding = 1;
112 this.value = HalfUtils.Pack(value);
118 public ushort RawValue
120 get {
return value; }
121 set { this.value = value; }
131 float[] results =
new float[values.Length];
132 for(
int i = 0; i < results.Length; i++)
133 results[i] = HalfUtils.Unpack(values[i].
RawValue);
144 Half[] results =
new Half[values.Length];
145 for(
int i = 0; i < results.Length; i++)
146 results[i] =
new Half(values[i]);
155 public static explicit operator Half(
float value)
157 return new Half(value);
165 public static implicit
operator float(
Half value)
167 return HalfUtils.Unpack(value.value);
177 public static bool operator ==(
Half left,
Half right)
179 return left.value == right.value;
189 public static bool operator !=(
Half left,
Half right)
191 return left.value != right.value;
201 return num.ToString(CultureInfo.CurrentCulture);
211 return (((num*3)/2) ^ num);
224 return value1.value == value2.value;
235 return other.value == value;
250 if (obj.GetType() != base.GetType())
255 return half.value == value;
260 Epsilon = 0.0004887581f;
262 MinValue = 6.103516E-05f;
static float[] ConvertToFloat(Half[] values)
Converts an array of half precision values into full precision values.
override int GetHashCode()
Returns the hash code for this instance.
bool Equals(Half other)
Returns a value that indicates whether the current instance is equal to the specified object...
static bool Equals(ref Half value1, ref Half value2)
Determines whether the specified object instances are considered equal.
ushort RawValue
Gets or sets the raw 16 bit value used to back this half-float.
static Half[] ConvertToHalf(float[] values)
Converts an array of full precision values into half precision values.
A half precision (16 bit) floating point value.
static readonly Half Zero
A Half whose value is 0.0f.
SiliconStudio.Paradox.Games.Mathematics.Half Half
override string ToString()
Converts the value of the object to its equivalent string representation.
static readonly float Epsilon
Smallest such that 1.0 + epsilon != 1.0
static readonly Half One
A Half whose value is 1.0f.
static readonly float MaxValue
Maximum value of the number.
override bool Equals(object obj)
Returns a value that indicates whether the current instance is equal to a specified object...
Half(float value)
Initializes a new instance of the T:SiliconStudio.Core.Mathematics.Half structure.
static readonly float MinValue
Minimum value of the number.