Author Topic: [JAVA] Calculate Pi!  (Read 19199 times)

0 Members and 1 Guest are viewing this topic.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
[JAVA] Calculate Pi!
« on: November 08, 2005, 10:10:27 pm »
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.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [JAVA] Calculate Pi!
« Reply #1 on: November 08, 2005, 10:25:51 pm »
Wow, your teachers suck. -_-

Offline Newby

  • Moderator
  • Hero Member
  • *****
  • Posts: 10877
  • Thrash!
    • View Profile
Re: [JAVA] Calculate Pi!
« Reply #2 on: November 08, 2005, 10:26:12 pm »
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

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. 

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [JAVA] Calculate Pi!
« Reply #3 on: November 08, 2005, 10:35:00 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
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline deadly7

  • 42
  • x86
  • Hero Member
  • *****
  • Posts: 6496
    • View Profile
Re: [JAVA] Calculate Pi!
« Reply #4 on: November 08, 2005, 10:35:51 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

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [JAVA] Calculate Pi!
« Reply #5 on: November 08, 2005, 10:39:40 pm »
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!"
« Last Edit: November 08, 2005, 10:44:16 pm by Joe[e2] »
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [JAVA] Calculate Pi!
« Reply #6 on: November 08, 2005, 10:51:34 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.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [JAVA] Calculate Pi!
« Reply #7 on: November 08, 2005, 11:12:32 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.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [JAVA] Calculate Pi!
« Reply #8 on: November 09, 2005, 12:06:01 am »
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

  • Guest
Re: [JAVA] Calculate Pi!
« Reply #9 on: November 09, 2005, 06:20:14 am »
infinity isn't a number.

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

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: [JAVA] Calculate Pi!
« Reply #10 on: November 09, 2005, 08:34:39 am »
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:

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: [JAVA] Calculate Pi!
« Reply #11 on: November 09, 2005, 10:25:19 am »
What is that, the sequence of squares over odd numbers (roughly)?
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: [JAVA] Calculate Pi!
« Reply #12 on: November 09, 2005, 05:42:08 pm »
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..

Offline d&q

  • Hero Member
  • *****
  • Posts: 1427
  • I'm here.
    • View Profile
    • Site
Re: [JAVA] Calculate Pi!
« Reply #13 on: November 09, 2005, 06:15:51 pm »
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.

Offline Quik

  • Webmaster Guy
  • x86
  • Hero Member
  • *****
  • Posts: 3262
  • \x51 \x75 \x69 \x6B \x5B \x78 \x38 \x36 \x5D
    • View Profile
Re: [JAVA] Calculate Pi!
« Reply #14 on: November 09, 2005, 06:32:22 pm »
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