/* By David Isaacson, 2003
* Released into the Public Domain
*
* epsilon.c
* The puropse of this program is to find the machine epsilon of this computer, that is,
* the smallest number E such that 1+E != 1 . (using single precision only)
*/
#include
int main()
{
float max = 1; //This is the lowest value that we know works.
//(By works, I mean that 1+E!=1)
float min = 0; //This is the highest value that we know doesn't work.
float test = 0; //This is our test varible. Duh.
do
{
test=(max+min)/2; //Set test to avg of max & min
if((1+test)!=1) //If we're too high, set the max to test and try again
max=test; //(We're trying to center in on the right value)
if((1+test)==1) //If we're too low, set the min to test and try again
min=test;
}while(test!=((max+min)/2)); //If max and min are not changing, they must be so
//close that there is no number in between that the
//computer can represent.
//So, either test=min= the highest value that
//doesn't work, or test=max= the lowest
//value that does work. Either way we're done.
printf("The epsilon for your machine is %e.\n",max);
//max is the lowest value that works.
return 0;
}
/* When running this program on my computer (Power Mac G4 533 MHz running Mac OS X 10.2), I
* recieved the result:
*
* The epsilon for your machine is 5.960465e-08.
*/