Boost logo

Boost :

From: Reggie Seagraves (reggie_at_[hidden])
Date: 2000-11-28 11:47:20


Hey Paul,
  The maximum denominator helps you pick the 'resolution' of your rationals,
in the current implementation, you would use numeric_limits<long>::max, or
some such equivalent where 'long' is the actual integral type used in the
implementation of the rational.

At 10:51 PM +0000 11/27/00, Paul Moore wrote:
>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