PDA

View Full Version : Finding Fractional calculator



harryweb
- 13th December 2017, 22:52
Hi,

I've got a problem to find a way to create numerator and denominator for my calculation
Here is the formula: (used by analog devices ADF435x software (windows))
(INT+(FRAC/MOD)x(PFD/DIV))=RF

I just calculate some variables but cannot find FRAC variable (see picture)8539

I found all my variables are OK but I found 6,25 for MOD !!! WOW not 125 as Analog give me
so.... I found some C code to calculate the FRAC and MOD, but how to calculate these numbers with PBP ? (FRAC & MOD knowing I found 6.25 for MOD)
8540
seems they use C code with integer (math.round) ?

thanks for help !
regards

mpgmike
- 15th December 2017, 00:52
First, I know with SELECT CASE you want to start with your smallest possibility with "IF VAR < VAL THEN" type statements. You have largest listed first. If your code executes in order, then you will be changing your OutputDividerBox.Text value with each successive IF... clause.

Secondly, to work with decimals in PBP, multiply it by 10 or 100 up front, then divide the result back down by the same 10 or 100 at the end. Example:

7.5 X 22 = (75 X 22) / 10

That would allow you to work with decimals in PBP. Of course, you need a filter to tell you if that's needed (perhaps IF MOD != 0 THEN). I'm sure there are other aspect that need attention, but these were the obvious things I could contribute towards.

harryweb
- 15th December 2017, 18:49
Thank you, that's what I've done now... Many select case and if then else... seem's to work now but not tried everything... looking for bugs.... Running...
Regards

Art
- 16th December 2017, 09:38
math.round is only used there because the result will be copied to an integer.
The calculation is done with floats though (at least I assume because you didn’t show variable declarations).
If it weren’t for that, the result would always be rounded down. You can simulate that by rounding up if the decimal part is greater than 0.5.