Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2005-09-06 20:23:29


"Joel Eidsath" <jeidsath_at_[hidden]> wrote in message
news:431E2D2F.7090501_at_gmail.com...
>
>>
>>Thats true but irrelevant, because you cant tell, given only the resulting
>>floating point representation, whether your
>> floating-point value is representing an approximation to some value which may
>>be rational or itrrational or alternatively is an exact representation of a
>>rational value.
>>
>>
>>
> And so...? I fail to see your point.

My point is that floating point representation of a number is in no way a peer
concept of rational number. IOW your assertion :

"Examples of basic rational number types in C++: float, double, etc."

is equivalent trying to compare two C++ types that dont have a comparison
operator.

 The proper use for a rational number is as a dimensionless constant in an
equation. In this case its numerator or denominator values are rarely anything
other than small integers.

floating-point values on the other hand are useful to represent measured
analogue quantities (physical measurement by nature being inexact) , for example
the distance between two points, the height of the tide at an analogue instant
of time. Physical quantities are never rational numbers but rather analogue
values given meaning by the convention of units.

The following is an example of how I would consistenly use floating-point types
and
rationals to give a theoretically better precision then if using floating-point
types only.
(Of course, due to the lossiness of floats, any multiplication/division of a
float by a rational and vice versa must result in a float (rather than a
rational) )

// get distance travelled from u,v,a,t
double u = U, v = V, t = T, a = A; // analogue velocities expressed in some
units of measure
double s = u * t + my::rational(1,2) * a * pow(t,2);

// find volume of sphere
double radius =R;
double volume= my::rational(4,3) * pow(r,3);

note: Having said that boost::rational can't be used in this way because there
is no multiplication or division between boost::rational and floating point
types. This in now way invalidates the examples.

regards
Andy Little


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