Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pass Array of Doubles to WinAPI routine
Message
 
 
To
29/11/2003 18:42:33
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00854213
Message ID:
00854505
Views:
17
You are correct. Here's an example that proves the hypothesis. I found there were several syntax errors in my posts above regarding the use of the RtlMoveMemory routine. But this will let you pretty easily create and work with arrays of IEEE 64-bit floats by just annealing or slicing strings.
DECLARE INTEGER RtlMoveMemory IN win32API as VFPMoveDouble String @xDest, Double @xSrc, Integer nBytes
DECLARE INTEGER RtlMoveMemory IN win32API as VFPMoveFloat String @xDest, Single @xSrc, Integer nBytes
DECLARE INTEGER RtlMoveMemory IN win32API as VFPMoveToDouble Double @xDest, string @xSrc, Integer nBytes
DECLARE INTEGER RtlMoveMemory IN win32API as VFPMoveToFloat Single @xDest, string @xSrc, Integer nBytes


xDblValue=1.2345678901234567890
cStringAsFloat=Repl(CHR(0),8)  && Fill string with binary zeros
VFPMoveDouble( @cStringAsFloat, @xDblValue, 8)

* Show bytes of the string now filled
FOR i=1 TO 8
  ?ASC(SUBSTR(cStringAsFloat,i,1))
ENDFOR
?
xd=0.0   && Initialize a numeric value and move a "stringed" double into it
VFPMoveToDouble( @xD, @cStringAsFloat, 8)
* Prove the values are equal
?STR(xd,22,18)
?STR(xDblValue,22,18)

* Do the same experiment with a 32-bit float
?
cStringAsFloat=Repl(CHR(0),8)
VFPMoveFloat( @cStringAsFloat, @xDblValue, 4)

FOR i=1 TO 8
  ?ASC(SUBSTR(cStringAsFloat,i,1))
ENDFOR

VFPMoveToFloat(@xD, @cStringAsFloat, 4)
?STR(xd,22,18)  && This will display a lower precision value
Previous
Reply
Map
View

Click here to load this message in the networking platform