Anyone know C++ ? (NLC)

Anything goes in here.....
User avatar
Tom
Posts: 3220
Joined: Mon Mar 06, 2006 5:50 pm
Location: UK

Anyone know C++ ? (NLC)

Post by Tom » Mon Jan 28, 2008 3:44 pm

I need to write a program that can provide a solution for pi, and then compare this solution to the preprogrammed value for pi and show the difference between the two.... :shock: :? :?

Anyone help with this as it's pickling my brain trying to work it out.....??

TIA...:thumbsup
1995 Volvo 940SE Estate

User avatar
steve_weegie
Posts: 3248
Joined: Tue Jun 28, 2005 12:40 am
Location: Nessieland

Post by steve_weegie » Mon Jan 28, 2008 4:15 pm

If at first you dont succeed, plagiarise? ;)

http://www.shedai.net/c/new/#section1group2

How are you expected to calculate pi? there's a few different methods and will all yield different results depending on the number of iterations you compute

Cheers,

Steve
Arriving broadside, in a cloud of smoke......

User avatar
Rag_It
Posts: 4286
Joined: Fri Mar 18, 2005 2:43 pm
Location: Perth/Fife

Post by Rag_It » Mon Jan 28, 2008 6:15 pm

Tom, is that you speaking?!!!!!!!

I think Robin has logged in under Tom's user name!

User avatar
The_Rossatron
Posts: 1844
Joined: Sun Jul 10, 2005 8:14 pm
Location: Edinburgh, Scotland
Contact:

Post by The_Rossatron » Mon Jan 28, 2008 7:20 pm

I'm no expert but give us a shout if you get stuck!

Are you supposed to try a number of rational approximations and then work out which is best?
"There is no emoticon for what I'm feeling right now."
Ferrari F355, Fiat Panda 100HP, Rover Mini Cooper

http://www.allflashnocash.com

User avatar
robin
Jedi Master
Posts: 10544
Joined: Mon Mar 27, 2006 1:39 pm

Post by robin » Mon Jan 28, 2008 7:30 pm

I am assuming you have the algorithm and you just want to implement it?

You really just need C, not C++ (i.e. you can stick to understanding the basic control flow and statements; you don't really need to understand the class/object system that C++ layers on top of C).

Numerical methods is a bit of a specialist subject in programming circles - in particular the standard implementation of single and double precision floating point can be insufficiently accurate around the boundary condition to yield consistent results.

For very long number computations you can use an arbitrary precision "big number" library.

Soooo, how accurately do you want to know the answer? If you just want it to 10 or so decimal places, the standard double precision floating point type will be fine for all but the most bizarre algorithms for computing PI. For greater than 10 d.p. you should start thinking about using arbitrary length libraries. These are about 100 times slower than the CPU's built in floating point processor, but who cares in this case.

In the real world of real programs that do important things, almost nobody uses floating point arithmetic - it's just too woolly :-)

If you really want to learn, I would be happy to explain over a bottle of red wine and a laptop :-)

Cheers,
Robin
I is in your loomz nibblin ur wirez
#bemoretut

User avatar
robin
Jedi Master
Posts: 10544
Joined: Mon Mar 27, 2006 1:39 pm

Post by robin » Mon Jan 28, 2008 7:32 pm

BTW, if you use radians for all your geometry you can forget about the actual value of PI ;-)

Cheers,
Robin
I is in your loomz nibblin ur wirez
#bemoretut

User avatar
Sanjøy
Posts: 8828
Joined: Sun Oct 02, 2005 8:23 pm
Location: Edinburgh Hamptons

Post by Sanjøy » Mon Jan 28, 2008 8:05 pm

I could tell you a joke about Pi but its irrational.
W213 All Terrain

User avatar
steve_weegie
Posts: 3248
Joined: Tue Jun 28, 2005 12:40 am
Location: Nessieland

Post by steve_weegie » Mon Jan 28, 2008 8:56 pm

robin wrote:BTW, if you use radians for all your geometry you can forget about the actual value of PI ;-)

Cheers,
Robin
Indeed, possibly the only time half a pie = pi ;)
Arriving broadside, in a cloud of smoke......

User avatar
kenny
Posts: 7666
Joined: Thu Mar 10, 2005 9:10 pm
Location: Bearsden

Post by kenny » Mon Jan 28, 2008 9:01 pm

I thought Rossybee ate all the pies? :P






Oh hey, taxi for me :arrow:

User avatar
ExigeKen
Posts: 6113
Joined: Mon Nov 28, 2005 7:11 pm
Location: Stewarton

