06-30-2003, 07:35 AM
Ok, let's get back to the topic. We haven't had a one-line algorithm since Oracle's calculation for PI.
A few days ago I posted the following:
Nobody came up with the method of computing the "nearest" multiple, so here it is:*****
A few days ago I posted the following:
Code:
Given a positive integer number N, compute the next multiple of X:
Result to M.
defint a-z
M = int((N+X)/X)*X
Note: "next" multiple means that if you're already at a multiple, you move up to the next multiple. Example: if N=5 and X=5, the result will be 10.
If you got that, then make a slight change to the algorithm to compute the "nearest" multiple. Example: if n=5 and x=5, the result is 5 because it is the nearest (you're already there). This is like rounding --- if it's already rounded, then that's the answer.
Code:
M = int((N+X-1)/X)*X