Ada Programming/Libraries/Ada.Numerics.Generic Elementary Functions


This language feature is available from Ada 95 on.

Ada. Time-tested, safe and secure.
Ada. Time-tested, safe and secure.

Ada.Numerics.Generic_Elementary_Functions is a unit of the Predefined Language Environment since Ada 95.

The generic package Ada.Numerics.Generic_Elementary_Functions defines various mathematical functions for floating point type. Being generic it can not only be used for predefined floating point types but also for any user defined floating type.

Usage

edit

There is an extensive usage guide in Ada Programming/Mathematical calculations. Here the relevant extract:

File: numeric_4.adb (view, plain text, download page, browse all)
with Ada.Numerics.Generic_Elementary_Functions;

procedure Numeric_4 is

  type Value_Type is digits 12 range
     -999_999_999_999.0e999 .. 999_999_999_999.0e999;

  package Value_Functions is new Ada.Numerics.Generic_Elementary_Functions (
     Value_Type);

Specification

edit
--                     Standard Ada library specification
--   Copyright (c) 2003-2018 Maxim Reznik <reznikmm@gmail.com>
--   Copyright (c) 2004-2016 AXE Consultants
--   Copyright (c) 2004, 2005, 2006 Ada-Europe
--   Copyright (c) 2000 The MITRE Corporation, Inc.
--   Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc.
--   SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual
-- -------------------------------------------------------------------------

generic
   type Float_Type is digits <>;

package Ada.Numerics.Generic_Elementary_Functions is
   pragma Pure (Generic_Elementary_Functions);

   function Sqrt
     (X           : Float_Type'Base) return Float_Type'Base;
   function Log
     (X           : Float_Type'Base) return Float_Type'Base;
   function Log
     (X, Base     : Float_Type'Base) return Float_Type'Base;
   function Exp
     (X           : Float_Type'Base) return Float_Type'Base;
   function "**"    (Left, Right : Float_Type'Base) return Float_Type'Base;

   function Sin
     (X           : Float_Type'Base) return Float_Type'Base;
   function Sin
     (X, Cycle    : Float_Type'Base) return Float_Type'Base;
   function Cos
     (X           : Float_Type'Base) return Float_Type'Base;
   function Cos
     (X, Cycle    : Float_Type'Base) return Float_Type'Base;
   function Tan
     (X           : Float_Type'Base) return Float_Type'Base;
   function Tan
     (X, Cycle    : Float_Type'Base) return Float_Type'Base;
   function Cot
     (X           : Float_Type'Base) return Float_Type'Base;
   function Cot
     (X, Cycle    : Float_Type'Base) return Float_Type'Base;

   function Arcsin
     (X           : Float_Type'Base) return Float_Type'Base;
   function Arcsin
     (X, Cycle    : Float_Type'Base) return Float_Type'Base;
   function Arccos
     (X           : Float_Type'Base) return Float_Type'Base;
   function Arccos
     (X, Cycle    : Float_Type'Base) return Float_Type'Base;
   function Arctan  (Y           : Float_Type'Base;
                     X           : Float_Type'Base := 1.0)
                    return Float_Type'Base;
   function Arctan  (Y           : Float_Type'Base;
                     X           : Float_Type'Base := 1.0;
                     Cycle       : Float_Type'Base) return Float_Type'Base;
   function Arccot  (X           : Float_Type'Base;
                     Y           : Float_Type'Base := 1.0)
                    return Float_Type'Base;
   function Arccot  (X           : Float_Type'Base;
                     Y           : Float_Type'Base := 1.0;
                     Cycle       : Float_Type'Base) return Float_Type'Base;

   function Sinh
     (X           : Float_Type'Base) return Float_Type'Base;
   function Cosh
     (X           : Float_Type'Base) return Float_Type'Base;
   function Tanh
     (X           : Float_Type'Base) return Float_Type'Base;
   function Coth
     (X           : Float_Type'Base) return Float_Type'Base;
   function Arcsinh
     (X           : Float_Type'Base) return Float_Type'Base;
   function Arccosh
     (X           : Float_Type'Base) return Float_Type'Base;
   function Arctanh
     (X           : Float_Type'Base) return Float_Type'Base;
   function Arccoth
     (X           : Float_Type'Base) return Float_Type'Base;

end Ada.Numerics.Generic_Elementary_Functions;

See also

edit

Wikibook

edit

Ada Reference Manual

edit

Ada 95

edit

Ada 2005

edit

Ada 2012

edit

Open-Source Implementations

edit

FSF GNAT

drake