5

I keep seeing references to a specific value in vb code I am looking at, and wondered if anyone has any clues as to the significance.

var_ret_1 = Int((6.37066138261923E-314 / 32))

and

loc_0046BBAE: Var_Ret_2 = CDbl((6.37066138261923E-314 - 6.37066138261923E-314))
loc_0046BBC4: fcomp real8 ptr var_5C
loc_0046BBE3: Err.Raise
loc_0046BBE9:
loc_0046BBF5: If word ptr [ecx] < 0 Then GoTo loc_0046BBFD
loc_0046BBF7: Err.Raise
loc_0046BBFD:
loc_0046BC00: shl eax, 04h
loc_0046BC03: edi+edi*4 = edi+edi*4 - word ptr var_28
loc_0046BC0E: shl eax, 04h
loc_0046BC11: esi+esi*4 = esi+esi*4 - word ptr [ecx]
loc_0046BC38: Var_Ret_3 = CDbl((6.37066138261923E-314 - 6.37066138261923E-314))
loc_0046BC4E: fcomp real8 ptr var_68
loc_0046BC6F: edi = word ptr [eax] - 1```
Craig
  • 2,248
  • 1
  • 19
  • 23
  • I see the magic number in your VB example code. What source are you referencing to? Where does the example come from? – user11909 May 09 '19 at 13:29
  • The examples are just snippets of code I found on the 'net - they always use that specific number, and as part of the learning experience I'd like to know what it is, why it's used, and what it does. :) So the magic number is a defined constant? Why is the same value used in so many snippets, and for what purpose? It doesn't seem to be a meaningful value... – user3406968 May 09 '19 at 13:34
  • 4
    Error handling in VBA relies on the OS support for exceptions (SEH). It uses an oddball exception code, 0xC0000090 (aka "Floating-point invalid operation"). Hard to guess why they liked that one, but it does have the advantage of being easy to trigger. – Hans Passant May 09 '19 at 13:37
  • 2
    @HansPassant how do you even know those things :) – the_lotus May 09 '19 at 13:38
  • Been there, seen it. Advantage of being an old fart that didn't forget too much yet. – Hans Passant May 09 '19 at 13:42
  • @HansPassant ooookay, how does 0xC0000090 relate to the number though? Is it something to do with testing the accuracy of 32 bit numbers? – user3406968 May 09 '19 at 13:43
  • 1
    Math on denormal floating point operands, https://stackoverflow.com/a/14002547/17034 – Hans Passant May 09 '19 at 13:51
  • 1
    The source code you have posted is not ordinary VB6. It is decompiled from a compiled EXE. It's a mixture of assembly language (e.g. `shl eacx, 04h`) and VB6 (e.g. `CDbl`). It won't compile as VB6 nor will it build as assembler. The decompiler may be doing something odd to the source code. You say you found the code on the 'net, where exactly was it? – MarkJ May 14 '19 at 11:28

1 Answers1

0

That's in the neighborhood of the smallest (closest to zero) 64-bit floating point number. Maybe when you subtract it from itself, it either raises an error (exponent overflow), zeroes out Var_Ret_2 and Var_Ret_3, or doesn't quite zero out those variables.

This seems like questionable code.

xpda
  • 15,585
  • 8
  • 51
  • 82