Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to calculate a cubic root in VFP ? 3

Status
Not open for further replies.

german12

Programmer
Nov 12, 2001
563
DE
I look for a function to get e.g. 3 (which is the 3rd. root) from 27

How can I do it programming in VFP?

(btw. It would be no problem with a pocket-calculator, but that is not asked).
Square root is also no problem as there is the built-in function SQRT in VFP available.

Thanks in advance.
Klaus



Peace worldwide - it starts here...
 
I would do this

Code:
FUNCTION CUBEROOT
  PARAMETERS M.MYNUM
  PRIVATE M.MYNUM
  RETURN(M.MYNUM ^ (1/3))



Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Griff said:
RETURN(M.MYNUM ^ (1/3))

Thanks, Griff. Forgot about that one. Surely, it can be used in an application in many ways as I'm sure you know.

Steve
 
I would also like to thank you very much, Griff.
I had forgotten what my teacher said 60 years ago, namely:
The extraction of roots is only the reverse of exponentiation.

Regards from Germany
Klaus


Peace worldwide - it starts here...
 
Hi Mike Yearwood,

Sorry, but I had not yet tested your contribution, when I answered Griff here.
However now I just have done it.

I agree with your recommendation - thank you very much.

I think, the cuberoot.prg is ideal when it is called with a second parameter like this:

*!* *Cuberoot.prg

*!* *This program calculates all roots
*!* m.mynum = radicand
*!* n = root value eg. 2 = square-root, 3 = cubic-root 4 = 4th. root etc.
*!* Example call: Cuberoot(81,4) results in 4th. root of 81 = 3

LPARAMETERS m.mynum,n
RETURN(m.mynum^(1/n))


Regards
Klaus


Peace worldwide - it starts here...
 
n=0

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
thank you - I had to be more specific
Unclear program names and divisions by zero as well as ambiguous variable names are more terrible than being beaten up by the wife.


Klaus[rednose]


Peace worldwide - it starts here...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top