Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0190f96
Optimized conversions between `Half` and `Single`.
MineCake147E Feb 4, 2023
f36ab2b
Updated `explicit operator Half(float value)`.
MineCake147E Feb 5, 2023
b3b8eee
Removed `[MethodImpl(MethodImplOptions.AggressiveInlining)]` from `ex…
MineCake147E Feb 6, 2023
d26f6d9
Coding convention compliance
MineCake147E Mar 31, 2023
90abc81
Revert "Coding convention compliance"
MineCake147E Mar 31, 2023
a99b0a9
Coding convention compliance #1 redo
MineCake147E Mar 31, 2023
5535e6f
Merge branch 'main' of https://github.com/dotnet/runtime into improve…
MineCake147E Mar 31, 2023
c01f2f7
Merge branch 'main' of https://github.com/dotnet/runtime into improve…
MineCake147E May 16, 2023
a5142f3
Merge branch 'main' of https://github.com/dotnet/runtime into improve…
MineCake147E May 16, 2023
210815f
* Names of variables and constants got slightly more descriptive
MineCake147E May 16, 2023
394f434
Hopefully fixed bugs
MineCake147E May 16, 2023
ddd6880
Added explanation of `explicit operator float`
MineCake147E May 19, 2023
dc30370
Removed error causing whitespaces at the end of lines
MineCake147E May 20, 2023
d874357
+ Added explanation of `explicit operator Half(float value)`
MineCake147E May 24, 2023
7e2fa18
Merge branch 'main' of https://github.com/dotnet/runtime into improve…
MineCake147E May 24, 2023
05f7100
Fixed misinformation in comments
MineCake147E May 26, 2023
858499c
Optimized `Single`->`Half` conversion with subnormal result
MineCake147E May 26, 2023
5dd0fec
Merge branch 'main' of https://github.com/dotnet/runtime into improve…
MineCake147E May 27, 2023
3e5be81
Update src/libraries/System.Private.CoreLib/src/System/Half.cs
MineCake147E Jul 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed error causing whitespaces at the end of lines
  • Loading branch information
MineCake147E committed May 20, 2023
commit dc30370ea06ac25cab75c3601d4c9823ec5c78ec
14 changes: 7 additions & 7 deletions src/libraries/System.Private.CoreLib/src/System/Half.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ public static explicit operator Half(float value)
#region Explanation of this algorithm
// This algorithm converts a single-precision floating-point number to a half-precision floating-point number by multiplying it as a floating-point number and rearranging the bit sequence.
// However, it introduces some tricks to implement rounding correctly, to avoid multiplying denormalized numbers and to deal with exceptions such as infinity and NaN without using branch instructions.
//
//
// The bit sequence of a half-precision floating-point number is as follows
// seee_eeff_ffff_ffff
// The bit sequence of a single-precision floating-point number is as follows
Expand Down Expand Up @@ -934,7 +934,7 @@ public static explicit operator float(Half value)
#region Explanation of this algorithm
// This algorithm converts a half-precision floating-point number to a single-precision floating-point number by rearranging the bit sequence and multiplying it as a floating-point number.
// However, it introduces some tricks to avoid multiplying denormalized numbers and to deal with exceptions such as infinity and NaN without using branch instructions.
//
//
// The bit sequence of a half-precision floating-point number is as follows
// seee_eeff_ffff_ffff
// The bit sequence of a single-precision floating-point number is as follows
Expand All @@ -943,19 +943,19 @@ public static explicit operator float(Half value)
// In half-precision, the exponent part is 5 bits and the mantissa part is 10 bits. In single precision, the exponent is 8 bits and the mantissa is 23 bits.
// Both formats use an offset binary representation for the exponent part: the exponent part for 1.0 is half of the maximum value for either precision, i.e., 127 for single-precision and 15 for half-precision.
// The mantissa part is normalized when the exponent part is nonzero, since in binary numbers, 1 appears as the most significant digit for any nonzero number.
//
//
// This conversion algorithm takes advantage of the similarity between the two formats.
// By isolating the sign part from the half-precision bitstring and shifting it 13 bits to the left, the boundary between the exponent and mantissa parts matches with that of single-precision.
// In other words,
// 0eeeeeffffffffff is rearranged to
// In other words,
// 0eeeeeffffffffff is rearranged to
// 0000eeeeeffffffffff0000000000000
// which matches the boundary between the exponent and mantissa parts of single-precision floating-point number:
// seeeeeeeefffffffffffffffffffffff
//
//
// After rearrangement, this bit sequence is multiplied by the constant 5.192297E+33f in the floating-point number multiplication unit.
// However, most hardware cannot efficiently handle the multiplication of denormalized numbers.
// Denormalized numbers are more common in half-precision than in single-precision, so they cannot be ignored.
//
//
// First, if the value is a denormalized number, the constant 0x3880_0000u is added beforehand in the integer addition unit to make it behave as a normalized number.
// For Infinity or NaN, the constant 0x7000_0000u is added beforehand in the integer adder.
// These numbers are then converted to single-precision floating-point numbers as per the IEEE754 specification by the following operations.
Expand Down