sloth85 Posted June 21, 2012 Posted June 21, 2012 I would like to convert from 2 byte shorts tohalf precision floats and vice versa. Are there any functions that can accomplish this?
jchd Posted June 21, 2012 Posted June 21, 2012 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 hereRegExp tutorial: enough to get startedPCRE 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)
czardas Posted June 22, 2012 Posted June 22, 2012 (edited) 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 June 22, 2012 by czardas operator64 ArrayWorkshop
JohnOne Posted June 22, 2012 Posted June 22, 2012 (edited) 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 June 22, 2012 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
sloth85 Posted June 22, 2012 Author Posted June 22, 2012 (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 June 22, 2012 by sloth85
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now