W.Ehrhardt: Misc.

It is known since more than 20 years that exp looses up to 13 bits for
extended arguments; even the newer Delphi versions (confirmed up to D14,
some are corrected in D17) have horrible bugs:

e.g. arccsch(2) = 0.27980789397 (correct = 0.48121182506);
coth(12000)=1 crashes;
sech(12000)=0 crashes;
sinh(x)/x=0 for small x;
sin(1e22)=1e22 (correct = -0.852200849767);
StdDev(a,a+1,a+2) crashes e.g. for a=100000000000; etc..

AMath’s elementary mathematical functions include: exponential, logarithmic,
trigonometric, hyperbolic, inverse circular / hyperbolic functions.
There are polynomial, vector, statistic operations as well as
floating point and FPU control functions. Delphi’s nonsense routines
(IfThen, IsZero, InRange …) and its financial functions are not
(and will not be) implemented. Here is the complete list of
AMath functions with short descriptions.

All standard one argument elementary transcendental functions have peak relative errors less than
2.2e-19, values for power(x,y) are 2.1e-19 (for |x|,|y| < 1000) and 3.4e-19
(for |x|,|y| < 2000). The accuracy is tested with the t_amathx
program using MPArith functions.

The ext2 (double-extended) routines operate on pairs of extended floating
point numbers, which represent the unevaluated sum of the high and low parts:
a = (a.h, a.l) = a.h + a.l, normally with |a.l| ≤ eps_x*|a.h|.

Util

PRNG

MPArith

AMath

DAMath

zlib

