unit math

Additional mathematical routines

author: Tomasz Biela (Tebe)


http://www.freepascal.org/docs-html/rtl/math/index-5.html
https://github.com/graemeg/freepascal/blob/master/rtl/objpas/math.pp
hypot function from AMath library (C) Copyright 2009-2013 Wolfgang Ehrhardt

Constants:

name:value:description:
a0D_PI_2
a1-0.212
a20.074
a3-0.019

Interface:

name:description:
DegNormalize

function DegNormalize(deg : real) : real;



    degtorad

    function degtorad(deg : real) : real;



      radtodeg

      function radtodeg(rad : real) : real;



        gradtorad

        function gradtorad(grad : real) : real;



          radtograd

          function radtograd(rad : real) : real;



            degtograd

            function degtograd(deg : real) : real;



              gradtodeg

              function gradtodeg(grad : real) : real;



                cycletorad

                function cycletorad(cycle : real) : real;



                  radtocycle

                  function radtocycle(rad : real) : real;



                    DivMod

                    procedure DivMod(Dividend: integer; Divisor: Word; var r, Remainder: Word); overload;


                    DivMod returns Dividend DIV Divisor in Result, and Dividend MOD Divisor in Remainder
                      DivMod

                      procedure DivMod(Dividend: integer; Divisor: Word; var r, Remainder: smallint); overload;


                      DivMod returns Dividend DIV Divisor in Result, and Dividend MOD Divisor in Remainder
                        InRange

                        function InRange(const AValue, AMin, AMax: byte): Boolean; overload;


                        InRange returns True if AValue is in the range AMin..AMax. It returns False if Value lies outside the specified range.
                          InRange

                          function InRange(const AValue, AMin, AMax: Integer): Boolean; overload;


                          InRange returns True if AValue is in the range AMin..AMax. It returns False if Value lies outside the specified range.
                            EnsureRange

                            function EnsureRange(const AValue, AMin, AMax: byte): Integer; overload;


                            EnsureRange returns Value if AValue is in the range AMin..AMax. It returns AMin if the value is less than AMin, or AMax if the value is larger than AMax.
                              EnsureRange

                              function EnsureRange(const AValue, AMin, AMax: Integer): Integer; overload;


                              EnsureRange returns Value if AValue is in the range AMin..AMax. It returns AMin if the value is less than AMin, or AMax if the value is larger than AMax.
                                Min

                                function Min(x, y: real): real; overload;


                                Min returns the smallest value of X and Y.
                                  Min

                                  function Min(x, y: shortreal): shortreal; overload;


                                  Min returns the smallest value of X and Y.
                                    Min

                                    function Min(x, y: single): single; overload;


                                    Min returns the smallest value of X and Y.
                                      Min

                                      function Min(x, y: smallint): smallint; overload;


                                      Min returns the smallest value of X and Y.
                                        Min

                                        function Min(x, y: integer): integer; overload;


                                        Min returns the smallest value of X and Y.
                                          Max

                                          function Max(x, y: real): real; overload;


                                          Max returns the maximum of X and Y.
                                            Max

                                            function Max(x, y: shortreal): shortreal; overload;


                                            Max returns the maximum of X and Y.
                                              Max

                                              function Max(x, y: single): single; overload;


                                              Max returns the maximum of X and Y.
                                                Max

                                                function Max(x, y: smallint): smallint; overload;


                                                Max returns the maximum of X and Y.
                                                  Max

                                                  function Max(x, y: integer): integer; overload;


                                                  Max returns the maximum of X and Y.
                                                    RandomRange

                                                    function RandomRange(const aFrom, aTo: smallint): smallint;


                                                    RandomRange returns a random value in the range AFrom to ATo. AFrom and ATo do not need to be in increasing order. The upper border is not included in the generated value, but the lower border is.
                                                      RandomRangeF

                                                      function RandomRangeF(const min, max: single): single;



                                                        RandG

                                                        function RandG(mean, stddev : single) : single;


                                                        Return gaussian distributed random number.
                                                          power

                                                          function power(base : real; const exponent : shortint) : real; overload;


                                                          Return real power.
                                                            power

                                                            function power(base : single; const exponent : shortint) : single; overload;


                                                            Return real power.
                                                              power

                                                              function power(base : integer; const exponent : shortint) : integer; overload;


                                                              Return real power.
                                                                arctan2

                                                                function arctan2(y,x : real) : real;


                                                                arctan2 calculates arctan(y/x), and returns an angle in the correct quadrant. The returned angle will be in the range $-\pi$ to $\pi$ radians.
                                                                  ArcSin

                                                                  function ArcSin(x: real): real;


                                                                  Arcsin returns the inverse sine of its argument x. The argument x should lie between -1 and 1.
                                                                    ArcCos

                                                                    function ArcCos(x: real): real;


                                                                    Arccos returns the inverse cosine of its argument x. The argument x should lie between -1 and 1 (borders included).
                                                                      Tan

                                                                      function Tan(x: Real): Real;


                                                                      Tan returns the tangent of x. The argument x must be in radians.
                                                                        Ceil

                                                                        function Ceil(a: real): smallint;


                                                                        Ceil returns the lowest integer number greater than or equal to x. The absolute value of x should be less than maxint.
                                                                          Floor

                                                                          function Floor(a: real): smallint;


                                                                          Floor returns the largest integer smaller than or equal to x. The absolute value of x should be less than maxint.
                                                                            FMod

                                                                            function FMod(a, b: real): real;



                                                                              Log10

                                                                              function Log10(x: single): single;


                                                                              Log10 returns the 10-base logarithm of X.
                                                                                log2

                                                                                function log2(x : single) : single;


                                                                                Log2 returns the 2-base logarithm of X.
                                                                                  logn

                                                                                  function logn(n,x : single) : single;


                                                                                  Logn returns the n-base logarithm of X.
                                                                                    IsNan

                                                                                    function IsNan(const d : Single): Boolean;


                                                                                    IsNan returns True if the single d contains Not A Number (a value which cannot be represented correctly in single format).
                                                                                      Sign

                                                                                      function Sign(const AValue: Integer): shortint; overload;


                                                                                      Return sign of argument
                                                                                        parameters:
                                                                                      • AValue - Integer
                                                                                      Sign

                                                                                      function Sign(const AValue: Real): Real; overload;


                                                                                      Return sign of argument
                                                                                        parameters:
                                                                                      • AValue - Real
                                                                                      Sign

                                                                                      function Sign(const AValue: Single): Single; overload;


                                                                                      Return sign of argument
                                                                                        parameters:
                                                                                      • AValue - Single (float)
                                                                                      hypot

                                                                                      function hypot(x,y : float) : float;


                                                                                      Hypot returns the hypotenuse of the triangle where the sides adjacent to the square angle have lengths x and y. The function uses Pythagoras' rule for this.