Hi.
Continuing with my tutorial, here is an entry I have added recently. I
hope it is not controversial. If you see any errors/ambiguities/etc please
just answer in this thread.
Thanks in advance for your help.
----------------------------------------------------------------------
The machine epsilon
The machine epsilon is the smallest number that changes the result of an
addition operation at the point where the representation of the numbers
is the densest. In IEEE754 representation this number has an exponent
value of the bias, and a fraction of 1. If you add a number smaller than
this to 1.0, the result will be 1.0. For the different representations
we have in the standard header <float.h>:
#define FLT_EPSILON 1.19209290e-07F // float
#define DBL_EPSILON 2.2204460492503 131e-16 // double
#define LDBL_EPSILON 1.0842021724855 04434007452e-19L //long double
// qfloat epsilon truncated so that it fits in this page...
#define QFLT_EPSILON 1.0900377190486 584296973751359 3110651 ... E-106
This defines are part of the C99 ANSI standard. For the standard types
(float, double and long double) this defines should always exist in
other compilers.
Here is a program that will find out the machine epsilon for a given
floating point representation.
#include <stdio.h>
int main(void)
{
double float_radix=2.0 ;
double inverse_radix = 1.0/float_radix;
double machine_precisi on = 1.0;
double temp = 1.0 + machine_precisi on;
while (temp != 1.0) {
machine_precisi on *= inverse_radix;
temp = 1.0 + machine_precisi on ;
printf("%.17g\n ",machine_preci sion);
}
return 0;
}
Continuing with my tutorial, here is an entry I have added recently. I
hope it is not controversial. If you see any errors/ambiguities/etc please
just answer in this thread.
Thanks in advance for your help.
----------------------------------------------------------------------
The machine epsilon
The machine epsilon is the smallest number that changes the result of an
addition operation at the point where the representation of the numbers
is the densest. In IEEE754 representation this number has an exponent
value of the bias, and a fraction of 1. If you add a number smaller than
this to 1.0, the result will be 1.0. For the different representations
we have in the standard header <float.h>:
#define FLT_EPSILON 1.19209290e-07F // float
#define DBL_EPSILON 2.2204460492503 131e-16 // double
#define LDBL_EPSILON 1.0842021724855 04434007452e-19L //long double
// qfloat epsilon truncated so that it fits in this page...
#define QFLT_EPSILON 1.0900377190486 584296973751359 3110651 ... E-106
This defines are part of the C99 ANSI standard. For the standard types
(float, double and long double) this defines should always exist in
other compilers.
Here is a program that will find out the machine epsilon for a given
floating point representation.
#include <stdio.h>
int main(void)
{
double float_radix=2.0 ;
double inverse_radix = 1.0/float_radix;
double machine_precisi on = 1.0;
double temp = 1.0 + machine_precisi on;
while (temp != 1.0) {
machine_precisi on *= inverse_radix;
temp = 1.0 + machine_precisi on ;
printf("%.17g\n ",machine_preci sion);
}
return 0;
}
Comment