Q
questions?
I have a problem involves under flow/over flow.
###################################################
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
double rate;
double t;
double u;
int main(){
int i;
double diff;
double rtime;;
t=0.0047590000;
diff=t/10;
rtime=0;
rate=0.00000000000001;
for(i=0;i<10;i++){
printf("real time is:%.50lf and current time:%.50lf\n",t,rtime);
u=(1-exp(-1*rate*rtime))/(1-exp(-1*rate*t));
printf("for the %d th time, u=%.50lf\n",i,u);
rtime=rtime+diff;
}
return 0;
}
************************
The idea is that,u is a monotonically increaseing function of rtime,
as rtime increase from 0 to t, u increase from 0 to 1.
But appearantly it runs into underflow/overflow.
how can I deal with this problem nicely? Roughly, how precise is C
double?
Thanks for comments
###################################################
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
double rate;
double t;
double u;
int main(){
int i;
double diff;
double rtime;;
t=0.0047590000;
diff=t/10;
rtime=0;
rate=0.00000000000001;
for(i=0;i<10;i++){
printf("real time is:%.50lf and current time:%.50lf\n",t,rtime);
u=(1-exp(-1*rate*rtime))/(1-exp(-1*rate*t));
printf("for the %d th time, u=%.50lf\n",i,u);
rtime=rtime+diff;
}
return 0;
}
************************
The idea is that,u is a monotonically increaseing function of rtime,
as rtime increase from 0 to t, u increase from 0 to 1.
But appearantly it runs into underflow/overflow.
how can I deal with this problem nicely? Roughly, how precise is C
double?
Thanks for comments