### Precision of t in fadvance

Posted:

**Wed Apr 18, 2012 8:38 pm**Hello, I'm using a sinusoidally varying netstim in my model and so I added code to fadvance() to update the interval of the netstim. I only want to update the interval every so often and so I added code to check the value of t before resetting the interval. However, the check doesn't work because calculations involving t seem to be less precise than I expected.

For example below, I checked t to print its value every 100 ms. The same code outside of fadvance for a loop variable (r) produces the expected result whether I use the mod operator (%) or explicitly calculate it myself. But in fadvance(), it's not as precise and so I run into trouble even if I increase float_epsilon.

This code:

produces this output:

And if I don't change float_epsilon, during fadvance() I only get:

I don't understand why the calculation is less reliable within fadvance()?

For example below, I checked t to print its value every 100 ms. The same code outside of fadvance for a loop variable (r) produces the expected result whether I use the mod operator (%) or explicitly calculate it myself. But in fadvance(), it's not as precise and so I run into trouble even if I increase float_epsilon.

This code:

Code: Select all

```
{load_file("nrngui.hoc")} // Standard definitions - NEURON library file
tstop = 1000
float_epsilon = 1e-5
print "Before run:"
for r=0, 999 {
if ((r - int(r/100)*100)==0) {print "calc r = ", r, " r%100 = ", r%100}
if (r%100 == 0) {print "% r = ", r}
}
print " "
print "During run:"
proc advance() {
if ((t - int(t/100)*100)==0) {print "calc t = ", t, " t%100 = ", t%100}
if (t%100 == 0) {print "% t = ", t}
fadvance()
}
run()
quit()
```

produces this output:

Code: Select all

```
Before run:
calc r = 0 r%100 = 0
% r = 0
calc r = 100 r%100 = 0
% r = 100
calc r = 200 r%100 = 0
% r = 200
calc r = 300 r%100 = 0
% r = 300
calc r = 400 r%100 = 0
% r = 400
calc r = 500 r%100 = 0
% r = 500
calc r = 600 r%100 = 0
% r = 600
calc r = 700 r%100 = 0
% r = 700
calc r = 800 r%100 = 0
% r = 800
calc r = 900 r%100 = 0
% r = 900
During run:
calc t = 0 t%100 = 0
% t = 0
calc t = 100 t%100 = 1.4168222e-11
% t = 100
calc t = 200 t%100 = 100
calc t = 300 t%100 = 100
calc t = 400 t%100 = 100
calc t = 500 t%100 = 100
calc t = 600 t%100 = 100
calc t = 700 t%100 = 3.5515768e-10
% t = 700
calc t = 800 t%100 = 7.1895556e-10
% t = 800
calc t = 900 t%100 = 1.0827534e-09
% t = 900
```

And if I don't change float_epsilon, during fadvance() I only get:

Code: Select all

```
During run:
calc t = 0 t%100 = 0
% t = 0
calc t = 600 t%100 = 100
```