command line for "mod" or "rem"?

Particularly useful chunks of hoc and/or NMODL code. May be pedestrian or stunningly brilliant, may make you gasp or bring tears to your eyes, but always makes you think "I wish I had written that; I'm sure going to steal it."
Post Reply
pjthomas
Posts: 6
Joined: Fri Jun 05, 2009 9:00 am

command line for "mod" or "rem"?

Post by pjthomas »

This post may win the "most pedestrian" award. I'd like to add a curve to a plot of the form f(mod(t,period)) and I don't see a command equivalent to "mod" (or "rem") in the programmer's reference. The following works as a substitute:

atan2(sin(t*2*PI/period),cos(t*2*PI/period))

but that is a lot to type into the "plot what" dialog window, when all I really want is "mod(t,period)". Suggestions?
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: command line for "mod" or "rem"?

Post by ted »

You're looking for %.
for i=0,10 print i%3
It's in the NEURON Book, but not in Kernighan & Pike's original definition of hoc in "The UNIX Programming Environment," so you'll get a pass from them.
pjthomas
Posts: 6
Joined: Fri Jun 05, 2009 9:00 am

Re: command line for "mod" or "rem"?

Post by pjthomas »

Many thanks, Ted! Sorry I didn't know that one -- it doesn't appear under the general "math" entry
http://www.neuron.yale.edu/neuron/stati ... .html#math
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: command line for "mod" or "rem"?

Post by ted »

I don't think any of the operators is listed in the Programmer's Reference--a stunning omission. We're doing a big rewrite of the Programmer's Reference, and this is one of the items on our to-do list.
Post Reply