• (cs)

    Ehh... Mathematicians are the jealous ones! We CS majors get all the girls! Right? Erhh... right? Maybe not.

  • (cs) in reply to strictnein
    strictnein:
    Ehh... Mathematicians are the jealous ones! We CS majors get all the girls! Right? Erhh... right? Maybe not.

    Yeah, cuz we know how to hack all the pr0n sitez!

  • Math Guru (unregistered)

    Well, it doesn´t take a math guru also to see that the code is, besides crappy, wrong : it returns "even" when the number is odd (and vice versa).

  • (cs)

    Have you considered what would happen if index was bigger than MAX_INT? Or if 2 were bigger than MAX_INT? Clearly not. Luckily BigInteger is here to save your bacon!

  • snoofle (unregistered) in reply to bstorer
    bstorer:
    Have you considered what would happen if index was bigger than MAX_INT? Or if 2 were bigger than MAX_INT? Clearly not. Luckily BigInteger is here to save your bacon!
    Oh come on now, any self respecting web developer knows to make sure that you can always display 2^32+1 rows!
  • (cs)

    Why make it simple when we can complicate?

    OP:
    On a happier note, at least they're not using JavaScript or XSLT to do the presentation. As far as I'm concerned, there is hope for any company that buries display logic deep in business logic.
    +1 That one actually made me laugh out loud (luckily, I have an office of my own).

    But the existence of this function doesn't mean that it's in a business logic layer. It could very well be a Bean, or a static ArrayListToHtml() method.

  • Carsten Otto (unregistered)

    I am working on a quite huge scientific project, where the underlying data structures were modified to use BigInts recently. Now I am happy to work with code snippets where I know that the greatest number ever occuring is TWO. Unfortunately BigInteger has no constant TWO :)

    PS: BigInts make much sense in other parts of the project using the very same data structures.

  • (cs)
    new BigInteger("2")

    I have absolutely no idea what could possibly go through the mind of the coder who typed this.

    Would you not, while your typing slows down with each key you press, grow a marginally more ill and green look on your face as you plodded though the quote, the 2, the closing-quote and finished, heavily panting plus throbbing headache, with a closing parenthesis? Like so:

    Big.. Integer..

    ...

    ...

    ergh

    ...

    (reaching for key)

    ...TWO

    ...

    AUGH

    phew

    done

    There. It is done. Created: an aircraft hangar. Inside: a matchbox.

  • richtenstein (unregistered)

    If int index is bigger than MAX_INT then I think we are one step closer to TARDIS technology!

  • Anonymous commie (unregistered) in reply to bstorer
    bstorer:
    Have you considered what would happen if index was bigger than MAX_INT? Or if 2 were bigger than MAX_INT? Clearly not. Luckily BigInteger is here to save your bacon!
    And it was very clever of the original coder to use "String" for the result, so that he/she didn't have to consider what could happen if dividing two numbers larger than MAX_INT.
  • Aaron (unregistered)

    Bigger is better, I thought? Why do arithmetic with a measly 32 bits when 64 bits are just sitting there waiting for an opportunity to prove themselves?

    Actually - and I recognize the sarcasm in the topic post but some others may not - there are legitimate uses for BigInt/Int64. We're rapidly approaching the point where a few of our tables will have more than 2147483648 rows, Decimal types are a waste of space in an identity key, and a GUID isn't appropriate in this case. Bigint is a small performance hit and should last a few centuries.

    That's a pretty narrow case, though. I'm almost positive that Int64 is never used anywhere else in the entire system.

  • Anonymous commie (unregistered) in reply to Aaron
    Aaron:
    We're rapidly approaching the point where a few of our tables will have more than 2147483648 rows, Decimal types are a waste of space in an identity key, and a GUID isn't appropriate in this case. Bigint is a small performance hit and should last a few centuries.
    Definitively. But I would personally hate to browse through a web page with more than 2147483648 rows, and I think I would still hate it in the next century.
  • Ken (unregistered)

    Yes, there is the "what if index is larger than MAX_INT" situation. I thought of that at first, until I re-read the code:

    public String rowClass( int index )
    And, in addition to the return being a string of "even" or "odd", the modulo result is converted to a string as well.
  • (cs) in reply to dhromed
    dhromed:
    new BigInteger("2")
    Would you not, while your typing slows down with each key you press, grow a marginally more ill and green look on your face as you plodded though the quote, the 2, the closing-quote and finished, heavily panting plus throbbing headache, with a closing parenthesis?

    How about:

    Big (snicker) Integer (snort) ... ... (shaking uncontrolably, face turning red from holding breath) ... ... TWO ... (laughs maniacally, scaring boss' children who were visiting and causing devout atheist coworkers to look for a church).

  • Jon Skeet (unregistered)

    I'm surprised that there have been this many comments without someone pointing out that

    if ((x%2)==0) is the same as if ((x&1)==0)

    but the latter is marginally faster. Less readable (arguably), and bound to make no significant difference at all, but that doesn't usually stop the comments :)

  • Duston (unregistered) in reply to Anonymous commie
    Anonymous commie:
    Definitively. But I would personally hate to browse through a web page with more than 2147483648 rows, and I think I would still hate it in the next century.

    But what about the people with 2147483649 messages in their inbox?

  • Le Poete (unregistered) in reply to dhromed
    dhromed:
    new BigInteger("2")

    I have absolutely no idea what could possibly go through the mind of the coder who typed this.

    Would you not, while your typing slows down with each key you press, grow a marginally more ill and green look on your face as you plodded though the quote, the 2, the closing-quote and finished, heavily panting plus throbbing headache, with a closing parenthesis? Like so:

    Big.. Integer..

    ...

    ...

    ergh

    ...

    (reaching for key)

    ...TWO

    ...

    AUGH

    phew

    done

    There. It is done. Created: an aircraft hangar. Inside: a matchbox.

    That is a thing I see frequently in VB.NET simply because on data type naming (int = Integer; BigInteger = Long).

    This is most often a misuse brought over from VB6 programmers who didn't pay attention to changes in data types between VB6 and VB.NET as Integer in VB6 was 16bits and is now 32bits in .NET, but Long which was the 32 bits in VB6 is now 64bits. So some people might think they use 32bits with Long data types.

  • katre (unregistered) in reply to Jon Skeet
    Jon Skeet:
    I'm surprised that there have been this many comments without someone pointing out that

    if ((x%2)==0) is the same as if ((x&1)==0)

    but the latter is marginally faster. Less readable (arguably), and bound to make no significant difference at all, but that doesn't usually stop the comments :)

    Hmm, it's less readable, and it's the kind of simple optimization the compiler or the JVM can do? I'll definitely go change all my code, right now!

  • Daniel C W (unregistered) in reply to Aaron
    BigInt/Int64
    Just in case: I thought BigInt refers to the BigIntegers that are as large as required to store any possible number (part of N). So they can be alot larger than 64 bit.
  • Misha (unregistered)
    Full Article • 255 Words
    Hmm, did someone use a Byte for the word count variable? Should have used a BigInt.
  • Aaron (unregistered) in reply to Anonymous commie
    Anonymous commie:
    Definitively. But I would personally hate to browse through a web page with more than 2147483648 rows, and I think I would still hate it in the next century.
    Funny. Fortunately for our users, these tables aren't edited or dumped directly!

    Although one client did ask explicitly for raw data totalling a few million rows - can't imagine what they intend to do with it.

  • forgeten (unregistered) in reply to bstorer
    bstorer:
    Have you considered what would happen if index was bigger than MAX_INT? Or if 2 were bigger than MAX_INT? Clearly not. Luckily BigInteger is here to save your bacon!

    except index is passed in as a int in the params

  • (cs) in reply to dhromed
    dhromed:
    There. It is done. Created: an aircraft hangar. Inside: a matchbox.

    Omg... that was great...

  • The One True Josh (unregistered)

    ... that everywhere it's used looks something like this:

    ... = (rowClass(index) == "even")?0:1;

  • (cs) in reply to snoofle
    snoofle:
    bstorer:
    Have you considered what would happen if index was bigger than MAX_INT? Or if 2 were bigger than MAX_INT? Clearly not. Luckily BigInteger is here to save your bacon!
    Oh come on now, any self respecting web developer knows to make sure that you can always display 2^32+1 rows!
    I sense sarcasm in your statement... You can't just assume that int is 32-bits. What if you have a one bit integer? Then you need BigInteger for the 2.
  • Meh, who cares? (unregistered)

    um, ok... why not...

    while(results){ /* some code with RowClass */ if(RowClass.value == "odd") RowClass.value = "even"; else RowClass.value = "odd"; } ... instead?

  • (cs) in reply to forgeten
    forgeten:
    bstorer:
    Have you considered what would happen if index was bigger than MAX_INT? Or if 2 were bigger than MAX_INT? Clearly not. Luckily BigInteger is here to save your bacon!

    except index is passed in as a int in the params

    That sound you hear is the joke flying way over your head.

  • Meh, who cares? (unregistered) in reply to Meh, who cares?

    or a one-line...

    while(results){ /* some code with RowClass */ RowClass.value = RowClass.value == "odd"?"even":"odd"; }

  • Anonymous commie (unregistered) in reply to Duston
    Duston:
    Anonymous commie:
    Definitively. But I would personally hate to browse through a web page with more than 2147483648 rows, and I think I would still hate it in the next century.

    But what about the people with 2147483649 messages in their inbox?

    I think they hate their inbox.

  • (cs)

    As Daniel mentioned BigInteger can actually contain any number, its even used for 512bit numbers.

  • no name (unregistered) in reply to bstorer
    bstorer:
    snoofle:
    bstorer:
    Have you considered what would happen if index was bigger than MAX_INT? Or if 2 were bigger than MAX_INT? Clearly not. Luckily BigInteger is here to save your bacon!
    Oh come on now, any self respecting web developer knows to make sure that you can always display 2^32+1 rows!
    I sense sarcasm in your statement... You can't just assume that int is 32-bits. What if you have a one bit integer? Then you need BigInteger for the 2.

    But, it looks like we are dealing with Java, so ints are always 32 bits, no matter what the underlying architecture.

    If I remember right, even in C they have to be at least 7 bits.

  • Anonymous commie (unregistered) in reply to Aaron
    Aaron:
    Anonymous commie:
    Definitively. But I would personally hate to browse through a web page with more than 2147483648 rows, and I think I would still hate it in the next century.
    Funny. Fortunately for our users, these tables aren't edited or dumped directly!
    In this case, there is no need for color coding every other row in HTML, is it?(*)
    Aaron:
    Although one client did ask explicitly for raw data totalling a few million rows - can't imagine what they intend to do with it.
    I remember legends told about Real Programmers in the Old Days that could read hex dumps, which was then basically a pile of pyjama paper - some inches high (or multiple of 5 centimeters - lets not get started on the "metrics suck!" topic again, please) - filled with hex numbers. Maybe your client was a Real Programmer.

    (*) Sorry for being so picky...

  • Anonymous commie (unregistered) in reply to no name
    no name:
    bstorer:
    I sense sarcasm in your statement... You can't just assume that int is 32-bits. What if you have a one bit integer? Then you need BigInteger for the 2.

    But, it looks like we are dealing with Java, so ints are always 32 bits, no matter what the underlying architecture.

    If I remember right, even in C they have to be at least 7 bits.

    The jokes are really flying high today...

  • (cs) in reply to dhromed
    dhromed:
    new BigInteger("2")

    I have absolutely no idea what could possibly go through the mind of the coder who typed this.

    Maybe his editor used a really large font.

  • (cs) in reply to Duston
    Duston:
    Anonymous commie:
    Definitively. But I would personally hate to browse through a web page with more than 2147483648 rows, and I think I would still hate it in the next century.

    But what about the people with 2147483649 messages in their inbox?

    There are days that it feels like I have 2147483649 messages in my inbox. Is there a macro that in one click, I can use to send them all back with a common message?

  • (cs) in reply to bstorer
    bstorer:
    snoofle:
    bstorer:
    Have you considered what would happen if index was bigger than MAX_INT? Or if 2 were bigger than MAX_INT? Clearly not. Luckily BigInteger is here to save your bacon!
    Oh come on now, any self respecting web developer knows to make sure that you can always display 2^32+1 rows!
    I sense sarcasm in your statement... You can't just assume that int is 32-bits. What if you have a one bit integer? Then you need BigInteger for the 2.
    <being picky> Isn't a one bit integer a boolean? Oh wait, I forgot; booleans have 3 or 4 states ;) </being picky>
  • Kinglink (unregistered) in reply to Aaron

    I've seen a lot of people defend big int but they seem to miss a little problem.

    The parameter into this function is an int, it's never going to be able to get any number that's close to needing big int.

    Captcha: Yummy, like my bagel.

  • -j (unregistered)

    Err, I think that usually a big integer has a maximum of 2^32 bits, rather than 64 or "arbitrarily many"

  • (cs) in reply to Anonymous commie
    Anonymous commie:
    <snip> I remember legends told about Real Programmers in the Old Days that could read hex dumps, which was then basically a pile of pyjama paper - some inches high (or multiple of 5 centimeters - lets not get started on the "metrics suck!" topic again, please) - filled with hex numbers. Maybe your client was a Real Programmer.

    Wait a minute.... when I first started out, I would frequently have to sift through mountains of printed hex dumps. I even used to read wave forms on an oscilloscope to read memory contents (breadboarding). Great, now I feel old.

  • (cs) in reply to snoofle
    snoofle:
    Duston:
    Anonymous commie:
    Definitively. But I would personally hate to browse through a web page with more than 2147483648 rows, and I think I would still hate it in the next century.

    But what about the people with 2147483649 messages in their inbox?

    There are days that it feels like I have 2147483649 messages in my inbox. Is there a macro that in one click, I can use to send them all back with a common message?
    There's the "Select All, Delete" option. Will that work?

  • Scooter Libby (unregistered) in reply to bstorer
    bstorer:
    snoofle:
    Duston:
    Anonymous commie:
    Definitively. But I would personally hate to browse through a web page with more than 2147483648 rows, and I think I would still hate it in the next century.

    But what about the people with 2147483649 messages in their inbox?

    There are days that it feels like I have 2147483649 messages in my inbox. Is there a macro that in one click, I can use to send them all back with a common message?
    There's the "Select All, Delete" option. Will that work?

    No. It was implemented with a signed short.

  • (cs)

    I'm tempted to go draw a three foot tall number "two" on the whiteboard over there. When anyone asks, I'll tel them "It's my BigInt!"

  • funthomas (unregistered) in reply to snoofle
    <being picky> Isn't a one bit integer a boolean? Oh wait, I forgot; booleans have 3 or 4 states ;) </being picky>
    For booleans with 3 or more states one should use BigBoolean, of course. Wonder, however, what's the value of MAX_BOOLEAN.
  • infidel (unregistered)

    One of the neatest features that sold me on Python is the way it lets you work with integers of any size:

    10 ** 100 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000L

  • (cs)
    ( (evenRow.equals("0")) ? "odd" : "even" );

    WTF... this produces exactly the wrong answer every time!

    That function could be added to the Paula Bean...

  • Dim Jim (unregistered)

    A couple points of information. Hard Disk drive size and the limit of seeking into a file to and passed 2GB (2^32) around about 1990. In those 17 years, there have been enough rounds of this coming to and going by a limit ala Y2k and the silliness of last week's daylight savings that you'd think the hive mindset would be smarter about these kinds of issues.

    When 2^64 isn't enough, something written today will still be around.

    BTW, what is the largest Usenet News newsgroup number? There was a time it was 32k then 64k.

  • ÿ (unregistered) in reply to Duston
    Duston:
    But what about the people with 2147483649 messages in their inbox?

    Intervention. Those people need an intervention.

  • MWL (unregistered) in reply to dhromed
    dhromed:
    new BigInteger("2")
    There. It is done. Created: an aircraft hangar. Inside: a matchbox.

    A beautiful mental image, although perhaps not quite horrifying enough.

    On a straight line, using a line 2mm long for the "2", and a mere 64bit number for our BigInt...

    According to Google calculator, (2^64) millimeters = 123308.761 Astronomical Units = 1.94986403 lightyears (and probably even more teaspoons)

    Working with a real 3d matchbox 25mL in volume... the aircraft hangar should have a volume of... (25 mL) * .5 * (2^64) = 230 584.301 cubic km

    The mind boggles

    (disclaimer - this math is probably very, very wrong)

  • Moogle (unregistered)

    Bwahahah, I should probably submit this as a full WTF on its own, it's so bad. (Except it's a student project, so not so surprising.)

    I and a friend had a CS theory class where we had to write a bigint class to do RSA encryption - we couldn't use the native bigint in whatever language we chose. I originally wrote mine in C, but as the deadline neared and my memory usage exploded, I realized it would be faster to rewrite in java than to fix the memory leaks. I ended up with a pretty good bigint class that would do math calculations on 32 bit chunks, calculating overflows and everything.

    I had been keeping tabs on my friends progress, but I didn't quite pay enough attention to understand what he was up to until the very end. I forget what language he used (java also I guess), but apparently since the TAs said they'd only be testing 512 bit keys, he was statically allocating 1024 bits (to hold multiplications of two 512 bit numbers). So aside from not being an arbitrary sized bigint, it used the same memory whether it is was holding 2 or 2e200.

    It was only after the due date that he explained, to my great horror, that he was using 32 bit integers to hold his bits.

    1024 32 bit ints to hold each individual 1 or 0 ...

  • (cs) in reply to -j
    -j:
    Err, I think that usually a big integer has a maximum of 2^32 bits, rather than 64 or "arbitrarily many"
    That's the difference between a big integer and a BigInteger.

Leave a comment on “Big Math, Little Snippet ”

Log In or post as a guest

Replying to comment #:

« Return to Article