all repos — min @ ce1df877b06a6d85b44463b1470e2e6d0e12efc0

A small but practical concatenative programming language.

added `med` function in Num module
drkameleon yaniszaf@gmail.com
Fri, 22 Jan 2021 07:03:36 +0100
commit

ce1df877b06a6d85b44463b1470e2e6d0e12efc0

parent

b2e6078d7421f7512f0fb026b8cd6e999b8cc111

1 files changed, 19 insertions(+), 0 deletions(-)

jump to
M minpkg/lib/min_num.nimminpkg/lib/min_num.nim

@@ -163,5 +163,24 @@ c = c + n.intVal.float

c = c / len(s.qVal).float i.push c.newVal + + def.symbol("med") do (i: In): + var s: MinValue + i.reqQuotationOfNumbers s + let first = s.qVal[(s.qVal.len-1) div 2] + let second = s.qVal[((s.qVal.len-1) div 2)+1] + if s.qVal.len mod 2 == 1: + i.push first + else: + if first.isFloat: + if second.isFloat: + i.push ((first.floatVal+second.floatVal)/2).newVal + else: + i.push ((first.floatVal+second.intVal.float)/2).newVal + else: + if second.isFloat: + i.push ((first.intVal.float+second.floatVal)/2).newVal + else: + i.push ((first.intVal+second.intVal).float/2).newVal def.finalize("num")