Jump to content

Recommended Posts

Posted

I would like to convert from 2 byte shorts tohalf precision floats and vice versa. Are there any functions that can accomplish this?

Posted

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?

  Reveal hidden contents

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)

Posted (edited)

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

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
  • Recently Browsing   0 members

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