1275: "int(pi)"
Moderators: Moderators General, Prelates, Magistrates
Re: 1275: "int(pi)"
Why do I get the feeling that this whole thing was to set up the alttext pie joke?
Lordy! Am I becoming cynical?
Lordy! Am I becoming cynical?
 Quicksilver
 Posts: 437
 Joined: Wed Apr 29, 2009 6:21 am UTC
Re: 1275: "int(pi)"
Pi is exactly 3?
 rhomboidal
 Posts: 771
 Joined: Wed Jun 15, 2011 5:25 pm UTC
 Contact:
Re: 1275: "int(pi)"
I knew "3" was the bad apple in "13". "1" is infallible and infinitely perfectly selfdivisible.
Re: 1275: "int(pi)"
Quicksilver wrote:Pi is exactly 3?
No, int(Pi) is exactly 3. Same for floor(Pi).
This comic gave me a "meh" moment.
 phlip
 Restorer of Worlds
 Posts: 7550
 Joined: Sat Sep 23, 2006 3:56 am UTC
 Location: Australia
 Contact:
Re: 1275: "int(pi)"
The fraction looks relatively clean, in mathematical notation:
Code: Select all
enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵╰(ಠ_ಠ ⚠) {exit((int)⚠);}
Re: 1275: "int(pi)"
Quicksilver wrote:Pi is exactly 3?
While there are some variations between programming languages, what Randall's doing here is referring to three specific functions:
floor(x) gives the highest integer that is less than or equal to x. So floor(3) = floor(3.01) = floor(3.8) = floor(pi) = 3.
ceiling(x) gives the lowest integer that is greater than or equal to x. So ceiling(4) = ceiling(3.01) = ceiling(3.8) = ceiling(pi) = 4.
int(x) gives the nearest integer to x, i.e. it gives x rounded to the nearest 1. So int(3) = int(3.01) = int(2.8) = int(pi) = 3.
In other words, he's providing a way to calculate the volume of a sphere ostensibly in terms of pi and the radius of the sphere.
pollywog wrote:I want to learn this smile, perfect it, and then go around smiling at lesbians and freaking them out.Wikihow wrote:* Smile a lot! Give a gay girl a knowing "Hey, I'm a lesbian too!" smile.
 phlip
 Restorer of Worlds
 Posts: 7550
 Joined: Sat Sep 23, 2006 3:56 am UTC
 Location: Australia
 Contact:
Re: 1275: "int(pi)"
ConMan wrote:int(x) gives the nearest integer to x, i.e. it gives x rounded to the nearest 1. So int(3) = int(3.01) = int(2.8) = int(pi) = 3.
In most programming languages I've come across, int() rounds towards zero (ie the same as floor() for positive numbers and ceil() for negative numbers... simply truncating the number at the decimal point). Sometimes it rounds down (ie same as floor()) but that's less common. There aren't that many that it's a roundtonearest operation... usually there's a separate round() function for that, or failing that, floor(x + 0.5).
Code: Select all
enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵╰(ಠ_ಠ ⚠) {exit((int)⚠);}
Re: 1275: "int(pi)"
This code doesn't work correctly. Because of the parens around (4/int(pi)) the expression will be evaluated as an integer, yielding 1 instead of 1.3333... Only after the division does the result get promoted to float for the rest of the operations. If it read 4/int(pi)*pi*r^int(pi) then it would work because everything would get promoted to float beforehand.
 phlip
 Restorer of Worlds
 Posts: 7550
 Joined: Sat Sep 23, 2006 3:56 am UTC
 Location: Australia
 Contact:
Re: 1275: "int(pi)"
trwrt wrote:This code doesn't work correctly. Because of the parens around (4/int(pi)) the expression will be evaluated as an integer, yielding 1 instead of 1.3333... Only after the division does the result get promoted to float for the rest of the operations. If it read 4/int(pi)*pi*r^int(pi) then it would work because everything would get promoted to float beforehand.
Well, that depends on the language in question. Some languages will treat the division of two ints as an int division, others as a float division (and have some other syntax for performing an int division). If you're going to assume we're using a specific language, you may as well complain that "^" is bitwise XOR instead of the power function, or that it should be "(int)x" instead of "int(x)" also the constant is called "M_PI" and "func(x) = expr" isn't the valid C function declaration syntax.
Code: Select all
enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵╰(ಠ_ಠ ⚠) {exit((int)⚠);}
 cjmcjmcjmcjm
 Posts: 1158
 Joined: Tue Jan 05, 2010 5:15 am UTC
 Location: Anywhere the internet is strong
Re: 1275: "int(pi)"
Floor pi is best pi. (now I'm hungry)
HalfLife 2: Episode Pi
HalfLife 2: Episode Pi
frezik wrote:Antiphotons move at the speed of dark
DemonDeluxe wrote:Paying to have laws written that allow you to do what you want, is a lot cheaper than paying off the judge every time you want to get away with something shady.

 Posts: 34
 Joined: Tue Jul 02, 2013 4:51 am UTC
Re: 1275: "int(pi)"
Just don't use PHP: 4 ^ 3 returns 7 (it's bitwise XOR).
I think int(x) is usually truncate or round toward zero; that is 3.14 => 3, 5.6 => 5, 2.2 => 2. You get the picture.
Round is usually separate.
(edited to be clearer)
I think int(x) is usually truncate or round toward zero; that is 3.14 => 3, 5.6 => 5, 2.2 => 2. You get the picture.
Round is usually separate.
(edited to be clearer)
Re: 1275: "int(pi)"
eh, having a 3 in your code is fine. a 4 though, you know what they say : four means death.
 azule
 Saved
 Posts: 2132
 Joined: Mon Jul 26, 2010 9:45 pm UTC
 Location: The land of the Golden Puppies and Rainbows
Re: 1275: "int(pi)"
Hah, I love it. I actually got one of these programming jokes on my own. Ok, it's actually math, right? But close enough.
If you read this sig, post about one arbitrary thing you did today.
I celebrate up to six arbitrary things before breakfast.
Time does drag on and on and contain spoilers. Be aware of memes.
Re: 1275: "int(pi)"
Stop the irrationality! Vote no on ballot measure π!
 Eternal Density
 Posts: 5520
 Joined: Thu Oct 02, 2008 12:37 am UTC
 Contact:
Re: 1275: "int(pi)"
I rewrote all of Sandcastle Builder's code to conform to this.
So now I have lines like
or
and I'm not risking it with numbers close to int(pi):
or fractions of it:
or strings:
or combinations of the above:
or numbers users might see:
This delayed the release of version 1.81. I hope GLR is happy.
So now I have lines like
Code: Select all
Molpy.Boosts['Double or Nothing'].department=1*(Math.floor(Math.random()*Math.floor(Math.PI))==0);
or
Code: Select all
var nBuy = Math.pow(Math.ceil(Math.PI),Molpy.options.castlemultibuy);
and I'm not risking it with numbers close to int(pi):
Code: Select all
bonus+=Molpy.SandToolsById[i].amount*Math.pow(Math.floor(Math.PI)+.5,i+1);
or fractions of it:
Code: Select all
var amount = Math.pow(1+Math.ceil(Math.PI)/10,Math.max(0,(Molpy.SandTools['Bag'].amountMolpy.npbDoubleThreshhold)/2))1;
or strings:
Code: Select all
,"The Lord of the Bags "+Math.floor(Math.PI)+": The Return of La Petite"
,"HalfBag "+Math.floor(Math.PI)+" Confirmed!"
or combinations of the above:
Code: Select all
new Molpy.Boost({name:'Embaggening',desc:'Each Cuegan after the 14th gives a 2% boost to the sand dig rate of Bags',
sand:Math.floor(Math.PI)+'.5M',castles:'23K',icon:'embaggening'});
or numbers users might see:
Code: Select all
if(number==Math.floor(Math.PI))return 'Math.floor(Math.PI)';
if(number==Math.ceil(Math.PI))return 'Math.ceil(Math.PI)';
This delayed the release of version 1.81. I hope GLR is happy.
Play the game of Time! castle.chirpingmustard.com Hotdog Vending Supplier But what is this?
In the Marvel vs. DC filmmaking war, we're all winners.
In the Marvel vs. DC filmmaking war, we're all winners.

 Posts: 44
 Joined: Fri Apr 17, 2009 9:33 pm UTC
 Location: London, United Kingdom
