From cfa352ccbebf9eae6ccfbe934f1691e2068563d2 Mon Sep 17 00:00:00 2001 From: hiiamboris Date: Fri, 2 Sep 2022 17:15:13 +0300 Subject: [PATCH 1/2] FEAT: clip function --- environment/functions.red | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/environment/functions.red b/environment/functions.red index 6e8257ae5c..73f17b8e90 100644 --- a/environment/functions.red +++ b/environment/functions.red @@ -1104,6 +1104,14 @@ average: func [ divide sum block to float! length? block ] +clip: func [ + "Return A if it's within [B,C] range, otherwise nearest to it range boundary" + a [scalar!] b [scalar!] c [scalar!] + return: [scalar!] +][ + min max a b max min a b c +] + last?: func [ "Returns TRUE if the series length is 1" series [series!] From 90e0f88c137fb40add9f1c62acbc7d5c51744012 Mon Sep 17 00:00:00 2001 From: hiiamboris Date: Fri, 2 Sep 2022 18:55:24 +0300 Subject: [PATCH 2/2] DOC: better docstring --- environment/functions.red | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment/functions.red b/environment/functions.red index 73f17b8e90..ba1dc17813 100644 --- a/environment/functions.red +++ b/environment/functions.red @@ -1105,7 +1105,7 @@ average: func [ ] clip: func [ - "Return A if it's within [B,C] range, otherwise nearest to it range boundary" + "Return A if it's within [B,C] range, otherwise the range boundary nearest to A" a [scalar!] b [scalar!] c [scalar!] return: [scalar!] ][