[Image: GNU Sather logo]
(Answer) (Category) Sather FAQ : (Category) Developing the Sather language and libraries : (Answer) Customized floats
From: gomes@ICSI.Berkeley.EDU (Benedict A. Gomes)
Date: 24 Feb 1998 07:36:39 GMT

In article <34F1D1EF.73B9@DMI.USherb.CA>,
Jean-Pierre Dussault   wrote:
>Hi...
>
>I use floating point computations, and I wish to make my code
>independent from the chosen representation (FLT, FLTD, FLTI, ...).
>Therefore, I wish I could use something like:
>
>immutable class MY_FLOAT is
>   include FLTD;
>   --include FLT;
>   --include FLTI;
>   -- etc
>end;
>
>
>Unfortunately, the conversions between the number classes are "hard
>coded", so that I am not able to create any "MY_FLOAT". I was once
>suggested to use something like:
>
....

A clean solution could be achieved with a module construct where the type is set for the whole module. I've come across similar situations.

I usually manage to get around the problem since my usage of FLTs is somewhat layered, and I can isolate the upper layers from the lower, numeric layers.

Start by creating some basic classes that are parametrized around
FLT/FLTD etc.
eg. class VECTOR{T} ....

You can then create different versions of these classes pre-parametrized. i.e. one file might contain
flt-version.sa
class VECTOR is include VECTOR{FLT} end;
class MATRIX is include MATRIX{FLT} end;

Another file might contain:
fltd-version.sa
class VECTOR is include VECTOR{FLTD} end;
class MATRIX is include MATRIX{FLTD} end;

Using the module file you can then point to flt-version.sa or fltd-version.sa depending on what you wish to use for a particular compilation. You can do this quite conveniently with different module files.

Boris will respond with details on a lower-level solution by defining the create routine for MY_FLOAT in a config file.

ben

Previous: (Answer) Design by Contract -- Eiffel v. Sather
Next: (Answer) Formal aspects of the Sather language

Copyright (C) 2000 Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA
Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.