comp.lang.ada
 help / color / mirror / Atom feed
* how to make a package????
@ 1996-08-15  0:00 Michael W. Hall
  1996-08-15  0:00 ` Kevin J. Weise
  1996-08-15  0:00 ` John Herro
  0 siblings, 2 replies; 4+ messages in thread
From: Michael W. Hall @ 1996-08-15  0:00 UTC (permalink / raw)



I took a beginners course on ADA and now I am trying to learn some on my
own with book I bought, but there seems to be a big gap in the info 
between the 2. I need to know how to make a package. I guess that will
allow me to put it somewhere without having to repeat code or whatever. 
But at any rate I dont understand at all what Im doing. I have taken 
this little square root procedure and was wondering if someone can tell 
me what changes need to be made. The only thing I need to limit is 
negative numbers. And I guess somehow I need to pass this tolerance to 
the package so it can be variable. At any rate if anyone here knows what 
Im talking about, can you take a look at it. There must be some simple 
way to change a procedure to a package. Thanks. mhall59@us.net


---------------------------

with Text_IO;

procedure Square_Root is
   package Float_IO is new Text_IO.Float_IO (Num => Float);

   function Sqrt (Value : in Float) return Float is

      Tolerance : constant := 0.000001;
      Approx : Float;
 
  begin
      Approx := Value / 2.0;
      Calculate_Square_Root: 
         loop
            exit Calculate_Square_Root when abs(Approx ** 2 - Value) < 
Tolerance;
	    Approx := 0.5 * (Approx + Value / Approx);
         end loop Calculate_Square_Root;
      return Approx;
   end Sqrt;
begin
   Float_IO.Put (Sqrt (16.0));
   Text_IO.New_Line;
   Float_IO.Put (Sqrt (15.0));
   Text_IO.New_Line;
end Square_Root;





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1996-08-15  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-08-15  0:00 how to make a package???? Michael W. Hall
1996-08-15  0:00 ` Kevin J. Weise
1996-08-15  0:00   ` Michael W. Hall
1996-08-15  0:00 ` John Herro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox