Page 1 of 1

floor and ceil function

Posted: Wed Oct 23, 2013 3:21 am
by oren
Hello,
Is there a floor and ceil function in neuron?
I know that I can use int for floor function , but what about ceil? ( I can not do floor + 1 because sometimes I can get a int number)

I notice that in NMOD
http://www.neuron.yale.edu/neuron/stati ... lfunc.html
there are ceil and floor functions.

Thank You.

Re: floor and ceil function

Posted: Wed Oct 23, 2013 12:35 pm
by ted
It's NMODL (NEURON Model Description Language).

A mod file with SUFFIX nothing can be used to add arbitrary functions written in NMODL or C to hoc. Create a mod file called dummy.mod and put the following statements in it:

Code: Select all

: dummy.mod
: Makes functions written in C or NMODL available to hoc
NEURON {
	SUFFIX nothing
}
: call it gceil to avoid naming conflicts
FUNCTION gceil(z) {
   gceil = ceil(z)
}
FUNCTION gfloor(z) {
   gfloor = floor(z)
}
Put it in the directory that contains your hoc code that requires floor or ceil, then run mknrndll or nrnivmodl. hoc will now have two new functions called gfloor and gceil that allow execution of this statement

Code: Select all

print "floor(PI) = ", gfloor(PI), "    ceil(PI) = ", gceil(PI)
to produce the following result:

Code: Select all

floor(PI) = 3     ceil(PI) = 4

Re: floor and ceil function

Posted: Thu Oct 24, 2013 9:07 am
by oren
Ted,
Thank you