On 2020-06-24 20:41, 'Bo Jacoby' via Programming wrote:
Is
_0.5+0.5+4r5
0.8
the smarter way to convert 4r5 into 0.8 ?
here are some options sorted by speed in j902, though
with a narrow benchmark:
ops =: }: LF splitstring 0 : 0
_0.5+0.5+4r5
+/ _0.5 0.5 , 4r5
x:inv 4r5
_1 x: 4r5
]&.(+&0.5) 4r5
)
(". each ops) , ops ,: times=: 30&timex each ops
+------------+-----------------+----------+---------+--------------+
|0.8 |0.8 |0.8 |0.8 |0.8 |
+------------+-----------------+----------+---------+--------------+
|_0.5+0.5+4r5|+/ _0.5 0.5 , 4r5|x:inv 4r5 |_1 x: 4r5|]&.(+&0.5) 4r5|
+------------+-----------------+----------+---------+--------------+
|6.63333e_6 |4.86667e_6 |1.23333e_6|6e_7 |1.53333e_6 |
+------------+-----------------+----------+---------+--------------+
> ops {~ /: times
_1 x: 4r5
x:inv 4r5
]&.(+&0.5) 4r5
+/ _0.5 0.5 , 4r5
_0.5+0.5+4r5
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm