Page 1 of 4

Anyone know C++ ? (NLC)

Posted: Mon Jan 28, 2008 3:44 pm
by Tom
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

Posted: Mon Jan 28, 2008 4:15 pm
by steve_weegie
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

Posted: Mon Jan 28, 2008 6:15 pm
by Rag_It
Tom, is that you speaking?!!!!!!!

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

Posted: Mon Jan 28, 2008 7:20 pm
by The_Rossatron
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?

Posted: Mon Jan 28, 2008 7:30 pm
by robin
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

Posted: Mon Jan 28, 2008 7:32 pm
by robin
BTW, if you use radians for all your geometry you can forget about the actual value of PI ;-)

Cheers,
Robin

Posted: Mon Jan 28, 2008 8:05 pm
by Sanjøy
I could tell you a joke about Pi but its irrational.

Posted: Mon Jan 28, 2008 8:56 pm
by steve_weegie
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 ;)

Posted: Mon Jan 28, 2008 9:01 pm
by kenny
I thought Rossybee ate all the pies? :P






Oh hey, taxi for me :arrow:

Posted: Mon Jan 28, 2008 9:43 pm
by ExigeKen
kenny wrote:I thought Rossybee ate all the pies? :P






Oh hey, taxi for me :arrow:
<BG>

Posted: Tue Jan 29, 2008 11:08 am
by rossybee
Why am I strangely drawn to this thread?

Posted: Tue Jan 29, 2008 11:09 am
by rossybee
Oh yes :wink:

Image

Posted: Wed Jan 30, 2008 12:18 am
by campbell
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...

Posted: Wed Jan 30, 2008 10:21 am
by GregR
rossybee wrote:Oh yes :wink:

Image
:ROFL

Posted: Wed Jan 30, 2008 11:44 am
by Tom
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