PRINT USING Incorrect Results, Hang for Double Precision (43309)






This article was previously published under Q43309

SYMPTOMS

PRINT USING for double precision numbers assigned to an expression in the range of (&H1D - 128) to (&H1D - 256) (where hex and decimal notations are mixed) can produce incorrect results in the program below. In the QB.EXE editor, it ignores the format string and prints a very large number. When compiled to an executable .EXE, it produces varied results depending on the version of the compiler and the options used. Compiling for Debug (with BC /d) does not affect the result.

The following program, when compiled with BC.EXE Version 4.00 for use with BRUN, or with 4.00b, 6.00, or 6.00b for use with BCOM, prints large numbers as it does in the editor, but does not hang. When compiled with BC.EXE 4.00b, 4.50, 6.00, or 6.00b for use with BRUN, it prints very large numbers, and if run twice, it hangs the machine. When compiled with /O with BCOM in 4.00 and 4.50, it prints garbled output to the screen, but does not hang the machine.

STATUS

Microsoft has confirmed this to be a bug in Microsoft QuickBasic Versions 4.00, 4.00b, and 4.50, and in Microsoft Basic Compiler Versions 6.00 and 6.00b (buglist6.00, buglist6.00b) for MS-DOS and MS OS/2. This problem was corrected in Microsoft Basic Professional Development System (PDS) Version 7.00 (fixlist7.00).

Code Example

' You can substitute "#" for each
' double precision number with the same result.
DEFDBL A-Z
CLS

j = &H1D - 128

FOR i = 1 TO 128
  j = j / 10
  PRINT USING "##.#######"; j
  NEXT
END
				

Modification Type: Minor Last Reviewed: 1/8/2003
Keywords: KB43309