RosettaCodeData/Task/Nth-root/Bracmat/nth-root.bracmat

30 lines
830 B
Plaintext

( ( root
= n a d x0 x1 d2 rnd 10-d
. ( rnd { For 'rounding' rational numbers = keep number of digits within bounds. }
= N r
. !arg:(?N.?r)
& div$(!N*!r+1/2.1)*!r^-1
)
& !arg:(?n,?a,?d)
& !a*!n^-1:?x0
& 10^(-1*!d):?10-d
& whl
' ( ( rnd$(((!n+-1)*!x0+!a*!x0^(1+-1*!n))*!n^-1.10^!d)
. !x0
)
: (?x0.?x1)
& (!x0+-1*!x1)^2:~<!10-d { Exit loop when required precision is reached. }
)
& flt$(!x0,!d) { Convert rational number to floating point representation. }
)
& ( show
= N A precision
. !arg:(?N,?A,?precision)
& out$(str$(!A "^(" !N^-1 ")=" root$(!N,!A,!precision)))
)
& show$(10,1024,20)
& show$(3,27,20)
& show$(2,2,100)
& show$(125,5642,20)
)