Post by ExigeKen » Mon Jan 28, 2008 9:43 pm

kenny wrote:I thought Rossybee ate all the pies? :P






Oh hey, taxi for me :arrow:
<BG>
2004 Exige S2 1.8 - Ardent Red

2003 RAV4 vvti 2.0 - Baleric Blue shiny version

Don't Fear The Reaper

Back on the road!

User avatar
rossybee
Posts: 11091
Joined: Tue Mar 15, 2005 9:13 pm
Location: Dundee

Post by rossybee » Tue Jan 29, 2008 11:08 am

Why am I strangely drawn to this thread?
Ross
---------
1972 Alfaholics Giulia Super
2000 Elise S1 Sport 160
2004 Bentley Conti GT
2017 Schkoda Yeti
2x Hairy GRs (not Toyota)

Now browsing the tech pages :mrgreen:

:cheers

User avatar
rossybee
Posts: 11091
Joined: Tue Mar 15, 2005 9:13 pm
Location: Dundee

Post by rossybee » Tue Jan 29, 2008 11:09 am

Oh yes :wink:

Image
Ross
---------
1972 Alfaholics Giulia Super
2000 Elise S1 Sport 160
2004 Bentley Conti GT
2017 Schkoda Yeti
2x Hairy GRs (not Toyota)

Now browsing the tech pages :mrgreen:

:cheers

User avatar
campbell
Posts: 17331
Joined: Sat Mar 25, 2006 12:42 pm
Location: West Lothian
Contact:

Post by campbell » Wed Jan 30, 2008 12:18 am

robin wrote:I am assuming you have the algorithm and you just want to implement it?

You really just need C, not C++ (i.e. you can stick to understanding the basic control flow and statements; you don't really need to understand the class/object system that C++ layers on top of C).

Numerical methods is a bit of a specialist subject in programming circles - in particular the standard implementation of single and double precision floating point can be insufficiently accurate around the boundary condition to yield consistent results.

For very long number computations you can use an arbitrary precision "big number" library.

Soooo, how accurately do you want to know the answer? If you just want it to 10 or so decimal places, the standard double precision floating point type will be fine for all but the most bizarre algorithms for computing PI. For greater than 10 d.p. you should start thinking about using arbitrary length libraries. These are about 100 times slower than the CPU's built in floating point processor, but who cares in this case.

In the real world of real programs that do important things, almost nobody uses floating point arithmetic - it's just too woolly :-)

If you really want to learn, I would be happy to explain over a bottle of red wine and a laptop :-)

Cheers,
Robin
This brings back some scary memories of all the things about maths and computers that I grew to detest!

I'd rather change a nappy, frankly !!

Edit: although the red wine and laptop bit sounds mildly appealling...
http://www.rathmhor.com | Coaching, training, consultancy

User avatar
GregR
Posts: 6933
Joined: Tue Oct 18, 2005 1:45 pm
Location: Edinburgh

Post by GregR » Wed Jan 30, 2008 10:21 am

rossybee wrote:Oh yes :wink:

Image
:ROFL
Ferrari 458
Porsche 993 C2
Disco V

User avatar
Tom
Posts: 3220
Joined: Mon Mar 06, 2006 5:50 pm
Location: UK

Post by Tom » Wed Jan 30, 2008 11:44 am

robin wrote:I am assuming you have the algorithm and you just want to implement it?

You really just need C, not C++ (i.e. you can stick to understanding the basic control flow and statements; you don't really need to understand the class/object system that C++ layers on top of C).

Numerical methods is a bit of a specialist subject in programming circles - in particular the standard implementation of single and double precision floating point can be insufficiently accurate around the boundary condition to yield consistent results.

For very long number computations you can use an arbitrary precision "big number" library.

Soooo, how accurately do you want to know the answer? If you just want it to 10 or so decimal places, the standard double precision floating point type will be fine for all but the most bizarre algorithms for computing PI. For greater than 10 d.p. you should start thinking about using arbitrary length libraries. These are about 100 times slower than the CPU's built in floating point processor, but who cares in this case.

In the real world of real programs that do important things, almost nobody uses floating point arithmetic - it's just too woolly :-)

If you really want to learn, I would be happy to explain over a bottle of red wine and a laptop :-)

Cheers,
Robin
Red wine and laptop does sound appealing. I'm struggling with this. Don't have any experience with programming and frankly don't know where to start. pm sent. :thumbsup
1995 Volvo 940SE Estate

Post Reply