Delphi CRT unit

  • Base2N V0.42:
    General base 2**N conversion routines (N=1…6)
  • Bitarray V0.19:
    Bit array context with max. 524160 bits (spin off from MPArith 16 bit prime sieve)
  • BTypes V0.21:
    Portable common basic types
  • Compvers V0.41:
    Compiler version as string or symbol
  • Dates V0.38:
    Implements compiler and OS independent routines for the current date
    and time (including milliseconds since midnight) and functions for Julian day numbers.
  • Hrtimer V0.29:
    Contains a high resolution
    timer for most Pascal/Delphi compilers using the comp data type. It uses
    the RDTSC instruction, therefore it will stop on machines (except ARM) that do
    not support RDTSC (this feature can be turned off via $ifdef). The timer
    is used by several optimizing test programs.
  • memh V0.15:
    Implements portable heap memory allocation functions
  • Mem_util V0.99:
    Implements compiler independent routines for comparing memory blocks and
    converting memory blocks to HEX and Base64 strings.
  • Ministat V0.45:
    Statistics unit with accurate „on the fly“ statistics routines for one and two
    variables.
  • Sort V1.18:
    General QuickSort, HeapSort (standard and bottom-up), CombSort routines using
    swap/compare functions. Additional pointer versions have a typeless data
    pointer that is carried through the functions and can be used to access
    local data etc by the caller.
  • std.inc V1.75:
    Standard include file for compiler detection, standard definitions, options.
  • Tsc V0.44:
    This unit has a more low level access to the Time Stamp Counter
    than hrtimer and additionally defines a system dependent low resolution counter
    (GetTickCount, 18.2 Hz Systick, or milliseconds since midnight)
    if RDTSC support is not available.
  • Bob Jenkins‘ public domain ISAAC random number generator
    (Indirection, Shift, Accumulate, Add, and Count).
    The average cycle length of ISAAC is 2**8295, the minimum length is 2**40.
  • salsar is based upon the
    Salsa20 stream cipher and needs the
    salsa20 unit (included in $supp_rng.zip).
    The core routine uses 128 bit keys and 8 rounds (this default value can be changed
    to 12 or 20 rounds with salsar_set_rounds).
  • aesr uses AES/CTR
    mode routines with 128 bit keys (included in $supp_rng.zip).
  • New functions:
    succd/s/x, predd/s/x in mp_rcalc; mpc_log10, mpc_is_ia in mp_cmplx;
    new unit mp_ccalc, which parses and evaluates mp_complex expressions;
  • Changed functions:
    adjust sign of mpc_arctanh on the branch cut,
    error MP_PRECISION in s_mpf_mod_pi2k instead of assert;
  • Other:
    configuration parameter MPC_NO_EXECPTIONS;
  • Bugfixes:
    mp_real: copy/paste bug in mpf_sinhcosh, subtle bug for mpf_arctan2(y,0),
    mp_cmplx: mpc_ln1p and mpc_expm1 for small imaginary a, mpc_arctanh for real |a| > 1.

  • AMath V2.50:
    This unit implements accurate mathematical functions; it makes many
    routines of Delphi’s math unit available to other supported Pascal versions
    and fixes bugs and inaccuracies of Delphi:

  • The AMTools V0.46 unit provides accurate and reliable tools for finding zeros
    and local minima of functions, numerical integration of one-dimensional
    functions, convergence acceleration of sums and sequences,
    and solving quadratic / cubic / polynomial equations:

    The functions localmin, mbrent, and fmin (differing in parameter count
    / ease of use) use Brent’s algorithm with guaranteed convergence for finding a
    local minimum of a function f in an interval (a,b). The algorithm combines
    golden section search and successive parabolic interpolation using only
    function (not derivative) evaluations.

    The functions zbrent and zeroin use the Brent/Dekker algorithm with
    guaranteed convergence for finding a zero of a continuous function f in the interval
    [a,b], when f(a) and f(b) have different signs;
    zbrenty handles the zeros of f(x)-y. The algorithm is based on a
    combination of successive interpolations and bisection.
    zridders implements Ridders‘ root finding method based on
    regula falsi and exponential factors.

    The qag* procedures are Pascal translations of
    Quadpack algorithms
    by R. Piessens, E. de Doncker-Kapenga, C.W. Überhuber, D. Kahaner.
    These routines perform global adaptive quadrature of functions over finite or infinite
    intervals based on Gauss-Kronrod rules for the subintervals and acceleration
    by Wynn’s epsilon algorithm, they can handle rather difficult integrals
    including integrand functions with local difficulties such as a
    discontinuities and integrable singularities.
    quagk is a simple general purpose shell for the qag* routines.
    The Quadpack algorithm qawc computes the Cauchy principal value of f(x)/(x-c)
    using a globally adaptive strategy and modified Clenshaw-Curtis integration
    on the subintervals containing the point x=c.

    The procedures intdeo and intdei
    use the Double Exponential (DE) transformation (developed by M. Mori, T. Ooura, and others)
    for automatic quadrature of f(x) over the infinite interval (a,+INF) for
    functions with and without oscillatory factors resp.
    intde integrates over finite intervals (a,b) and
    intde_p, intdei_p are the corresponding procedures for
    functions f(x,p) with parameters.

    The adaptive quanc8 algorithm by G.E. Forsythe, M.A. Malcolm, C.B. Moler
    estimates the integral of a smooth function over a finite interval
    using a Newton-Cotes rule.


    The procedures levinu1 and wynneps1 are stand-alone versions
    of convergence acceleration methods, they perform one step of the
    Levin u-transformation for sums or one step of Wynn’s epsilon algorithm
    for the sequences or sums (original customized versions are used in LerchPhi
    and the Quadpack routines, respectively). The calling driver routines have
    to analyze the convergence of the processes.


    The squad functions accurately solve quadratic equations with
    double coefficients; they implement ideas of G.E. Forsythe, W. Kahan, P.H.
    Sterbenz (high precision calculation of discriminant, scaling by powers of two
    etc).

    The cubsolve procedure computes the solutions of real cubic equations with double
    coefficients; it is based on lecture notes by W. Kahan.

    The PolyRoots procedure computes the n (complex) roots
    x[k] + i*y[k] of the polynomial p[0] + p[1]*z + … p[n]*z^n
    using a companion matrix method, balancing, and the QR algorithm
    for the eigenvalues of an upper Hessenberg matrix.
    PolyRootsA preforms PolyRoots, then sorts and polishes the roots.


  • The units SpecFun/SpecFunX V1.53.03 implement many special functions for double and
    extended precision. In this release the following function groups are available:

    Currently all functions have double and extended versions
    (with name suffix x), e.g. erfc vs. erfcx, here is the complete list of
    AMath special functions with short descriptions.
    The file specialfunctions.pdf
    contains the Special Functions Reference Manual with Implementation Notes.

    Generally the extended versions have larger relative errors (measured in corresponding
    machine epsilon units eps_x or eps_d) than their double counterparts,
    especially gammax and betax for large arguments.
    Note that some functions are sensitive to small changes in the argument;
    therefore in high precision comparisons argument values should be used, that
    are representable in both calculations.

  • The unit AMCmplx V1.14 provides AMath based complex arithmetic,
    basic and transcendental functions; here is the
    complete list
    with short descriptions and there is a separate chapter in the
    reference PDF. The complex data type is a record with
    real and imaginary parts using the base type extended. Most routines are
    procedures with const input record(s) and a var output record.

    Please note that the exponential, trigonometric, or hyperbolic functions may
    overflow or return INFs or NaNs for inputs with real or imaginary parts of
    order ln_MaxExt or greater, this will be handled more systematically in future
    versions.


    The internal archive complexdemo.zip contains the expression parser
    / interpreter amccalc.pas and the accompanying demo programs PlotPhase
    (a GUI application for the visualization of complex functions, on the right
    a sample image) and T_CCalcX (a console program for the evaluation of
    complex expressions).


  • The unit AMQuat V0.20 units provide AMath based quaternionic
    arithmetic and elementary transcendental functions here is the complete list with short descriptions.
    The quaternion data type is a record with real (or scalar) and
    imaginary (or vector) parts using the base type extended.

    type
      Quaternion = record
                     r:     extended; {real or scalar part     }
                     x,y,z: extended; {imaginary or vector part}
                   end;
    

    Most routines are procedures with const
    input record(s) and a var output record.
    A quaternion is often written as a = r1 + xi + yj
    + zk, where 1, i, j, k are the fundamental quaternion units
    (as 4-dimensional vectors they are the standard unit vectors).

    Addition and subtraction are defined component-wise, i.e. the standard vector
    addition in R4. Multiplication of quaternions is associative and
    distributive, but it is not commutative, it is determined
    by the relations i^2 = j^2 = k^2 = ijk = -1. The norm of a quaternion
    is r^2 + x^2 + y^2 +z^2, the absolute value |a| is the square root of the norm,
    and conj(a) = r1 – xi – yj – zk is the conjugate.
    The multiplicative inverse is (1/a) = conj(a)/norm(a), division is defined as
    a/b = a*(1/b).

    Most (inverse) trigonometric / hyperbolic quaternion functions b=f(a) are
    basically computed with the corresponding complex function w=F(z) with z =
    Re(a) + i*abs(Im(a)) and the mapping to quaternions Re(b) = Re(w), Im(b) =
    Im(w)*Im(a)/abs(Im(a)). Note that AMQuat has no quaternionic power
    function a^b, if b=x is a real number, a^x is defined as exp(x*ln(a)).

  • Bessel functions and related,
  • elliptic integrals/functions and theta functions,
  • gamma function and related,
  • zeta functions, polylogarithms, and related,
  • error function and related,
  • exponential integrals and related,
  • orthogonal polynomials, Legendre functions and related,
  • hypergeometric functions and related,
  • statistical distributions,
  • and other special functions.

  • DAMath V1.17:
    This unit implements the double precision accurate mathematical functions:
    exponential, logarithmic, trigonometric, hyperbolic, inverse circular /
    hyperbolic functions; and there are the polynomial, vector, statistic operations
    and floating point functions.

    DAMath uses the system functions abs, arctan, frac, int, ln, and trunc
    (including possible bugs for 32-bit). Because FPC-64 (versions ≤ 2.6.4) looses up to 13 of the
    53 bits for exp, DAMath implements its own exp function. System sin(x)
    and cos(x) are used for |x| ≤ Pi/4, Payne/Hanek range reduction is performed
    if |x| > 2^30.

    On Win7/64 the 64-bit DAMath one argument elementary transcendental functions
    and power have peak relative errors < 2*eps_d (about 4.4e-16), the RMS
    values are < 0.6*eps_d, a complete list and the Delphi, FPC, ARM figures can be
    found in the log files *.cmp.

    The dbl2 (double-double) routines work with pairs of 53-bit doubles
    representing the unevaluated sum a = (a.h, a.l) = a.h + a.l, normally with |a.l| ≤ eps_d*|a.h|.


  • The DAMTools V0.47 unit provides accurate and reliable tools for finding zeros
    and local minima of functions, numerical integration of one-dimensional
    functions, convergence acceleration of sums and sequences, and solving quadratic,cubic
    and polynomial equations.


  • DAMath based double precision special functions
    are derived from the AMath implementations, i.e. the descriptions in
    the introduction
    and the specialfunctions.pdf manual
    are essentially valid (with obvious restrictions), the interfaced functions in unit
    SpecFunD V1.38.02 have the same names, etc. Here are some internal details:


  • The unit DAMCmplx V0.70 provides DAMath based complex arithmetic,
    basic and transcendental functions (here is the
    complete list
    with short descriptions). The complex data type is
    a record with real and imaginary parts of type double.
    The internal archive complexdemo.zip contains the 64-bit compatible
    versions of the expression parser / interpreter damccalc.pas and the
    accompanying demo programs PlotPhaseD and T_CCalcD.


  • The unit DAMQuat V0.20 units provides DAMath based quaternionic
    arithmetic and elementary transcendental functions (here is the
    complete list
    with short descriptions) The quaternion data
    type is a record with real (or scalar) and imaginary (or vector) parts using
    the base type double.

    type
      Quaternion = record
                     r:     double; {real or scalar part     }
                     x,y,z: double; {imaginary or vector part}
                   end;
    

    Most routines are procedures with const input record(s) and a
    var output record. Addition and subtraction are defined component-wise.
    Multiplication of quaternions is associative and distributive, but it is
    not commutative. Most (inverse) trigonometric / hyperbolic quaternion
    functions are basically computed with their corresponding complex
    function.

  • The internal functions are pre-fixed with sfd_,
    the unit names start with sd, e.g. sdBessel vs. sfBessel.
  • Constants, arguments, and function value ranges are adjusted to the double
    precision target.
  • Hex/extended constructs are replaced by hex/double (partly recalculated).
  • Most polynomial and rational approximations are kept, resulting in
    slightly sub-optimal implementations (optimal double precision approximations
    are usually very different).
  • Chebyshev approximations are easily adjusted to double precision!
  • The relative errors of the DAMath special functions are usually larger
    (especially on 64-bit systems) than those of the corresponding AMath
    double functions (which are often correctly rounded due to the internal
    extended precision calculations).

  • The code base V1.1.4 is very old and there are
    newer and better versions of zlib. Therefore the zlib units included
    in newer Delphi and FPC version should be used whenever possible.
  • My zlib routines should only be applied to files with sizes
    less that 2 GB (32 bit counters; Delphi eof bug and/or 32 bit filesize function).
