Using R programming, write a program to compute the Machine epsilon in single precision(32 bits) and double precision(64 bits). Follow programming guidelines.
#include <stdio.h>
#define N 100000
#define TYPE float
int main(void)
{ TYPE max = 1.0, min = 0.0, test;
int i;
for (i = 0; i < N; i++)
{ TYPE one_plus_test;
test = (max + min) / ((TYPE)2.0);
one_plus_test = ((TYPE)1.0) + test;
if (one_plus_test == ((TYPE)1.0))
{
min = test;
} else
{
max = test;
}
}
printf("The epsilon machine is %.50lf\n", max);
return 0;
}
typedef union {
long long i64;
double d64;
} dbl_64;
double machine_eps (double value)
{
dbl_64 s;
s.d64 = value; s.i64++;
return s.d64 - value;
}
Get Answers For Free
Most questions answered within 1 hours.