As a canonical example, consider the problem of argument-reduction for trigonometric functions, as in computing x mod 2π as a first step for computing sin(x). This kind of problem is difficult in that you can't just use fmod, because y (2π in the example) is not representible.
I came up with a simple solution that works for arbitrary values y, not just 2π, and I'm curious how it compares (in performance) with typical argument-reduction algorithms.
The basic idea is to store a table containing the value of 2n mod y for each value n in the range log2(y) to the maximum possible floating point exponent, then using the linearity of modular arithmetic, sum the values in this table over bits that are set in the value of x. It amounts to N branches and at most N additions, where N is the number of mantissa bits in your floating point type. The result is not necessarily less than y, but it's bounded by N*y, and the procedure can be applied again to give a result that's bounded by log2(N)*y or fmod can simply be used at this point with minimal error.
Can this be improved? And do the typical trigonometric argument reduction algorithms work for arbitrary y or only for 2π?