avoiding roundoff

NMODL and the Channel Builder.
Post Reply
ashutosh

avoiding roundoff

Post 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?
hines
Site Admin
Posts: 1710
Joined: Wed May 18, 2005 3:32 pm

Re: avoiding roundoff

Post 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?
ashutosh

Re: avoiding roundoff

Post 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.
hines
Site Admin
Posts: 1710
Joined: Wed May 18, 2005 3:32 pm

Re: avoiding roundoff

Post by hines »

Sorry, my typo. I should have said "%.20g"
ashutosh

Re: avoiding roundoff

Post 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.
Post Reply