min-max limiter

For the Compleat Fan

min-max limiter

Postby hds1 » Mon Apr 25, 2016 7:13 am

Hello,

i couldn't find a function in newlisp to limit a value between upper and lower limits.
i.e. something like this:

"return x < some_minimum ? some_minimum : x > some_maximum ? : some_maximum : x;"

Reason is that i'am working a lot with sin, cos and the brothers and i often need to limit my floats for example to precisly -1 or 1.

Thanks and Regards
Heiko
hds1
 
Posts: 27
Joined: Thu Mar 20, 2014 5:02 pm

Re: min-max limiter

Postby TedWalther » Mon Apr 25, 2016 8:00 am

Code: Select all
(cond ((> x some_max) x_max) ((< x some_min) x_min) (true x))


If you use this idiom enough, you may want to wrap it into a function, call it "bandpass".

Code: Select all
(define (bandpass x xmin xmax)
    (cond ((> x xmax) xmax) ((< x xmin) xmin) (true x)))
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.
TedWalther
 
Posts: 602
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC

Re: min-max limiter

Postby hds1 » Mon Apr 25, 2016 8:21 am

sweet.

Thanks a lot for pointing this one out.
hds1
 
Posts: 27
Joined: Thu Mar 20, 2014 5:02 pm


Return to Anything else we might add?

Who is online

Users browsing this forum: No registered users and 1 guest

cron