Example of cdef function is below.

cdef=a,c,/,b,c,/,b,c,/,*,-,SQRT

## How to convert CDEF function to formula.

**Moderators:** Moderators, Developers

- TheWitness
- Developer
**Posts:**14855**Joined:**Tue May 14, 2002 5:08 pm**Location:**MI, USA-
**Contact:**

### Re: How to convert CDEF function to formula.

First of all, you have to be old enough to know RPN. If you are an engineer, and you used either an HP 11-C or HP 15-C calculator, then you would not be asking that question. Think of an RPN as a first in last out queue. So, to do math, you stack the queue, and then unstack it from the left. So, one good example is:

a,b,*

This would equate to:

result = a * b;

The result is thrown back on the stack. How about this one:

a,b,*,20,/

This would equate to:

result = (a * b ) /20

When there are no more expressions to process, the stack size MUST be 1, if it's one, or if during some calculation there are insufficient elements on the stack, you would get an error. In your case:

a,c,/,b,c,/,b,c,/,*,-,SQRT

result = ( ( ( ( ( a / c ) / b ) / c ) * b ) - c) ^^ 0.5

Which if you ask me, is horribly written. Better to do:

a,c,/,b,/,c,/,b,*,c,-,SQRT

That way you are always dealing with no more than 2 elements on the stack. Easier for old guys like me to read it that way.

Good luck.

a,b,*

This would equate to:

result = a * b;

The result is thrown back on the stack. How about this one:

a,b,*,20,/

This would equate to:

result = (a * b ) /20

When there are no more expressions to process, the stack size MUST be 1, if it's one, or if during some calculation there are insufficient elements on the stack, you would get an error. In your case:

a,c,/,b,c,/,b,c,/,*,-,SQRT

result = ( ( ( ( ( a / c ) / b ) / c ) * b ) - c) ^^ 0.5

Which if you ask me, is horribly written. Better to do:

a,c,/,b,/,c,/,b,*,c,-,SQRT

That way you are always dealing with no more than 2 elements on the stack. Easier for old guys like me to read it that way.

Good luck.

True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.

_________________

Official Cacti Documentation

GitHub Repository with Supported Plugins

Central Plugin Repository

Central Templates Repository

I'm still out there people. Getting excited for Cacti 1.2. I think it will be a great release.

Life is an adventure, let yours begin with Cacti!

Author of MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.

_________________

Official Cacti Documentation

GitHub Repository with Supported Plugins

Central Plugin Repository

Central Templates Repository

I'm still out there people. Getting excited for Cacti 1.2. I think it will be a great release.