© 2018 W.Ehrhardt Last update Nov. 27, 2018
Home CRC/Hash Crypto Misc. Info Links Deutsch
Miscellaneous
BP7 BP7 D6 D6 D18/64 D18/64
Generator ctx size cycle length C/B MB/s C/B MB/s C/B MB/s
pasrand 4 2**32 74.0 22.9 5.0 294.0 5.0 459.0
taus88 16 2**88 79.0 21.5 8.0 211.9 10.8 213.5
taus113 20 2**113 85.0 20.0 8.0 211.9 13.5 170.0
kiss123 20 2**123 114.0 14.9 13.3 127.9 15.0 153.0
tt800 106 2**800 308.3 5.5 18.5 91.7 18.0 126.7
well1024a 134 2**1024 166.5 10.2 7.8 218.7 13.8 166.9
xor4096 522 2**4096 80.0 21.0 6.5 260.7 12.3 187.3
mt19937 2502 2**19937 227.4 7.4 8.3 204.5 12.6 181.5
aesr 290 2**128 211.2 8.0 28.4 59.7 60.2 38.1
salsar 202 2**70 108.3 15.7 15.4 110.3 31.1 73.8
isaac 2066 2**8295 122.0 13.9 9.0 189.3 12.8 178.9
Home CRC/Hash Crypto Misc. Info Links Deutsch

procedure generic_init(var ctx: generic_ctx; seed: longint);
  {-Init context from seed}

procedure generic_init0(var ctx: generic_ctx);
  {-Init context from randseed}

procedure generic_next(var ctx: generic_ctx);
  {-Next step of PRNG}

procedure generic_read(var ctx: generic_ctx; dest: pointer; len: longint);
  {-Read len bytes from the PRNG to dest}

function  generic_long(var ctx: generic_ctx): longint;
  {-Next random positive longint}

function  generic_dword(var ctx: generic_ctx): {$ifdef HAS_CARD32}cardinal{$else}longint{$endif};
  {-Next 32 bit random dword (cardinal or longint)}

function  generic_word(var ctx: generic_ctx): word;
  {-Next random word}

function  generic_double(var ctx: generic_ctx): double;
  {-Next random double [0..1) with 32 bit precision}

function  generic_double53(var ctx: generic_ctx): double;
  {-Next random double in [0..1) with 53 bit precision}

function  generic_rangew(var ctx: generic_ctx; range: word): word;
  {-Next random word in range 0..range-1}

function  generic_rangel(var ctx: generic_ctx; range: longint): longint;
  {-Next random longint in range 0..range-1}

function  generic_selftest: boolean;
  {-Simple self-test of PRNG}

std.zipstd.incBTypesBefore downloading any software from this site please read this
legal notice.
Last changes:Last changes: Well1024arangel/wtaus88taus113tt800mt19937kiss123 well1024axor4096pasrand.cryptographicmulti precision integer, rational, real,
and complex arithmetic
Last changes: accurate mathematical methodsrmNearest80-bit extendednotLast changes:AMathSpecial FunctionsAMCmplxdouble precision accurate mathematical methodsAMathDFPUAMathLast changes:DAMathSpecial FunctionsDAMCmplxPASZLIB 1.0zlibexzpipeLast changes: zlibzlibhgzioPlease note:Last changes: notdisclaimerNote: notrandomministathrtimerconstconstused ‚unit was based heavily
off of the Borland CBuilder 5 RTL‘
UtilPRNGMPArithAMathDAMathzlibDelphi CRTutil_2018-11-27.zipprng_2018-01-01.zipmparith_2018-11-27.zipmp_intromp_intro function listmp_intro referencesamath_2018-11-27.zipDAMathintroductiondamath_2018-11-27.zipzlibw114_2015-09-14.zipzlibFZCA demo programMPArithdcrt_2017-11-29.ziplinks

Nach oben scrollen