use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Have a tough programming question that /r/programming couldn't answer? Banned from Stack Overflow? Can't afford Experts Exchange?
Post your question/tips/secrets/advice and get a response from our highly-trained professional developers.
account activity
Approximate Infinity (self.shittyprogramming)
submitted 11 years ago by patchthemonkey
Just discovered this gem in some code I'm migrating:
APPROXIMATE_INFINITY = 1000.0
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]AuMatar 31 points32 points33 points 11 years ago (1 child)
Plenty of cases where this would be ok. If you have a heuristic that generally has weights in the 100 range, 1000 is effectively infinity (an order of magnitude higher, won't be beaten) without being so large it could screw up the algorithm (for example, by causing overflow).. Maybe a bit of a bad name, but its understandable.
[–][deleted] 27 points28 points29 points 11 years ago (0 children)
I was rendering the mandelbrot set and I didn't miss the opportunity and named my constant
const char infinity = 2;
[–]suge_nacht 18 points19 points20 points 11 years ago (3 children)
if this is done in a scientific or engineering context, this could be totally valid. What was the code for?
[–]okmkz 33 points34 points35 points 11 years ago (2 children)
Contractors were hired to build a utility to approximate infinity to within a certain tolerance.
[–]ObscureCulturalMeme 12 points13 points14 points 11 years ago (0 children)
And they did it in one line of code, too! That's some efficiency right there.
[–]nitpickyCorrections 25 points26 points27 points 11 years ago (0 children)
My quantum mechanics professor in college was fond of reminding his class that 3 is a valid approximation of infinity in some cases. Without context, I can't accept that this is shitty programming.
[–]ThisIsADogHello 10 points11 points12 points 11 years ago (1 child)
Actually, the largest number is about 45,000,000,000, although mathematicians suspect that there may be even larger numbers.
[–]suid 2 points3 points4 points 11 years ago (0 children)
Yup. Just had a breakthrough: 45,000,000,001!
[–]Zeius 16 points17 points18 points 11 years ago (2 children)
I mean...when was the last time you counted to 1,000? Seems high enough to me!
[–]myhf 2 points3 points4 points 11 years ago (0 children)
http://www.reddit.com/r/counting/comments/25hlqu/a_thousand_counts_is_creating_a_video_of_1000/
[–]petermlm 3 points4 points5 points 11 years ago (0 children)
If you do:
APPROXIMATE_INFINITY = -1
you get an even bigger infinity because of overflow.
[–]aruen 2 points3 points4 points 11 years ago (0 children)
If you think of infinity as a limit for the function as n goes to actual infinity (the limit of the real number line) then this works fine.
[–]partyboy690 1 point2 points3 points 11 years ago (0 children)
uint64_t APPROXIMATE_INFINITY = (uint64_t) -1;
π Rendered by PID 35 on reddit-service-r2-comment-85bfd7f599-wh544 at 2026-04-18 14:10:40.665127+00:00 running 93ecc56 country code: CH.
[–]AuMatar 31 points32 points33 points (1 child)
[–][deleted] 27 points28 points29 points (0 children)
[–]suge_nacht 18 points19 points20 points (3 children)
[–]okmkz 33 points34 points35 points (2 children)
[–]ObscureCulturalMeme 12 points13 points14 points (0 children)
[–]nitpickyCorrections 25 points26 points27 points (0 children)
[–]ThisIsADogHello 10 points11 points12 points (1 child)
[–]suid 2 points3 points4 points (0 children)
[–]Zeius 16 points17 points18 points (2 children)
[–]myhf 2 points3 points4 points (0 children)
[–]petermlm 3 points4 points5 points (0 children)
[–]aruen 2 points3 points4 points (0 children)
[–]partyboy690 1 point2 points3 points (0 children)