By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,219 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,219 IT Pros & Developers. It's quick & easy.

Finding minimum normalized positive number

P: 16
Hello,
I was asked to write a C program to find minimum normalized positive number that can be represented in my computer. I know that the value is 2.2250738585072014e-308.
I wrote the program to find the machine precision. Now i need to make some parameter changes to this program to find the min. number given above.
do
{
Epsilon = Epsilon/2.0 ; //Variable value is halved until the smallest
//value of 'e' is found while meeting the
//required condition
}
while ((float)((Epsilon+1.0))>1.0);

Epsilon = 2*Epsilon;

this gave me the machine precision. Any help would be appreciated.
thanks in advance.
Jan 21 '08 #1
Share this Question
Share on Google+
1 Reply


P: 5
Expand|Select|Wrap|Line Numbers
  1. double Epsilon;
  2. double store;
  3.  
  4. int main(int argc, char *argv[]) {
  5.     Epsilon = 1;
  6.     do {
  7.         Epsilon /= 2; //Variable value is halved until the smallest
  8.         //value of 'e' is found while meeting the
  9.         //required condition
  10.         store = Epsilon/2;
  11.     } while (store != 0);//If the smallest, then Epsilon/2 == 0 as Epsilon/2 approches 0.
  12.  
  13.     cout << "The smallest normalized number is: " << Epsilon << endl;
  14.  
  15.     system("PAUSE");
  16.     return EXIT_SUCCESS;
  17. }
  18.  
As suggested in the reply to your topic at 'http://www.physicsforums.com/showthread.php?t=210044', you must cast Epsilon as a double rather than single -floating point number. This is because doubles can represent numbers smaller than floating-point numbers (see wikipedia, I say =D).

Epsilon approaches 0 when repeatedly divided, and indeed meets 0 at the lowest normalized number. The variable "store" is used to identify where this lowest point occurs without changing the value of Epsilon to 0. Interestingly, my computer produced a result ~ 4.94066 e-324 (or something like that), which implies either your produced limit is wrong, or I have incorrectly coded the solution, because a limit is a limit is a limit. I can't speculate as to why this might occur.
Feb 26 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.