Re: 1275: "int(pi)"
Well, I wish I had known of this curse BEFORE I chose my forum username...
"We are the weirdos, Mister!"
Fairuza Balk, The Craft
I have travelled from 1955 to be a member of the unofficial board Council of Elders. Phear M3
Fairuza Balk, The Craft
I have travelled from 1955 to be a member of the unofficial board Council of Elders. Phear M3
 Arancaytar
 Posts: 1642
 Joined: Thu Mar 15, 2007 12:54 am UTC
 Location: 52.44°N, 13.55°E
 Contact:
Re: 1275: "int(pi)"
Remember, you can generate EVERY natural number by a finite expression of the form ceil(pi)+...+ceil(pi)floor(pi)...floor(pi)!
"You cannot dualwield the sharks. One is enough." Our DM.
Re: 1275: "int(pi)"
This reminded me of the techniques used on the ZX81 and ZX Spectrum, where "1" was often replaced by PI/PI and "0" by PIPI.
The BASIC programs were tokenized on entry and stored in tokenized form. Numeric literals were stored as an escape byte followed by four bytes of floating point. Keywords were a single byte in the high ASCII range; these didn't even need to be scanned since they were entered with a single keypress. It was beautiful. The upshot was that a "1" took up 5 bytes, whereas PI/PI only took three. Bear in mind that you only had 1KB of memory to fit your program and data.
The BASIC programs were tokenized on entry and stored in tokenized form. Numeric literals were stored as an escape byte followed by four bytes of floating point. Keywords were a single byte in the high ASCII range; these didn't even need to be scanned since they were entered with a single keypress. It was beautiful. The upshot was that a "1" took up 5 bytes, whereas PI/PI only took three. Bear in mind that you only had 1KB of memory to fit your program and data.
xtifr wrote:... and orthogon merely sounds undecided.
 Monika
 Welcoming Aarvark
 Posts: 3655
 Joined: Mon Aug 18, 2008 8:03 am UTC
 Location: Germany, near Heidelberg
 Contact:
