vmod_math(3)

Name
vmod_math - VMOD wrapping math.h

SYNOPSIS

    import math [as name] [from "path"]
    BOOL approx(REAL a, REAL b, REAL maxDiff, REAL maxRelDiff)
    STRING strfromd(STRING format, REAL fp)
    REAL constant(ENUM name)
    INT fpclass(ENUM name)
    INT fpclassify(REAL x)
    INT isfinite(REAL x)
    INT isgreater(REAL x, REAL y)
    INT isgreaterequal(REAL x, REAL y)
    INT isinf(REAL x)
    INT isless(REAL x, REAL y)
    INT islessequal(REAL x, REAL y)
    INT islessgreater(REAL x, REAL y)
    INT isnan(REAL x)
    INT isnormal(REAL x)
    INT isunordered(REAL x, REAL y)
    INT signbit(REAL x)
    REAL acos(REAL x)
    REAL acosh(REAL x)
    REAL asin(REAL x)
    REAL asinh(REAL x)
    REAL atan(REAL x)
    REAL atan2(REAL y, REAL x)
    REAL atanh(REAL x)
    REAL cbrt(REAL x)
    REAL ceil(REAL x)
    REAL copysign(REAL x, REAL y)
    REAL cos(REAL x)
    REAL cosh(REAL x)
    REAL erf(REAL x)
    REAL erfc(REAL x)
    REAL exp(REAL x)
    REAL exp2(REAL x)
    REAL expm1(REAL x)
    REAL fabs(REAL x)
    REAL fdim(REAL x, REAL y)
    REAL floor(REAL x)
    REAL fma(REAL x, REAL y, REAL z)
    REAL fmax(REAL x, REAL y)
    REAL fmin(REAL x, REAL y)
    REAL fmod(REAL x, REAL y)
    REAL hypot(REAL x, REAL y)
    INT ilogb(REAL x)
    REAL j0(REAL x)
    REAL j1(REAL x)
    REAL jn(INT x, REAL y)
    REAL ldexp(REAL x, INT e)
    REAL lgamma(REAL x)
    REAL log(REAL x)
    REAL log10(REAL x)
    REAL log1p(REAL x)
    REAL log2(REAL x)
    REAL logb(REAL x)
    INT lrint(REAL x)
    INT lround(REAL x)
    REAL nan(STRING tag)
    REAL nearbyint(REAL x)
    REAL nextafter(REAL x, REAL y)
    REAL pow(REAL x, REAL y)
    REAL remainder(REAL x, REAL y)
    REAL rint(REAL x)
    REAL round(REAL x)
    REAL scalbln(REAL x, INT e)
    REAL scalbn(REAL x, INT y)
    REAL sin(REAL x)
    REAL sinh(REAL x)
    REAL sqrt(REAL x)
    REAL tan(REAL x)
    REAL tanh(REAL x)
    REAL tgamma(REAL x)
    REAL trunc(REAL x)
    REAL y0(REAL x)
    REAL y1(REAL x)
    REAL yn(INT n, REAL x)

DESCRIPTION

This VMOD wraps the functions in math.h(7), provides additional utilities and includes functions to access macros and constants from math.h(7) and float.h(7).

  Utility functions

  BOOL approx(REAL a, REAL b, REAL maxDiff, REAL maxRelDiff)

    BOOL approx(REAL a, REAL b, REAL maxDiff=0.0, REAL maxRelDiff=0.0)

Return true if the two numbers a and b are approximately equal per the AlmostEqualRelativeAndAbs function from Comparing Floating Point Numbers, 2012 Edition <https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/> given the additional parameters maxDiff and maxRelDiff. Read the blog post for details on why the seemingly simple question of two floating point numbers being equal has no simple answers.

For their default values of 0, the two additional parameters are initialized to:

•   maxDiff: 4 * DBL_EPSILON

•   maxRelDiff: DBL_EPSILON

  STRING strfromd(STRING format, REAL fp)

Convert the value fp into a string using format, see strfromd(3).

