Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Interesting Challenge
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00259328
Message ID:
00259397
Vues:
20
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?)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform