Depends on what you mean by "true," part 27



  • I know this is an ongoing theme, but I have to share the particular flavor of truth I have to deal with:

    We're in SQL Server, dealing with a column "bInactive," data type: numeric(18,0), nullable.

    9 bytes to store this. That means possible values from -10^18 + 1 to 10^18 -1. And null. For true/false.

    The valid values in the column for this application are 0, null or -1. 0 and null mean, of course, false, while obviously -1 means true. Negated, clearly, by the name of the column, bINactive.

    'Course, there's no default or constraint or anything.

    So for the thing in question to be "active,"  you simply  check:

    coalesce( binactive,  0 ) = 0

    Several hundred thousand times a day, the program does this.

    TRUTH!

    I still have not found the value for "File Not Found," but hope springs eternal.





  • @maldrich said:


    I still have not found the value for "File Not Found," but hope springs eternal.


    "Ooh, that's a tricky one.  You have to use calculus and imaginary numbers for this."
    "Imaginary numbers?"
    "You know, eleventeen, thirty-twelve, and all those.  It's a little confusing at first."



  • FileNotFound is for complex values of -1, I think.



  • so, lemme get this straight: FileNotFound * -1 = i ?



  • true, true.



  • WTypes.h



    #define VARIANT_TRUE  ((VARIANT_BOOL)-1)


    #define VARIANT_FALSE ((VARIANT_BOOL)0)



    One's complement -1 is 0xffffffff (if it's 32 bits; 0xffff if it's
    16 bits — I'll assume y'all can infer for yourselves how many
    ones you'd have in an eight-bit integer if all eight bits were
    nonzero).



    Visual Basic uses that for its boolean constants, last I heard. I
    suppose the motivation may have been for true to be all ones, and false
    to be all zeroes: Either an aesthetic preference, or a premature
    optimization of some kind, or maybe there's a good reason that escapes
    me (and seems to have escaped Dennis Ritchie, too...). Anyhow, lots of
    poor
    dumb bastards use VB to do database stuff.





    What's with 10^18 in nine bytes? Is it binary coded decimal or something?



  • Ah, I can see the logic now. Started with VB, true became -1, then needed to store that in the database, so just create a column ... but it can't be a bit column, because it would not be able to store -1/True. So "just throw numeric(18) at it; that should do the trick!" It still irks me though.

    AFA the nine bytes, that's SQL Server:

    p (precision)

    Specifies the maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point. The precision must be a value from 1 through the maximum precision. The maximum precision is 38.

    s (scale)

    Specifies the maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 through p. The default scale is 0; therefore, 0 <= s <= p. Maximum storage sizes vary, based on the precision.

    Precision Storage bytes
    1 - 9 5
    10-19 9
    20-28 13
    29-38 17

    Why 9 in paricular I can't say...

    Thanks for shining at least a little light on this :-)


  • It probably stores 19 and 9 digit groups in 8 and 4 byte integers respectively, plus 1 extra byte for the sign.



  • @Edgar Plonk said:

    Visual Basic uses that for its boolean constants, last I heard. I
    suppose the motivation may have been for true to be all ones, and false
    to be all zeroes: Either an aesthetic preference, or a premature
    optimization of some kind, or maybe there's a good reason that escapes
    me (and seems to have escaped Dennis Ritchie, too...). Anyhow, lots of
    poor
    dumb bastards use VB to do database stuff.




    VB, at least classic VB (VB 6 and previous) does not have logical
    operators, only bitwise operators.  That is, "x And y" is
    equivalent to "x & y", not "x && y".  "Not x" is
    equivalent to "~x", not "!x".



    In addition, classic VB automatically coerces all over the place. 
    When coercing to a boolean, zero is false, any non-zero number is true.



    What this means is that for any number x, where x is not 0xFFFF (that
    is, x is not -1), (x And ((Not x)) returns True.  If you have to
    pick a value of True when coercing to a number, you may as well pick
    one that will be Not False.  Since False is 0x0000, True has to
    0xFFFF.


Log in to reply