User Tools

Site Tools


using_2016-bit_20floating_20point_20values

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

using_2016-bit_20floating_20point_20values [2018/03/31 13:19]
127.0.0.1 external edit
using_2016-bit_20floating_20point_20values [2018/04/17 19:23] (current)
tbest3112 Added syntax highlighting
Line 7: Line 7:
   * **FN_ConvertFromHalf** converts a number from a half-precision floating point value   * **FN_ConvertFromHalf** converts a number from a half-precision floating point value
 \\  The difference between **FN_ConvertToHalf** and **FN_ConvertToHalfRounded** is that the former truncates towards zero, but is slightly faster, whereas the latter generates the half-precision number which is nearest to the supplied value, but is slightly slower. Use **FN_ConvertToHalf** if you know that the value can be converted exactly into half precision (for example it was returned from **FN_ConvertFromHalf**) or if you are not too concerned about accuracy. Use **FN_ConvertToHalfRounded** otherwise.\\ \\  \\  The difference between **FN_ConvertToHalf** and **FN_ConvertToHalfRounded** is that the former truncates towards zero, but is slightly faster, whereas the latter generates the half-precision number which is nearest to the supplied value, but is slightly slower. Use **FN_ConvertToHalf** if you know that the value can be converted exactly into half precision (for example it was returned from **FN_ConvertFromHalf**) or if you are not too concerned about accuracy. Use **FN_ConvertToHalfRounded** otherwise.\\ \\ 
 +<code bb4w>
         DEF FN_ConvertFromHalf(A%)         DEF FN_ConvertFromHalf(A%)
         LOCAL A#         LOCAL A#
Line 24: Line 25:
         A# /= 65536.0# : A% = !(^A#+4)         A# /= 65536.0# : A% = !(^A#+4)
         = ((A% >> 16) AND &8000) + ((A% >> 10) AND &7FFF) + ((A% >> 9) AND 1)         = ((A% >> 16) AND &8000) + ((A% >> 10) AND &7FFF) + ((A% >> 9) AND 1)
 +</​code>​
 Note that **FN_ConvertToHalf** and **FN_ConvertToHalfRounded** perform //no range checking// to ensure that the value you pass can be represented as a valid half-precision number. If this is important you can add a check as follows:\\ \\  Note that **FN_ConvertToHalf** and **FN_ConvertToHalfRounded** perform //no range checking// to ensure that the value you pass can be represented as a valid half-precision number. If this is important you can add a check as follows:\\ \\ 
 +<code bb4w>
         DEF FN_ConvertToHalf(A#​)         DEF FN_ConvertToHalf(A#​)
         LOCAL A%         LOCAL A%
Line 38: Line 41:
         A# /= 65536.0# : A% = !(^A#+4)         A# /= 65536.0# : A% = !(^A#+4)
         = ((A% >> 16) AND &8000) + ((A% >> 10) AND &7FFF) + ((A% >> 9) AND 1)         = ((A% >> 16) AND &8000) + ((A% >> 10) AND &7FFF) + ((A% >> 9) AND 1)
 +</​code>​
 In all cases the 16-bit half-precision value is passed in the least-significant 16-bits of a 32-bit integer. In all cases the 16-bit half-precision value is passed in the least-significant 16-bits of a 32-bit integer.
using_2016-bit_20floating_20point_20values.txt ยท Last modified: 2018/04/17 19:23 by tbest3112