Page 1 of 1

avoiding roundoff

Posted: Sat May 30, 2009 2:43 am
by ashutosh
In my NMODL code
P_v-1 evaluates to -3.68653e-06
exp(-((t-tsyn)/tau_VDD)) evaluates to 6.14421e-06
((P_v-1) * exp(-((t-tsyn)/tau_VDD))) evaluates to -2.26508e-11
But 1 + ((P_v-1) * exp(-((t-tsyn)/tau_VDD))) evaluates to 1.
Is there some way to avoid this roundoff?

Re: avoiding roundoff

Posted: Sat May 30, 2009 10:56 am
by hines
How do you know it evaluated to 1? Did you print in %-20g format or (if you put it in a variable x), printed x-1?

Re: avoiding roundoff

Posted: Sun May 31, 2009 7:31 pm
by ashutosh
I printed it in the %-20g format. Printing x-1 gives me the right answer (-2.26508e-11). Printing x*0.005 in %-20g gives me 0.005.

Re: avoiding roundoff

Posted: Mon Jun 01, 2009 6:51 am
by hines
Sorry, my typo. I should have said "%.20g"

Re: avoiding roundoff

Posted: Mon Jun 01, 2009 8:26 pm
by ashutosh
Thank you very much. Printing it out as %.20g gives me the right answer. I now understand that its got to do with the way %g is used.