Re: 1275: "int(pi)"
SomeoneSomewhere wrote:Just don't use PHP: 4 ^ 3 returns 7 (it's bitwise XOR).
Is there even any language where ^ (if it exists at all) does not mean XOR and does mean "to the power of"?
orthogon wrote:This reminded me of the techniques used on the ZX81 and ZX Spectrum, where "1" was often replaced by PI/PI and "0" by PIPI.
The BASIC programs were tokenized on entry and stored in tokenized form. Numeric literals were stored as an escape byte followed by four bytes of floating point. Keywords were a single byte in the high ASCII range; these didn't even need to be scanned since they were entered with a single keypress. It was beautiful. The upshot was that a "1" took up 5 bytes, whereas PI/PI only took three. Bear in mind that you only had 1KB of memory to fit your program and data.
Wow
#xkcdq on irc.foonetic.net  the LGBTIQQA support channel
Please donate to help these people
Please donate to help these people
Re: 1275: "int(pi)"
Monika wrote:SomeoneSomewhere wrote:Just don't use PHP: 4 ^ 3 returns 7 (it's bitwise XOR).
Is there even any language where ^ (if it exists at all) does not mean XOR and does mean "to the power of"
Lua [lua.org] (and MoonScript [moonscript.org], which compiles into Lua) uses ^ for exponent instead of XOR.
Re: 1275: "int(pi)"
orthogon wrote:This reminded me of the techniques used on the ZX81 and ZX Spectrum, where "1" was often replaced by PI/PI and "0" by PIPI.
The BASIC programs were tokenized on entry and stored in tokenized form. Numeric literals were stored as an escape byte followed by four bytes of floating point. Keywords were a single byte in the high ASCII range; these didn't even need to be scanned since they were entered with a single keypress. It was beautiful. The upshot was that a "1" took up 5 bytes, whereas PI/PI only took three. Bear in mind that you only had 1KB of memory to fit your program and data.
Thanks for the memory, I'd completely forgotten that. Ahh, the good old days, if you tell that to kids today they won't believe you. (And in defence of the Speccie, it did come with 16k of RAM as basic, it was the ZX81 and the earlier ZX80 which had the 1k RAM.)
 phlip
 Restorer of Worlds
 Posts: 7550
 Joined: Sat Sep 23, 2006 3:56 am UTC
 Location: Australia
 Contact:
Re: 1275: "int(pi)"
Choonster wrote:Monika wrote:Is there even any language where ^ (if it exists at all) does not mean XOR and does mean "to the power of"
Lua [lua.org] (and MoonScript [moonscript.org], which compiles into Lua) uses ^ for exponent instead of XOR.
Haskell and VB both also have ^ as a powerof function as well. Haskell also has ** as a different powerof function... because Haskell is like that. (x^n is integer exponentiation, defined for anything that supports multiplication, to the power of a natural number... x**y is floating point exponentiation, only defined for floats.)
Code: Select all
enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵╰(ಠ_ಠ ⚠) {exit((int)⚠);}

 Posts: 284
 Joined: Fri Feb 25, 2011 8:23 am UTC
 Location: My walls are full of hungry wolves.
 Contact:
Re: 1275: "int(pi)"
Ok, I could kinda see if this was a "the program isn't working and for some dumb reason doing X seemingly irrelevant thing fixes it" joke, but... I'm just not seeing what the "the number 3 is cursed" thing is in reference to. Things like pi/pi instead of 1 being used to save memory, I guess it could be related to this, but still that doesn't quite seem to fit.
Anyone have any idea what that's about?
Anyone have any idea what that's about?
Belial wrote:I'm all outraged out. Call me when the violent rebellion starts.
Re: 1275: "int(pi)"
Monika wrote:Is there even any language where ^ (if it exists at all) does not mean XOR and does mean "to the power of"?
Also bc, a programmable arbitraryprecision calculator found in many Linux distros. However, the power must be an integer; if you want arbitrary powers, you need to use logs.

 Posts: 74
 Joined: Mon Dec 21, 2009 8:34 am UTC
