From: Andras Erdei (aerdei_at_[hidden])
Date: 2005-04-17 18:23:41
On 4/17/05, Andy Little <andy_at_[hidden]> wrote:
> Apologies for not answering the other points. This is a complicated issue
> and I dont have answers..
i also don't know much about rationals (there is much about them i don't
know?), so i often fall back to asking mathematician friends when faced with
problems, unfortunately it turned out there are lots of things they don't
> >> Is a rational number implementation that has been rounded, a rational
> >> number?... Yes, but not the one you expected.
> > can you rephrase this (most likely i don't get this one because of my english)
> Assume you add 1/2 + 1/3 and you get the result 2/3 or 1/1. (assume a
> rational<uint2>) 2/3 is a rational number as is 1/1.
[i also assume that uint2 means the numerator and denominator can be 0..3,
thus the representable values are 0/1,1/3,1/2,2/3,1/1,3/2,2/1,3/1,1/0]
> BTW what would be the result in your rounding version of the calculation?
[if you haven't yet, please check
the exact result (5/6) is the median of two representable numbers (1/1 and
2/3), in such cases the algorithm always chooses the simpler one (p/q is
simpler than r/s if p <= r and q <= s and at least one inequality is strict),
thus the rounded result would be 1/1
you can view the numbers representable with rational<n> as a set of numbers
closed under the simpler than relation (any number simpler than a
representable number is also representable); an interesting property is that
simpler numbers have wider associated rounding intervals -- e.g. in rational<5>
where 1/3 and 2/5 are adjacent, more numbers will be rounded towards 1/3 than
2/5, which means that when a series of exact calculations would result in
some "special" value, you often get that result even if the intermediate
values were rounded
btw it's not "my" rounding, the math background comes from continued fractions
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk