| « Prev | Page 1 | Page 2 | Next » |
|
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! |
|
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).
|
|
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!
|
Re: Big Math, Little Snippet
2007-03-14 09:17
•
by
snoofle
(unregistered)
|
Oh come on now, any self respecting web developer knows to make sure that you can always display 2^32+1 rows! |
|
Why make it simple when we can complicate?
+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. |
|
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. |
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. |
|
If int index is bigger than MAX_INT then I think we are one step closer to TARDIS technology!
|
Re: Big Math, Little Snippet
2007-03-14 09:23
•
by
Anonymous commie
(unregistered)
|
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. |
|
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. |
Re: Big Math, Little Snippet
2007-03-14 09:33
•
by
Anonymous commie
(unregistered)
|
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. |
|
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:
And, in addition to the return being a string of "even" or "odd", the modulo result is converted to a string as well. |
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). |
|
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 :) |
Re: Big Math, Little Snippet
2007-03-14 09:41
•
by
Duston
(unregistered)
|
But what about the people with 2147483649 messages in their inbox? |
Re: Big Math, Little Snippet
2007-03-14 09:41
•
by
Le Poete
(unregistered)
|
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. |
Re: Big Math, Little Snippet
2007-03-14 09:45
•
by
katre
(unregistered)
|
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! |
Re: Big Math, Little Snippet
2007-03-14 09:47
•
by
Daniel C W
(unregistered)
|
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. |
Hmm, did someone use a Byte for the word count variable? Should have used a BigInt. |
Re: Big Math, Little Snippet
2007-03-14 09:48
•
by
Aaron
(unregistered)
|
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. |
Re: Big Math, Little Snippet
2007-03-14 09:53
•
by
forgeten
(unregistered)
|
except index is passed in as a int in the params |
Re: Big Math, Little Snippet
2007-03-14 09:53
•
by
SpiritOfGrandeur
|
Omg... that was great... |
What do you want to bet...
2007-03-14 10:01
•
by
The One True Josh
(unregistered)
|
|
... that everywhere it's used looks something like this:
... = (rowClass(index) == "even")?0:1; |
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. |
Re: Big Math, Little Snippet
2007-03-14 10:02
•
by
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? |
That sound you hear is the joke flying way over your head. |
Re: Big Math, Little Snippet
2007-03-14 10:04
•
by
Meh, who cares?
(unregistered)
|
|
or a one-line...
while(results){ /* some code with RowClass */ RowClass.value = RowClass.value == "odd"?"even":"odd"; } |
Re: Big Math, Little Snippet
2007-03-14 10:06
•
by
Anonymous commie
(unregistered)
|
I think they hate their inbox. |
|
As Daniel mentioned BigInteger can actually contain any number, its even used for 512bit numbers.
|
Re: Big Math, Little Snippet
2007-03-14 10:12
•
by
no name
(unregistered)
|
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. |
Re: Big Math, Little Snippet
2007-03-14 10:22
•
by
Anonymous commie
(unregistered)
|
In this case, there is no need for color coding every other row in HTML, is 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... |
Re: Big Math, Little Snippet
2007-03-14 10:24
•
by
Anonymous commie
(unregistered)
|
The jokes are really flying high today... |
Re: Big Math, Little Snippet
2007-03-14 10:33
•
by
SuperousOxide
|
Maybe his editor used a really large font. |
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? |
<being picky> Isn't a one bit integer a boolean? Oh wait, I forgot; booleans have 3 or 4 states ;) </being picky> |
Re: Big Math, Little Snippet
2007-03-14 10:42
•
by
Kinglink
(unregistered)
|
|
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. |
|
Err, I think that usually a big integer has a maximum of 2^32 bits, rather than 64 or "arbitrarily many"
|
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. |
There's the "Select All, Delete" option. Will that work? |
Re: Big Math, Little Snippet
2007-03-14 11:01
•
by
Scooter Libby
(unregistered)
|
No. It was implemented with a signed short. |
|
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!"
|
Re: Big Math, Little Snippet
2007-03-14 11:06
•
by
funthomas
(unregistered)
|
For booleans with 3 or more states one should use BigBoolean, of course. Wonder, however, what's the value of MAX_BOOLEAN. |
|
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 |
WTF... this produces exactly the wrong answer every time! That function could be added to the Paula Bean... |
|
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. |
Re: Big Math, Little Snippet
2007-03-14 11:51
•
by
ÿ
(unregistered)
|
Intervention. Those people need an intervention. |
Re: Big Math, Little Snippet
2007-03-14 11:57
•
by
MWL
(unregistered)
|
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) |
|
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 ... |
That's the difference between a big integer and a BigInteger. |
| « Prev | Page 1 | Page 2 | Next » |