(10-14-2021 06:02 PM)Valentin Albillo Wrote: Look, Dave, what you've given above is not an example of actual non-contrived code using the DSNZ function, you've just given an Owner's Handbook-style code bit picturing what it does.
I don't mean to play games with you, what I want is some sample code which does something non-contrived that shows the alleged "usefulness" and "cleanness" afforded by this DSNZ instruction, let's say similarly to how a simple implementation of the factorial function does clearly demonstrate the usefulness of the regular DSZ instruction.
Can you provide it, yes or no ?
Thanks and regards.
V.
Have you never needed to write a "for" or "while" loop where you break in the middle of the loop body instead of at the physical end of it? That's where this sort of thing would come in handy now and then.
For the sake of example, here's a cumulative (lower tail) binomial distribution program for 15C. Store n in R1, P in R2, and X in R3, then GSB A.
Code:
LBL A
0
STO 4
STO 5
RCL 2
1
STO+ 3
RCL- 2
/
STO 6 // P/(1-P)
LST x
RCL 1
y^x // B(n, 0, P) = (1-P)^n
LBL 1
STO+ 5 // Add to cumulative probability
/**** LOOP EXIT TEST ****/
DSE 3 // Decrement loop counter
GTO 0
GTO 9 // Break from loop if counter was zero
LBL 0
/**** END OF LOOP EXIT ****/
RCL 1 // Calculate B(n, r+1, P)...
RCL 4 // B(n, r+1, P) =
- // B(n, r, P) * (n-r)/(r+1) * P/(1-P)
RCL 4
1
+
STO 4
/
RCL* 6
* // Done calculating next term
GTO 1 // Do another loop
LBL 9
RCL 5 // Display total
RTN
With a hypothetical DSNE (decrement and skip if
not less than or equal), the loop exit condition could be shortened by removing the extra GTO and LBL:
Code:
LBL A
0
STO 4
STO 5
RCL 2
1
STO+ 3
RCL- 2
/
STO 6 // P/(1-P)
LST x
RCL 1
y^x // B(n, 0, P) = (1-P)^n
LBL 1
STO+ 5 // Add to cumulative probability
/**** LOOP EXIT TEST ****/
DSNE 3 // Decrement loop counter
GTO 9 // Break from loop if counter was zero
/**** END OF LOOP EXIT ****/
RCL 1 // Calculate B(n, r+1, P)...
RCL 4 // B(n, r+1, P) =
- // B(n, r, P) * (n-r)/(r+1) * P/(1-P)
RCL 4
1
+
STO 4
/
RCL* 6
* // Done calculating next term
GTO 1 // Do another loop
LBL 9
RCL 5 // Display total
RTN