Boost logo

Boost :

From: Paul Moore (gustav_at_[hidden])
Date: 2000-11-27 17:51:45


From: Reggie Seagraves [mailto:reggie_at_[hidden]]
> I previously sent (and am again enclosing here) an algorithm
> for converting a floating point value to a rational. This
> could/should be used by a rational class's constructor.
> Please integrate/test it at your convenience.

Thanks. This is very useful. I apologise for not having noticed your
previous posting...

However, there is an issue in the context of rational<>, namely the need for
a maximum denominator. I'm trying to implement a constructor from a double.
So where do I get a maximum denominator from? I could require the user to
specify it as a constructor argument, or I could use the maximum value of
the underlying integer type of rational<>. The former approach seems to me
not very user-friendly, whereas the latter doesn't avoid the problem of
"over-precise" values.

I believe that mathematically, it is possible to view machine doubles as
representing a series of discrete points on the mathematical real line. The
problem I am looking to solve is to find the simplest rational (a
well-defined concept) which is closer (in the absolute mathematical sense)
to the supplied double than to any other value representable as a double. I
believe this is calculable, and furthermore, I believe that there exist
implementations of the algorithm. Unfortunately, I don't know of existing
code, nor do I have the expertise to implement the algorithm from first
principles.

I'd appreciate Boost members' comments. Should I include Reggie's algorithm
(and if so, what should I use as a maximum denominator)? Or should I wait
until I can find an implementation of the "ideal" algorithm?

Thanks,
Paul.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk