approximate the value of PI

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: approximate the value of PI

 
0
  #11
Sep 4th, 2008
Declaring variables inside for loop initialization sections is indeed C99-only. I wouldn't do it if I were you.

Btw, what are the differences between float and double?
double just has more precision (usually). Oftentimes, a float is 4 bytes and a double is 8. There used to be a speed penalty for using floating-point numbers, which is why float exists, but there's not really any reason not to use double any more.

[edit]
  1. for (i = 0, sum = 0.0; i < n; ++i, sum += ((i % 2) * 2 - 1) * (1.0 / (1 + i * 2)));
*hides even further away* [/edit]
Last edited by dwks; Sep 4th, 2008 at 5:54 pm.
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,035
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: approximate the value of PI

 
0
  #12
Sep 4th, 2008
>*hides even further away*
There's nothing hidden there. Obfuscated, perhaps. Quite often, hard to read code, it is associated with cleverness, when the opposite it is true.

An abstraction layer is the only place where "hiding" some "goring details" of a program should be used. And interesting enough, it is for the sake of simplicity.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC