comp.lang.ada
 help / color / mirror / Atom feed
From: "John G. Volan" <johnvolan@sprintmail.com>
Subject: Re: Math functions in Ada
Date: 1997/05/17
Date: 1997-05-17T00:00:00+00:00	[thread overview]
Message-ID: <337E5534.4557@sprintmail.com> (raw)
In-Reply-To: 5lhvrk$cqj@mtinsc05.worldnet.att.net


> wfrye@mnsinc.com (William Frye) wrote:
> 
> >Is a there a source of freeware Ada routines for simple math functions?
> >I am particularly interested in a routine  to calculate x**y where x and y
> >are floating point numbers.  I am working with gnat on a Win95 platform.

Of course there is such a source! In fact, you already have it! (See
below...)

Jacob S. Rosenberg. wrote:
> 
> Hi William,
> 
> First of all, x**y equals exp(y * log(x)).  So, all you need are the
> log (logarithm) and exp (exponential) functions.  It should be failrly
> easy to write such a function as log and exp are generally provided.
> Indeed, the whole thing would be:
> 
> return exp(y * log(x));
> 
> I strongly recommend that the input values and the functions used are
> of type long_float and not float in order to provide greater range and
> accuracy.  The function itself could return a float.  In that case,
> you can do a conversion to float before the return statement.

Why in heaven's name would you want to re-invent the wheel, when "**" is
already provided in the standard library?  See ARM A.5.1 Elementary
Functions:

  generic
    type Float_Type is digits <>;
  package Ada.Numerics.Generic_Elementary_Functions is
     ...
     function "**" (Left, Right : Float_Type'Base)
       return Float_Type'Base;
     ...

------------------------------------------------------------------------
Internet.Usenet.Put_Signature 
  (Name => "John G. Volan",  Home_Email => "johnvolan@sprintmail.com",
   Slogan => "Ada95: The World's *FIRST* International-Standard OOPL",
   Disclaimer => "These opinions were never defined, so using them " & 
     "would be erroneous...or is that just nondeterministic now? :-) ");
------------------------------------------------------------------------




      parent reply	other threads:[~1997-05-17  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-05-01  0:00 Math functions in Ada William Frye
1997-05-01  0:00 ` David C. Hoos, Sr.
1997-05-05  0:00   ` Doug Smith
1997-05-06  0:00   ` Keith Thompson
1997-05-16  0:00 ` Jacob S. Rosenberg.
1997-05-16  0:00   ` Robert Dewar
1997-05-17  0:00   ` John G. Volan [this message]
replies disabled

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