In J, how can I find the extended precision integer floor of a square root -


i understand when take square root (%:) of number not result in integer, answer float. i'm looking find floor (<.) of square root in order integer result. j have built-in way achieve this? need resort loop find answer?

tossing in few extended precision (x:) requests doesn't it.

   rootanddiffa =: 3 : '(y - root ^ 2);(root =. <. %: y)'    rootanddiffa 24 ┌─┬─┐ │8│4│ └─┴─┘    rootanddiffa 26 ┌─┬─┐ │1│5│ └─┴─┘    rootanddiffa 99999999999999x ┌──┬────────┐ │_1│10000000│ └──┴────────┘    rootanddiffb =: 3 : '(y - root ^ 2);(root =. x: <. x: %: y)'    rootanddiffb 24 ┌─┬─┐ │8│4│ └─┴─┘    rootanddiffb 99999999999999x ┌──┬────────┐ │_1│10000000│ └──┴────────┘ 

from "j c programmers: 32":

the key idiom <.@v (or >.@v), v verb want apply. when code <.@v, interpreter knows interested in integer part of result, , if operand exact-precision, interpreter evaluate integer part of result exactly.

so, have use <.@%::

rt2 =: 3 :'(y - root ^ 2);(root =. <.@%: y)' rt2 99999999999999x ┌────────┬───────┐ │19999998│9999999│ └────────┴───────┘ 

see dictionary - extended , rational arithmetic

<.@f , >.@f produce extended integer results when applied extended integer arguments.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -