Condividi tramite


Visual Basic Concepts

Allow Unrounded Floating-Point Operations

Allows the compiler to compare the results of floating-point expressions without first rounding those results to the correct precision.

Floating-point calculations are normally rounded off to the correct degree of precision (Single or Double) before comparisons are made. Selecting this option allows the compiler do floating-point comparisons before rounding, when it can do so more efficiently. This improves the speed of some floating-point operations; however, this may result in calculations being maintained to a higher precision than expected, and two floating-point values that might be expected to compare equal might not.

In general this option should not be used if you perform equality comparisons directly on the results of floating-point computations. For example:

Dim Q As Single

Q = <floating-point computation>
  …
If Q = <floating-point computation> then
  ...
End If

If the option is set, the comparison of Q will be made with the result of the floating-point expression, which will likely have higher precision than that of a Single, so the comparison may fail. If the option is not set, the result of the floating-point expression will be rounded to the appropriate precision (Single) before the comparison, then the comparison will succeed.