Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Interesting Challenge
Message
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00259328
Message ID:
00259397
Views:
19
Sorry. This only works with numbers >= 1

Here is some documentation:
pOrig = number for which you want the square root
pLower = the best lower bound to the square root
pUpper = the best upper bound to the square root

In the example below I assure that for any number >= 1 that the square root is between 1 and the number. Pretty crappy guess but the only interval that you can be sure of.

>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