Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Interesting Challenge
Message
 
 
To
30/08/1999 15:06:10
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00259328
Message ID:
00259394
Views:
14
If I didn't have access to my numerical analysis books and no connection to the internet, and a no pressure to optimize the function, it would look something like this.
nAnswer = sr(100,1,100)
? "THE ANSWER:", nAnswer

FUNCTION sr(pOrig,pLower,pUpper)
* attempt to determine the square root by dividing the interval
? pOrig, pLower, pUpper
WAIT
nMiddle = ((pUpper - pLower) / 2) + pLower

DO CASE
	CASE pOrig = nMiddle*nMiddle 
		RETURN nMiddle
	CASE pOrig > nMiddle*nMiddle
		RETURN sr(pOrig,nMiddle,pUpper)
	CASE pOrig < nMiddle*nMiddle
		RETURN sr(pOrig,pLower,nMiddle)
	OTHERWISE
		? "ERROR: an impossible result!"
		RETURN 0
ENDCASE
RETURN
>Write a function to calculate the square root of a number to a given number of decimal places. (Yes. I know, VFP has the SQRT function, but what would you do without it?)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform