|
Boost : |
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2008-07-31 20:44:08
John C. Femiani wrote:
> Neal Becker wrote:
>
>> //self operator %=(base_type x) { val %= x; return *this; } What
>> should this do?
> I think perhaps it should behave like fmod (?)
>
>
I had a fixed-point library with the purpose that code written should be
able to choose to use fixed-point or floating point math at compile time
without having to rewrite the algorithms.
Instead of providing a % operator I provided an fmod function for parity
with floating point types.
/// Computes the remainder of fixed-point division
/// @param x The numerator.
/// @param y The divisor.
/// @return the value x - i * y, for some integer i such that, if y is
/// non-zero, the result has the same sign as x and magnitude
/// less than the magnitude of y.
template<std::size_t M, std::size_t F> inline
fixed<M,F> fmod( fixed<M,F> x, fixed<M,F> y )
{
return as_fixed(x.raw() % y.raw());
}
/// shorthand for fmod( fixed, integer )
template<std::size_t M, std::size_t F, typename T > inline
typename boost::enable_if<boost::is_integral<T>,fixed<M,F> >::type
fmod( fixed<M,F> x, T y )
{
return fmod( x, fixed<M,F>(y) );
}
Thanks,
Michael Marcin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk