floor and ceil function

The basics of how to develop, test, and use models.
Post Reply
oren
Posts: 55
Joined: Fri Mar 22, 2013 1:03 am

floor and ceil function

Post 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.
ted
Site Admin
Posts: 5784
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: floor and ceil function

Post 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
oren
Posts: 55
Joined: Fri Mar 22, 2013 1:03 am

Re: floor and ceil function

Post by oren »

Ted,
Thank you
Post Reply