TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy


Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
"Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
Lamar Harris <[log in to unmask]>
Wed, 12 Feb 1997 17:40:38 -0400
text/plain; charset="us-ascii"
Lamar Harris <[log in to unmask]>
text/plain (68 lines)
To All,

I was very impressed by the responses I got to my earlier request for help.
I've found two ways
to solve my problem. The first involved using an unchecked conversion to
convert the float type into a modular type and then see if the difference
was less than a certain amount. I found a differnce of less than four to
suffice for my purposes. The code to implement this is shown at the bottom.

Robert Eachus' solution of using a Fixed Point representation is the one I
like best. See his earlier post for how to implement this.  As the saying
goes, "You learn something everyday."

When (if) I get a paper published on an alternative algorithm to the
Traveling Salesman Problem, I'll be sure to drop a line here giving a
pointer to it. (As a teaser, I think I've found a way to find the solution
in N**2 rather than N! time, at least for points lying on the 2D Cartesian
plane.) My plan now is to hit up the ACM's Trans. on Mathematical Software
with a paper within the next two to three months. It will be nice to see a
reference in there to an algorithm implemented in something other than Fortran!

Thanks again for all the help!

Here's my code to compare two My_Float variables.  Obviously this could
easily be turned into a generic function, but I'm going rewrite my code
using Fixed Point instead.

function "="(Left, Right: in My_Float) return Boolean is
  type MFR is mod 2**My_Float'Size;
  for MFR'Size use My_Float'Size;
  package MFR_IO is new Ada.Text_IO.Modular_IO(MFR);
  use MFR_IO;
  function To_MFR
    is new Ada.Unchecked_Conversion(My_Float, MFR);
  function To_My_Float
    is new Ada.Unchecked_Conversion(MFR, My_Float);
  Left_MFR: MFR := To_MFR(Left);
  Right_MFR: MFR := To_MFR(Right);
  Diff: constant MFR := 4;
  if Left_MFR = Right_MFR then
    return True;
  elsif Left_MFR < Right_MFR then
    if Right_MFR-Left_MFR < Diff then
      return True;
      return False;
    end if;
    if Left_MFR-Right_MFR < Diff then
      return True;
      return False;
    end if;
 end if;
end "=";

Thanks again,
        ______      __
       / ____ \    / /\  Ray Harris, 2Lt, USAF
      / /\__/ /\  / / /  Rome Lab/C3CA
     / /_/_/ / / / / /   525 Brooks Rd.
    / __   _/ / / / /    Rome, NY 13441-4505
   / /\_| |\_/ / / /     "Where Visions Become Reality"
  / / / | ||  / /_/___   E-Mail: [log in to unmask] (Home: [log in to unmask])
 /_/ /  |_|| /_______/\  Phone : 315-330-4266 (DSN 587-4266)
 \_\/   \_\| \_______\/  Fax   : 315-330-7989 (DSN 587-7989)