Re: How to square root in 4gl
Posted in 1997
catalin_dumitrache@exe.com.au wrote: > > Is there a way to find the square root in 4gl ? > I do not want to call a C function. > > Thanks > Catalin Dumitrache (EXE Technologies - Melbourne). =20 The following algorithm will work for numbers that have a 'nice' root, like 64! But it'll need rounding logic inserted before the comparison 'if root = old_root', because it will 'toggle' between two values differing by 1 in the last d.p., virtually regardless of how u define 'root' and 'old_root'. I've given up and resorted to 'C' when I've needed to extract a root! Good luck! function root(square) define square integer, root decimal(16,8), old_root decimal(16,8) let root = square / 2 while true display root let old_root = root let root = square / root if root = old_root then exit while end if let root = (root + old_root) / 2 end while return root end function -- Phil Rule