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:
a0 : singleD_PI_2
a1 : single-0.212
a2 : single0.074
a3 : single-0.019
a0D_PI_2
a1-0.212
a20.074
a3-0.019

Interface:

name:description:
DegNormalize

function DegNormalize(deg : single) : single;



    degtorad

    function degtorad(deg : single) : single; overload;



      degtorad

      function degtorad(deg : real) : real; overload;



        radtodeg

        function radtodeg(rad : single) : single;



          gradtorad

          function gradtorad(grad : single) : single;



            radtograd

            function radtograd(rad : single) : single;



              degtograd

              function degtograd(deg : single) : single;



                gradtodeg

                function gradtodeg(grad : single) : single;



                  cycletorad

                  function cycletorad(cycle : single) : single;



                    radtocycle

                    function radtocycle(rad : single) : single;



                      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: shortint): shortint; 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: shortint): shortint; 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: single): single; overload;


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

                                                                          function ArcCos(x: single): single; overload;


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

                                                                            function ArcSin(x: real): real; overload;


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

                                                                              function ArcCos(x: real): real; overload;


                                                                              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.