Skip to content

Use one impl block for odd and even

Having separate impl blocks for numbers with odd and even fractional bits makes generic code that depend on fixed-sqrt very tedious to write, since all generic impls need to be copied thrice. This does not scale well for use cases where one may want to implement new traits on top of fixed-sqrt. Something like simba, for example: https://github.com/rustsim/simba/blob/master/src/scalar/fixed_impl.rs.

Instead of branching at type level, it's possible to use an if statement that branches depending on the Unsigned associated constants, in a single impl block. Since the typenum values are constants after monomorphization, this "dynamic" branch should simply get optimized away by the compiler through constant evaluation and dead code elimination. As a result, this shouldn't introduce any runtime cost, but would make it much easier to use fixed-sqrt as a building block in generic code.

I can make a PR if you think it's appropriate.