2 * Copyright (c) 2007-2010 SlimDX Group
\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
5 * of this software and associated documentation files (the "Software"), to deal
\r
6 * in the Software without restriction, including without limitation the rights
\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
8 * copies of the Software, and to permit persons to whom the Software is
\r
9 * furnished to do so, subject to the following conditions:
\r
11 * The above copyright notice and this permission notice shall be included in
\r
12 * all copies or substantial portions of the Software.
\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
24 #include "../design/HalfConverter.h"
\r
29 /// A half precision (16 bit) floating point value.
\r
31 /// <unmanaged>D3DXFLOAT16</unmanaged>
\r
32 [System::Serializable]
\r
33 [System::Runtime::InteropServices::StructLayout(System::Runtime::InteropServices::LayoutKind::Sequential)]
\r
34 [System::ComponentModel::TypeConverter( SlimDX::Design::HalfConverter::typeid )]
\r
35 public value class Half
\r
38 System::UInt16 m_Value;
\r
42 Half::Epsilon = D3DX_16F_EPSILON;
\r
43 Half::MaxValue = D3DX_16F_MAX;
\r
44 Half::MinValue = D3DX_16F_MIN;
\r
49 /// Number of decimal digits of precision.
\r
51 literal int PrecisionDigits = D3DX_16F_DIG;
\r
54 /// Number of bits in the mantissa.
\r
56 literal int MantissaBits = D3DX_16F_MANT_DIG;
\r
59 /// Maximum decimal exponent.
\r
61 literal int MaximumDecimalExponent = D3DX_16F_MAX_10_EXP;
\r
64 /// Maximum binary exponent.
\r
66 literal int MaximumBinaryExponent = D3DX_16F_MAX_EXP;
\r
69 /// Minimum decimal exponent.
\r
71 literal int MinimumDecimalExponent = D3DX_16F_MIN_10_EXP;
\r
74 /// Minimum binary exponent.
\r
76 literal int MinimumBinaryExponent = D3DX_16F_MIN_EXP;
\r
81 literal int ExponentRadix = D3DX_16F_RADIX;
\r
84 /// Additional rounding.
\r
86 literal int AdditionRounding = D3DX_16F_ROUNDS;
\r
89 /// Smallest such that 1.0 + epsilon != 1.0
\r
91 static initonly float Epsilon;
\r
94 /// Maximum value of the number.
\r
96 static initonly float MaxValue;
\r
99 /// Minimum value of the number.
\r
101 static initonly float MinValue;
\r
104 /// Initializes a new instance of the <see cref="Half"/> structure.
\r
106 /// <param name="value">The floating point value that should be stored in 16 bit format.</param>
\r
107 Half( float value );
\r
110 /// Gets or sets the raw 16 bit value used to back this half-float.
\r
112 property System::UInt16 RawValue
\r
114 System::UInt16 get();
\r
115 void set( System::UInt16 value );
\r
119 /// Converts an array of half precision values into full precision values.
\r
121 /// <param name="values">The values to be converted.</param>
\r
122 /// <returns>An array of converted values.</returns>
\r
123 static array<float>^ ConvertToFloat( array<Half>^ values );
\r
126 /// Converts an array of full precision values into half precision values.
\r
128 /// <param name="values">The values to be converted.</param>
\r
129 /// <returns>An array of converted values.</returns>
\r
130 static array<Half>^ ConvertToHalf( array<float>^ values );
\r
133 /// Performs an explicit conversion from <see cref="System::Single"/> to <see cref="Half"/>.
\r
135 /// <param name="value">The value to be converted.</param>
\r
136 /// <returns>The converted value.</returns>
\r
137 static explicit operator Half( float value );
\r
140 /// Performs an implicit conversion from <see cref="Half"/> to <see cref="System::Single"/>.
\r
142 /// <param name="value">The value to be converted.</param>
\r
143 /// <returns>The converted value.</returns>
\r
144 static operator float( Half value );
\r
147 /// Tests for equality between two objects.
\r
149 /// <param name="left">The first value to compare.</param>
\r
150 /// <param name="right">The second value to compare.</param>
\r
151 /// <returns><c>true</c> if <paramref name="left"/> has the same value as <paramref name="right"/>; otherwise, <c>false</c>.</returns>
\r
152 static bool operator == ( Half left, Half right );
\r
155 /// Tests for inequality between two objects.
\r
157 /// <param name="left">The first value to compare.</param>
\r
158 /// <param name="right">The second value to compare.</param>
\r
159 /// <returns><c>true</c> if <paramref name="left"/> has a different value than <paramref name="right"/>; otherwise, <c>false</c>.</returns>
\r
160 static bool operator != ( Half left, Half right );
\r
163 /// Converts the value of the object to its equivalent string representation.
\r
165 /// <returns>The string representation of the value of this instance.</returns>
\r
166 virtual System::String^ ToString() override;
\r
169 /// Returns the hash code for this instance.
\r
171 /// <returns>A 32-bit signed integer hash code.</returns>
\r
172 virtual int GetHashCode() override;
\r
175 /// Returns a value that indicates whether the current instance is equal to a specified object.
\r
177 /// <param name="obj">Object to make the comparison with.</param>
\r
178 /// <returns><c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns>
\r
179 virtual bool Equals( System::Object^ obj ) override;
\r
182 /// Returns a value that indicates whether the current instance is equal to the specified object.
\r
184 /// <param name="other">Object to make the comparison with.</param>
\r
185 /// <returns><c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns>
\r
186 virtual bool Equals( Half other );
\r
189 /// Determines whether the specified object instances are considered equal.
\r
191 /// <param name="value1"></param>
\r
192 /// <param name="value2"></param>
\r
193 /// <returns><c>true</c> if <paramref name="value1"/> is the same instance as <paramref name="value2"/> or
\r
194 /// if both are <c>null</c> references or if <c>value1.Equals(value2)</c> returns <c>true</c>; otherwise, <c>false</c>.</returns>
\r
195 static bool Equals( Half% value1, Half% value2 );
\r