Re: 1275: "int(pi)"
The PI rule of project estimation: Analyze the project and calculate a reasonable estimate of how much time it should take. Then multiply with PI.
Re: 1275: "int(pi)"
MATLAB and Octave use ^ for exponentiation.
I was also reminded of a problem set by Chris Maslanka in The Guardian. You have to make all the integers from 1 to 100 using five 5's, e.g.:
1=(5+5)/55/5
2=(5+5)/5+55
...
100=5x5x55x5
I worked on it for a while with a colleague on a business trip. We did pretty well but ran out of time/ideas before we got them all. Some thoughts spoilered in case you want to have a go:
ETA:
That's way too optimistic. The one I heard was "double it and move to the next larger unit of time", e.g. 3 days > 6 weeks, 2 months>4 years, etc.
Arancaytar wrote:Remember, you can generate EVERY natural number by a finite expression of the form ceil(pi)+...+ceil(pi)floor(pi)...floor(pi)!
I was also reminded of a problem set by Chris Maslanka in The Guardian. You have to make all the integers from 1 to 100 using five 5's, e.g.:
1=(5+5)/55/5
2=(5+5)/5+55
...
100=5x5x55x5
I worked on it for a while with a colleague on a business trip. We did pretty well but ran out of time/ideas before we got them all. Some thoughts spoilered in case you want to have a go:
Spoiler:
ETA:
Gargravarr wrote:The PI rule of project estimation: Analyze the project and calculate a reasonable estimate of how much time it should take. Then multiply with PI.
That's way too optimistic. The one I heard was "double it and move to the next larger unit of time", e.g. 3 days > 6 weeks, 2 months>4 years, etc.
xtifr wrote:... and orthogon merely sounds undecided.
Re: 1275: "int(pi)"
orthogon wrote:Gargravarr wrote:The PI rule of project estimation: Analyze the project and calculate a reasonable estimate of how much time it should take. Then multiply with PI.
That's way too optimistic. The one I heard was "double it and move to the next larger unit of time", e.g. 3 days > 6 weeks, 2 months>4 years, etc.
1 year > 2 centuries? Or two decades?
 Zassounotsukushi
 Posts: 76
 Joined: Wed Oct 26, 2011 8:38 pm UTC
 Contact:
Re: 1275: "int(pi)"
trwrt wrote:This code doesn't work correctly. Because of the parens around (4/int(pi)) the expression will be evaluated as an integer, yielding 1 instead of 1.3333... Only after the division does the result get promoted to float for the rest of the operations. If it read 4/int(pi)*pi*r^int(pi) then it would work because everything would get promoted to float beforehand.
That was my thought. While there are programs that will do (4/3) "correctly", as in the floating point math, I thought that integer division was fairly common. I would think that most real languages would return 1, as you say. If you're using something that's mathematicsoriented, probably not, but the use of ceiling() and floor() makes me think that this is intended to be relatively lowlevel, and thus not work right.
Re: 1275: "int(pi)"
brenok wrote:orthogon wrote:Gargravarr wrote:The PI rule of project estimation: Analyze the project and calculate a reasonable estimate of how much time it should take. Then multiply with PI.
That's way too optimistic. The one I heard was "double it and move to the next larger unit of time", e.g. 3 days > 6 weeks, 2 months>4 years, etc.
1 year > 2 centuries? Or two decades?
I guess 1 year > The project will be cancelled next month.
xtifr wrote:... and orthogon merely sounds undecided.
Re: 1275: "int(pi)"
orthogon wrote:This reminded me of the techniques used on the ZX81 and ZX Spectrum...
I can't quite decide whether that makes this better or worse.
Re: 1275: "int(pi)"
The number three is lava!
Re: 1275: "int(pi)"
orthogon wrote:I was also reminded of a problem set by Chris Maslanka in The Guardian. You have to make all the integers from 1 to 100 using five 5's
The earlier form of this problem (going back to the late 19th century) uses four fours.
The first printed occurrence of this activity is in "Mathematical Recreations and Essays" by W. W. Rouse Ball published in 1892. In this book it is described as a "traditional recreation".
In his discussion of the problem Ball calls it "An arithmetical amusement, said to have been first propounded in 1881, ...." . This date aligns with the appearance of the problem in Knowledge, An Illustrated Magazine of Science, (Dec 30, 1881) edited by Richard A. Proctor, the English astronomer who is remembered for one of the earliest maps of Mars.
I'm pretty sure that I first heard of the four fours puzzle in a Martin Gardner column.
Re: 1275: "int(pi)"
orthogon wrote:This reminded me of the techniques used on the ZX81 and ZX Spectrum, where "1" was often replaced by PI/PI and "0" by PIPI.
Oh, NOW someone tells me, some 30 years after I needed it.
Trying to cram programs AND operating system AND video memory into 1KB meant I NEEDED those extra bytes.
I might just have to dig that l'il beast out and try. Plugging a ZX80 into an HDTV alone might be quite satisfying...
Re: 1275: "int(pi)"
orthogon wrote:This reminded me of the techniques used on the ZX81 and ZX Spectrum, where "1" was often replaced by PI/PI and "0" by PIPI.
The BASIC programs were tokenized on entry and stored in tokenized form. Numeric literals were stored as an escape byte followed by four bytes of floating point. Keywords were a single byte in the high ASCII range; these didn't even need to be scanned since they were entered with a single keypress. It was beautiful. The upshot was that a "1" took up 5 bytes, whereas PI/PI only took three. Bear in mind that you only had 1KB of memory to fit your program and data.
I thought of that when I saw this comic, too.
On the Spectrum with 16k or more typically 48k of RAM it wasn't necessary most of the time (I certainly never came close to filling 48k), but it cropped up in the loaders of very large programs like games where the machine code was crammed into RAM so tightly that it left very little space in the BASIC area for the loader to fit.
I could see it on the unexpanded ZX81 though, where every single byte could make a difference. Now there was a system that knew how to use minimal memory. The way the screen contents were stored was particularly ingenious.
We can't go back.
We don't understand everything yet.
We don't understand everything yet.
Re: 1275: "int(pi)"
PM 2Ring wrote:orthogon wrote:I was also reminded of a problem set by Chris Maslanka in The Guardian. You have to make all the integers from 1 to 100 using five 5's
The earlier form of this problem (going back to the late 19th century) uses four fours.
Ah, so it was a twist on an old puzzle.
Spoiler:
Glad to see there are a few Sinclair BASIC oldtimers on here. I had a 48K Spectrum and I agree that the PIbaking wasn't really necessary for that  I think I saw it in printed listings in old Sinclair User mags and it made a lasting impression on me (and, I fear, my coding style) ever after.
xtifr wrote:... and orthogon merely sounds undecided.

 Posts: 11
 Joined: Wed Jun 03, 2009 5:18 pm UTC
