-
Five easy pieces #2: getting around
From a recent question on Stack Overflow:
q)q:9.638554216867471 q)rnd[q;2;`up] / round up "9.64" q)rnd[q;2;`dn] / round down "9.63" q)rnd[q;2;`nr] / round to nearest "9.64" q)rnd[q+0 1 2;3;`up] "9.639" "10.639" "11.639"
Write
rnd
without any control words (do
,while
,if
, Cond$
). For bonus points extend to multiple modes (3rd argument):q)rnd[q+0 1 2;3;`up`dn] "9.639" "10.639" "11.639" "9.638" "10.638" "11.638"
Log in to reply.