An invalid format string results in a VCL error and the NULL invalid string returned.

  Access to macros and constants

  REAL constant(ENUM name)

    REAL constant(
       ENUM {DBL_MANT_DIG, DBL_DIG, DBL_MIN_EXP, DBL_MIN_10_EXP, DBL_MAX_EXP, DBL_MAX_10_EXP, DBL_MAX, DBL_EPSILON, DBL_MIN, HUGE_VAL, M_E, M_LOG2E, M_LOG10E, M_LN2, M_LN10, M_PI, M_PI_2, M_PI_4, M_1_PI, M_2_PI, M_2_SQRTPI, M_SQRT2, M_SQRT1_2} name
    )

Return the value of the named constant. For DBL_* see float.h(7), otherwise math.h(7) for details.

  INT fpclass(ENUM name)

    INT fpclass(
       ENUM {FP_INFINITE, FP_NAN, FP_NORMAL, FP_SUBNORMAL, FP_ZERO} name
    )

Return the value of the named constant for comparisons of math.fpclassify() return values.

  math.h functions

The semantics of functions mapping directly to math.h(7) are not documented herein, see the system documentation instead (for example using man <function>).

  INT fpclassify(REAL x)

  INT isfinite(REAL x)

  INT isgreater(REAL x, REAL y)

  INT isgreaterequal(REAL x, REAL y)

  INT isinf(REAL x)

  INT isless(REAL x, REAL y)

  INT islessequal(REAL x, REAL y)

  INT islessgreater(REAL x, REAL y)

  INT isnan(REAL x)

  INT isnormal(REAL x)

  INT isunordered(REAL x, REAL y)

  INT signbit(REAL x)

  REAL acos(REAL x)

  REAL acosh(REAL x)

  REAL asin(REAL x)

  REAL asinh(REAL x)

  REAL atan(REAL x)

  REAL atan2(REAL y, REAL x)

  REAL atanh(REAL x)

  REAL cbrt(REAL x)

  REAL ceil(REAL x)

  REAL copysign(REAL x, REAL y)

  REAL cos(REAL x)

  REAL cosh(REAL x)

  REAL erf(REAL x)

  REAL erfc(REAL x)

  REAL exp(REAL x)

  REAL exp2(REAL x)

  REAL expm1(REAL x)

  REAL fabs(REAL x)

  REAL fdim(REAL x, REAL y)

  REAL floor(REAL x)

  REAL fma(REAL x, REAL y, REAL z)

  REAL fmax(REAL x, REAL y)

  REAL fmin(REAL x, REAL y)

  REAL fmod(REAL x, REAL y)

  REAL hypot(REAL x, REAL y)

  INT ilogb(REAL x)

  REAL j0(REAL x)

  REAL j1(REAL x)

  REAL jn(INT x, REAL y)

  REAL ldexp(REAL x, INT e)

  REAL lgamma(REAL x)

  REAL log(REAL x)

  REAL log10(REAL x)

  REAL log1p(REAL x)

  REAL log2(REAL x)

  REAL logb(REAL x)

  INT lrint(REAL x)

  INT lround(REAL x)

  REAL nan(STRING tag)

  REAL nearbyint(REAL x)

  REAL nextafter(REAL x, REAL y)

  REAL pow(REAL x, REAL y)

  REAL remainder(REAL x, REAL y)

  REAL rint(REAL x)

  REAL round(REAL x)

  REAL scalbln(REAL x, INT e)

  REAL scalbn(REAL x, INT y)

  REAL sin(REAL x)

  REAL sinh(REAL x)

  REAL sqrt(REAL x)

  REAL tan(REAL x)

  REAL tanh(REAL x)

  REAL tgamma(REAL x)

  REAL trunc(REAL x)

  REAL y0(REAL x)

  REAL y1(REAL x)

  REAL yn(INT n, REAL x)

COPYRIGHT

    This document is licensed under the same conditions as Vinyl Cache itself.
    See LICENSE for details.
    SPDX-License-Identifier: BSD-2-Clause
    Author: Nils Goroll <nils.goroll@uplex.de>