Last active
January 4, 2024 03:48
-
-
Save Ludophonic/8642597 to your computer and use it in GitHub Desktop.
Visual studio type visualizer for half precision (16 bit) floating point values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
union FP16 | |
{ | |
uint16 u; | |
struct | |
{ | |
uint16 Mantissa : 10; | |
uint16 Exponent : 5; | |
uint16 Sign : 1; | |
}; | |
}; | |
struct half | |
{ | |
// Constructors, operators, etc... here | |
FP16 fp16; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010"> | |
<Type Name="half"> | |
<DisplayString Condition = "fp16.Exponent == 0">{(0.00006103515625f * fp16.Mantissa/1024.0f)}</DisplayString> | |
<DisplayString Condition = "fp16.Exponent == 31 && fp16.Mantissa == 0">{fp16.Sign*-2+1}.#INFINITY</DisplayString> | |
<DisplayString Condition = "fp16.Exponent == 31">#NaN</DisplayString> | |
<DisplayString Condition = "fp16.Exponent < 15">{1.0f / (1 << (15 - fp16.Exponent)) * (fp16.Sign*-2+1.0f) * (1.0f + fp16.Mantissa/1024.0f)}</DisplayString> | |
<DisplayString Condition = "fp16.Exponent > 15">{(1 << (fp16.Exponent-15)) * (fp16.Sign*-2+1.0f) * (1.0f + fp16.Mantissa/1024.0f)}</DisplayString> | |
<DisplayString>{(fp16.Sign*-2+1) * 1.0f + fp16.Mantissa/1024.0f}</DisplayString> | |
</Type> | |
</AutoVisualizer> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment