According to the PB documentation for PB/CC, the RND function returns an extended precision value that is >= 0 and < 1. However, when you do a hex dump of the RND value assigned to an EXT variable (retrieving the 10 bytes stored in memory for the EXT value) using the code below, the lower four bytes of the stored variable never seem to change, seeming to suggest that the RND function does not return an extended precision value.
I'd really appreciate comments on this post before I request support regarding this issue.
I'd really appreciate comments on this post before I request support regarding this issue.
Code:
' rnd_test.bas ' PB/CC 4.04 #DEBUG ERROR ON #DIM ALL #REGISTER ALL #COMPILE EXE FUNCTION hex_data_dump(BYVAL value AS EXT)AS STRING 'retrieve 10-byte memory contents of ext variable LOCAL mem_bytes AS STRING LOCAL byte_counter AS LONG LOCAL address AS DWORD mem_bytes = "" address = VARPTR(value) + 9 'Address of most significant byte FOR byte_counter = 1 TO 10 mem_bytes = mem_bytes + HEX$(PEEK(BYTE, address),2) DECR address NEXT byte_counter FUNCTION = mem_bytes END FUNCTION FUNCTION PBMAIN () AS LONG LOCAL z AS EXT LOCAL counter AS LONG LOCAL hex_string AS STRING FOR counter = 1 TO 10000000 IF counter MOD 100000 = 0 THEN PRINT FORMAT$(counter, "#,") 'print counter every 100000 z = RND hex_string = hex_data_dump(z)'Assign memory contents for EXT variable z to hex_string. IF MID$(hex_string, 13) <> "00000000" THEN 'Test whether lower four bytes of EXT variable are all zeroes. PRINT "EXT lower 4 bytes not all zeroes!", hex_string WAITKEY$ END IF NEXT counter PRINT "end of program" WAITKEY$ END FUNCTION
Comment