Re: 1275: "int(pi)"
!+[]+!+[]+!+[] is 3 in javascript. Also, Astronomers often take pi to be 3 (or even sometimes 1) and pi^2 to be 10 when dealing with large numbers (the kind where you want the order of magnitude to be within an order of magnitude (wrap you're head around that!))
Re: 1275: "int(pi)"
Monika wrote:Is there even any language where ^ (if it exists at all) does not mean XOR and does mean "to the power of"?
Seriously? All {for sufficiently architected values of "all"} higherlevel languages use '^' for exponentiation. R, MatLab, and IDL are floor(pi) such examples.
There's this thing called "DWIM" (do what I mean) which, when well implemented, makes programming far faster and easier. The more you have to use nonintuitive methods and characters, the slower your work will be. And further, the harder it'll be for anyone not wellversed in your choice of programming language to understand your code.
https://app.box.com/witthoftresume
Former OTTer
Vote cellocgw for President 2020. #ScienceintheWhiteHouse http://cellocgw.wordpress.com
"The Planck length is 3.81779e33 picas."  keithl
" Earth weighs almost exactly π milliJupiters"  whatif #146, note 7
Former OTTer
Vote cellocgw for President 2020. #ScienceintheWhiteHouse http://cellocgw.wordpress.com
"The Planck length is 3.81779e33 picas."  keithl
" Earth weighs almost exactly π milliJupiters"  whatif #146, note 7
 San Fran Sam
 Posts: 228
 Joined: Tue Nov 15, 2011 5:54 pm UTC
Re: 1275: "int(pi)"
Would any of those pi be of the pumpkin variety?
Re: 1275: "int(pi)"
This expression is really slow on my computer, because it wants to calculate the last digit of pi before rounding. Does anyone know a way to optimize this?
Return to “Individual XKCD Comic Threads”
Who is online
Users browsing this forum: No registered users and 18 guests