Boost logo

Boost :

From: raoul45701 (kelsey_at_[hidden])
Date: 2002-02-21 13:02:53


Hi gang. I want to toss a couple of suggestions into the ring for new
features.

1. Operator overloading. For some types of classes, there are more
operators I would like to define than operator symbols. For example,
different types of matrix multiplication. It should not be difficult
to implement additional operators, but how should they be coded?

There are not many symbols available on the keyboard, so I suggest
some method of making legal identifiers represent operators. One way
to do this would be to start the identifier with some symbol to
suggest an operator. Maybe *my_new_op. If this is confusing the
compiler, how about \*my_new_op? Perhaps \* could be an esc symbol
for
some ascii number not used in C++. If this can be done, it should be
legal to end an operator with =.

2. I have read that a rational number class is being considered. I do
not think there is any one 'best' way to represent rational numbers.
One use of rational numbers is for exact computations. But
arithimetic can quickly max out any fixed representation. So you
would probably want some kind of dynamic representation.

A rational class that I have found useful is

class Rat {
private:
  unsigned long int n,d;
  long double fall_back;
  char index;
....
}

Depending on the value in index, the number is n/d, -n/d, or stashed
in fall_back if it cannot be represented with n and d. You can also
include +, -, and unsigned infinity, etc. if you want.

On a related note, does anyone an efficient algorithm for finding
integer types n and d so that n/d is the closest representable
rational number to a given double? This might not be doable.

Ralph


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