MJW Posted June 8, 2016 Share Posted June 8, 2016 To some this might seem trivial, but I think it could be useful. Suppose n and d are positive integers. Let n/d represent floating-point division and [n/d] represent (truncated) integer division. Suppose I want to find, The largest integer less than n/d; The largest integer less than or equal to n/d; The smallest integer greater than or equal to n/d; The smallest integer greater than n/d. ---------- 1) The largest integer less than or equal to n/d. This one is easy. It's just [n/d] 2) The largest integer less than n/d. The only case where [n/d] is not less than n/d is when d evenly divides n. If we subtract 1 from n, it will reduce the result by 1 for the evenly divisible values of n and leave the other values unchanged. However, care must be taken if n can be 0, since division of both positive and negative values truncates toward 0. In that case, we can add d to the numerator, and then subtract 1 from the truncated division. So, the correct value is: [(n - 1)/d] or, [(n + d - 1)/d] - 1 if n could be 0. 3) The smallest integer greater than n/d. This is [n/d] + 1 (or [(n + d)/d]) 4) The smallest integer greater than or equal to n/d. The situation is the same smallest integer greater than n/d, except the result for evenly divisible values of n must be reduced by 1. Using the same method as the largest integer less than n/d, the value is: [(n - 1)/d] + 1 or [(n + d - 1)/d] if n could be 0. ---------- Summarizing. The largest integer less than n/d: [(n - 1)/d] or [(n + d - 1)/d] - 1 The largest integer less than or equal to n/d: [n/d] The smallest integer greater than or equal to n/d: [(n - 1)/d] + 1 or [(n + d - 1)/d] The smallest integer greater than n/d: [n/d] + 1 1 Quote Link to comment Share on other sites More sharing options...

Rick Brewster Posted June 10, 2016 Share Posted June 10, 2016 It'd be cool to have an example of how/where to use these Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...

MJW Posted June 10, 2016 Author Share Posted June 10, 2016 Actually, I plan to do that. I thought I'd write a comment explaining how the Color Clearer plugin works. I found the problem of maximizing the transparency while exactly matching the original blended pixels to be interesting, and the techniques might be useful for other plugins. It's usually simpler to do everything in floating point, but because that's not how PDN does the blending computations, the results don't always exactly match. Quote Link to comment Share on other sites More sharing options...

## Recommended Posts

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.