comp.lang.ada
 help / color / mirror / Atom feed
* Math functions in Ada
@ 1997-05-01  0:00 William Frye
  1997-05-01  0:00 ` David C. Hoos, Sr.
  1997-05-16  0:00 ` Jacob S. Rosenberg.
  0 siblings, 2 replies; 7+ messages in thread
From: William Frye @ 1997-05-01  0:00 UTC (permalink / raw)




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.




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

* Re: Math functions in Ada
  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.
  1 sibling, 2 replies; 7+ messages in thread
From: David C. Hoos, Sr. @ 1997-05-01  0:00 UTC (permalink / raw)



How about the package Ada.Numerics.Generic_Elementary_Functions, or one of
its instantiations for long or short float types -- all provided with your
gnat distribution?
David C. Hoos, Sr.
http://www.ada95.com
http://www.dbhwww.com

William Frye <wfrye@mnsinc.com> wrote in article
<5ka4nc$man@news1.mnsinc.com>...
> 
> 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.
> 




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

* Re: Math functions in Ada
  1997-05-01  0:00 ` David C. Hoos, Sr.
@ 1997-05-05  0:00   ` Doug Smith
  1997-05-06  0:00   ` Keith Thompson
  1 sibling, 0 replies; 7+ messages in thread
From: Doug Smith @ 1997-05-05  0:00 UTC (permalink / raw)



In article <01bc5648$49652250$d08871a5@zeus>, "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> wrote:

> How about the package Ada.Numerics.Generic_Elementary_Functions, or one of
> its instantiations for long or short float types -- all provided with your
> gnat distribution?
> David C. Hoos, Sr.
> http://www.ada95.com
> http://www.dbhwww.com
> 
> William Frye <wfrye@mnsinc.com> wrote in article
> <5ka4nc$man@news1.mnsinc.com>...
> > 
> > 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.
> > 

If you haven't used generics before (or even if you have), it may not be
obvious that the functions are already available. Visit
 <http://sw-eng.falls-church.va.us/cgi-bin/webada/surfada?file=/opt/gnu/adainclude/a-nuelfu.ads#L20>
which is the predefined package Ada.Numerics.Elementary_Functions. However,
to see the list of functions (including "**") follow the link to the
generic as suggested above. The whole list of predefined packages can
be surfed at:
 <http://sw-eng.falls-church.va.us/cgi-bin/webada/file?template=predefined.html>

Doug
<mailto:dsmith@clark.net>




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

* Re: Math functions in Ada
  1997-05-01  0:00 ` David C. Hoos, Sr.
  1997-05-05  0:00   ` Doug Smith
@ 1997-05-06  0:00   ` Keith Thompson
  1 sibling, 0 replies; 7+ messages in thread
From: Keith Thompson @ 1997-05-06  0:00 UTC (permalink / raw)



In <01bc5648$49652250$d08871a5@zeus> "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> writes:
> How about the package Ada.Numerics.Generic_Elementary_Functions, or one of
> its instantiations for long or short float types -- all provided with your
> gnat distribution?

Note also that Ada.Numerics.Generic_Elementary_Functions is included
with any Ada 95 compiler, not just GNAT.

I know the original poster asked specifically about freeware and
said that he's using GNAT.  I just want to make sure others are aware
that Ada.Numerics.Generic_Elementary_Functions is predefined and not
GNAT-specific.

-- 
Keith Thompson (The_Other_Keith) kst@sd.aonix.com <http://www.aonix.com> <*>
TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix
5040 Shoreham Place, San Diego, CA, USA, 92122-5989
"Humor is such a subjective thing." -- Cartagia




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

* Re: Math functions in Ada
  1997-05-16  0:00 ` Jacob S. Rosenberg.
@ 1997-05-16  0:00   ` Robert Dewar
  1997-05-17  0:00   ` John G. Volan
  1 sibling, 0 replies; 7+ messages in thread
From: Robert Dewar @ 1997-05-16  0:00 UTC (permalink / raw)



Jacob says

<<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:>>


AARGH! This is a *horrible* equivalence to use in any program, since the
error bounds are simply awful. In other words, even with a perfectly
accurate exp and log, the result of computing x**y can be way off (hundreds
of ULP's) 

True, as Jacob suggests, if you can use a higher precisoin intermediate
type, then this formula is OK, and indeed one of the classic illustrations
of the utility of IEEE extended precision is precisely this one (i.e. if
you have accurate extended precision long and exp, as on the x86, then
you can compute long_form x**y accurately. For a detailed analysis of 
this case, see chapter 5 of my book on Microprocessors.






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

* Re: Math functions in Ada
  1997-05-01  0:00 Math functions in Ada William Frye
  1997-05-01  0:00 ` David C. Hoos, Sr.
@ 1997-05-16  0:00 ` Jacob S. Rosenberg.
  1997-05-16  0:00   ` Robert Dewar
  1997-05-17  0:00   ` John G. Volan
  1 sibling, 2 replies; 7+ messages in thread
From: Jacob S. Rosenberg. @ 1997-05-16  0:00 UTC (permalink / raw)



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.

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.

Regards,

Jacob Rosenberg

To find out about more job openings, please visit my website at
http://www.jobspot.com.  There are many more job listings in a
variety of industries and in many technical specialties.
 
All agency fees are paid by the companies.  Interview and  
relocation costs are usually reimbursed by the companies.  
Please send your resume by mail, fax, or e-mail. For best
quality, you are welcom to email your resume as an attached
file. 
Thanks and lots of luck!


Pearl Martin
Image Associates Inc.
5254 Merrick Road
Massapequa, NY  11758
Phone:  (516)798-3993
Fax:  (516)797-8703
E-Mail:  image@worldnet.att.net or headhunter@jobspot.com
--






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

* Re: Math functions in Ada
  1997-05-16  0:00 ` Jacob S. Rosenberg.
  1997-05-16  0:00   ` Robert Dewar
@ 1997-05-17  0:00   ` John G. Volan
  1 sibling, 0 replies; 7+ messages in thread
From: John G. Volan @ 1997-05-17  0:00 UTC (permalink / raw)



> 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? :-) ");
------------------------------------------------------------------------




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

end of thread, other threads:[~1997-05-17  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox