943,584 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 3208
  • C RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Sep 4th, 2008
0

Re: approximate the value of PI

Declaring variables inside for loop initialization sections is indeed C99-only. I wouldn't do it if I were you.

Quote ...
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.
Reputation Points: 185
Solved Threads: 28
Posting Whiz in Training
dwks is offline Offline
269 posts
since Nov 2005
Sep 4th, 2008
0

Re: approximate the value of PI

>*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.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Having problems in using linked lists
Next Thread in C Forum Timeline: Why address Gap in Char?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC