Jump to content

Converting between 2 byte short and half precision float


Recommended Posts

Place your input in a conveniently declared structure using DllStructCreate, then read it into variable(s) and place that in another struct with the needed output format.

BTW what do you mean with "half precision float"?

I know float and double but that?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

I wanted to respond to this question earlier but was interrupted by a telephone call. I've just been reading about half precision floating-point format on wiki. I haven't quite figured it out yet but will follow this topic with interest.

Edited by czardas
Link to comment
Share on other sites

Perhaps if you conveyed the reason you need such a type, you might get.

some suggestions, as far as I am aware, Autoit and dllstruct does not support

such a type as "half precision float".

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Never mind. After some digging I found someone had already written a short to half precision float function on these forums:

I proceeded to port a half precision to short function from C myself:

Func _HalfPrecisionFloat2Short($float)
$float = _WinAPI_FloatToInt($float)
Local $sign = BitAND(BitShift($float, 16), 0x00008000)
Local $exponent = BitAND(BitShift($float, 23), 0x000000ff) - (127 - 15)
Local $fraction = BitAND($float, 0x007fffff)

If $exponent <= 0 Then
If $exponent < -10 Then
If $sign Then
return 0x8000
Else
return 0x0000
EndIf
$fraction = BitShift(BitOR($fraction, 0x00800000), (1-$exponent))
return BitOR($sign, BitShift($fraction, 13))
EndIf
ElseIf $exponent = 0xFF - (127 - 15) Then
If $fraction = 0 Then
return BitOR($sign, 0x7C00)
Else
$fraction = BitShift($fraction, 13)
return BitOR($sign, 0x7C00, $fraction)
EndIf
Else
if $exponent > 30 Then
return BitOR($sign, 0x7C00)
Else
return BitOR($sign, BitShift($exponent, -10), BitShift($fraction, 13))
EndIf
EndIf
EndFunc
Edited by sloth85
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...