News:

Facebook killed the radio star. And by radio star, I mean the premise of distributed forums around the internet. And that got got by Instagram/SnapChat. And that got got by TikTok. Where the fuck is the internet we once knew?

Main Menu

[JAVA] Calculate Pi!

Started by Joe, November 08, 2005, 10:10:27 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Joe

Yes! A very advanced mathematical..tool?

This is the brainchild of five straight hours of pondering the problem, resulting in 5 hours of detention to be served starting tomorrow, for insubordination when teachers told me to get to work.

public class CalculatePi {
  public static void main(String args[]) {
    System.out.println("Pi: " + 4 * Math.atan(1));
  }
}


I also managed to port it to Visual Basic after another three hours of work, mostly debugging.
Public Sub Main
    Call MsgBox(4 * Atan(1))
End Sub


You may use this in your programs for a royalty of 50cents per copy sold.
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


Sidoh


Newby

How about pi?

Or (22 / 7) (isn't that supposed to be pi?)
- Newby
http://www.x86labs.org

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote from: Rule on June 30, 2008, 01:13:20 PM
Quote from: CrAz3D on June 30, 2008, 10:38:22 AM
I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT. 

Joe

Quote from: Sidoh on November 08, 2005, 10:25:51 PM
Wow, your teachers suck. -_-

We didn't learn that in school son.

Newby, I doubt it. Just a sec..

EDIT -
No, but its close. 22/7=3.1428571
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


deadly7

Quote from: Newby on November 08, 2005, 10:26:12 PM
How about pi?

Or (22 / 7) (isn't that supposed to be pi?)
I think it is.
Pi = the world's gayest number.
[17:42:21.609] <Ergot> Kutsuju you're girlfrieds pussy must be a 403 error for you
[17:42:25.585] <Ergot> FORBIDDEN

on IRC playing T&T++
<iago> He is unarmed
<Hitmen> he has no arms?!

on AIM with a drunk mythix:
(00:50:05) Mythix: Deadly
(00:50:11) Mythix: I'm going to fuck that red dot out of your head.
(00:50:15) Mythix: with my nine

Joe

#5
22/7 is 3.1428571. Pi is 3.141592 something.

EDIT -
deadly, actually, that would be infinity (the gayest number). At least you can add/subtract/multiply/divide something by pi and get something not pi.

Also, pi is not only a number, but the 16th letter in the greek alphabet.



STUPID -
Hm, are they going to start with hurricane gamma next year? I can just see it now "Hurricane Pi is coming!"
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


Sidoh

Quote from: deadly7 on November 08, 2005, 10:35:51 PM
Quote from: Newby on November 08, 2005, 10:26:12 PM
How about pi?

Or (22 / 7) (isn't that supposed to be pi?)
I think it is.
Pi = the world's gayest number.

No, it's not.  It's moderately close, but using a Pi constant on calculators is a lot more accurate than using 22/7.

Joe

Quote from: Sidoh on November 08, 2005, 10:51:34 PM
Quote from: deadly7 on November 08, 2005, 10:35:51 PM
Quote from: Newby on November 08, 2005, 10:26:12 PM
How about pi?

Or (22 / 7) (isn't that supposed to be pi?)
I think it is.
Pi = the world's gayest number.

No, it's not. It's moderately close, but using a Pi constant on calculators is a lot more accurate than using 22/7.

Anyone here work at TI and know how that's done? I figure its probably 4*ATan(1) rounded to the nearest millionth or something.
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


Sidoh

Quote from: Joe[e2] on November 08, 2005, 11:12:32 PM
Anyone here work at TI and know how that's done? I figure its probably 4*ATan(1) rounded to the nearest millionth or something.

How what's done?  Calculating Pi?  There's a stored constant for Pi in all TI model's I've ever used.  Calculating it is pretty dumb.  Plus, all TI model's I've seen round to the nearest 10th digit (or at least that's what I understand).

trust

infinity isn't a number.

I've debated it with my math teacher and that's what she says.

iago

Infinity isn't a number.  But, then, neither is 0, so eh?

And by the way, taking the atan of 1 isn't calculating Pi, since the forumla for arctan uses Pi.  It's like "calculating" the constant C in a=bC by setting b to 1.  You aren't calculating anything.  The best way to calculate Pi in Java is Math.PI, I believe.

To actually calculate Pi, it's an infinite formula.  You can keep going and it gets more and more accurate the longer you iterate, until you run out of room in your variable (unless you're using java.Math.BigDecimal, then you can go forever). 

I believe this is it:

MyndFyre

What is that, the sequence of squares over odd numbers (roughly)?
Quote from: Joe on January 23, 2011, 11:47:54 PM
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Quote from: Rule on May 26, 2009, 02:02:12 PMOur species really annoys me.

iago

Yeah, that sounds right.  It looks pretty recursive, and the deeper you go the more accurate you get.  Of course, on computess, double's are only see accurate in the first place, so..

d&q

Infinity isn't a number, its a concept.

I've used this formula for Pi since 'round sixth grade:

The writ of the founders must endure.

Quik

If infinity isn't a number, is e? I recently had a conversation with my math teacher about "the number e" (Euler's number)
Quote[20:21:13] xar: i was just thinking about the time iago came over here and we made this huge bomb and light up the sky for 6 min
[20:21:15] xar: that was funny