4

Disclaimer: I'm familiar with IEEE 754 floating point numbers and know that they have signed zeroes and other special values. That is not the question. If you enjoy language lawyering, read on.

We found a curious behavioral difference between 32 bit and 64 bit VBA:

' 32 bit VBA
? CStr(0.0 * -1)
0

' 64 bit VBA
? CStr(0.0 * -1)
-0

Apparently, the string representation of negative zero of (both single and double) floating point numbers is different in 32 bit and 64 bit VBA.

Section 5.5.1.2.4 of the VBA specification mentions that zero is converted to the string "0", so depending on whether you interpret (unqualified) "zero" as "positive zero" or "positive or negative zero", this could be seen as a spec violation.

Is this issue documented somewhere? Are there other floating point discrepancies between 32 and 64 bit VBA that we should be aware of?


Notes:

  • We were able to reproduce this with Office 2016 and Microsoft 365, but I doubt that the exact version matters.
  • I have tagged this question with both MS Access and MS Excel, since those are the two main "users" of VBA.
4
  • 3
    Interesting. ?-0.0 or ?-0# is also sufficient to reproduce this behavior. Commented Aug 13, 2024 at 12:02
  • It will even survive yet a forth-and-back conversion: Str(Val(Str(-0.0))) -> -0. Commented Aug 13, 2024 at 13:15
  • And, ? CStr(0.0E309 * -1) gives -1,28822975391943E-231 where as ? CStr(0.0E310 * -1) gives Overflow Commented Aug 13, 2024 at 14:49
  • @Haluk 0.0E255*-1 and 0.0E256*-1 are the cutoff for -0 and that -1.29E-231 value. Also: 0.0E-254*-1 is -0 and 0.0E-255*-1 is -3.6E+52 Commented Aug 19, 2024 at 12:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.