vmod_math(3)

πŸ“¦
version 9.1.0 Β· 4 versions
, in arch rolling

🌸 NAME 🌸

okay so this is vmod_math(3) from the Library Functions Manual, bestie β€” and it is literally a VMOD wrapping math.h, no cap.

✨ 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)

BOOL code_coverage(REAL x)

πŸ’– DESCRIPTION πŸ’–

so this VMOD wraps the functions in math.h(7), gives you some extra utility stuff, and also lets you access macros and constants from math.h(7) and float.h(7). it's giving β€œmath class but make it actually useful,” honestly.

🧚 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)

returns true when the two numbers a and b are approximately equal, per the AlmostEqualRelativeAndAbs function from Comparing Floating Point Numbers, 2012 Edition at https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/, using the extra parameters maxDiff and maxRelDiff. read the blog post for the details on why β€œare these two floating point numbers equal?” sounds simple and absolutely is not β€” it has no simple answers, periodt.

when maxDiff and maxRelDiff are left at their default values of 0, the two extra parameters get initialized to:

  • maxDiff: 4 * DBL_EPSILON
  • maxRelDiff: DBL_EPSILON

πŸŽ€ STRING strfromd(STRING format, REAL fp)

turns the value fp into a string using format β€” see strfromd(3) for the details. if format is invalid, you get a VCL error and the NULL invalid string returned. so yeah, invalid format = not the vibe. πŸ™ˆ

πŸŽ€ 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
)

returns the value of the named constant. for the DBL_* ones, check float.h(7); otherwise it's math.h(7) for the details.

πŸ¦‹ INT fpclass(ENUM name)

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

returns the value of the named constant so you can compare against math.fpclassify() return values. lowkey handy.

πŸ¦‹ math.h functions πŸ¦‹

these map directly to math.h(7), and their semantics are not documented here β€” check the system documentation instead, like with man <function>. iykyk.

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)
BOOL code_coverage(REAL x)

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>


okay that's the whole vmod_math(3) page, bestie πŸ’œ the footer/source-version is literally just vmod_math(3) and there's no date attached, so that's the sign-off β€” go forth and math responsibly πŸ’…βœ¨

πŸ“¦ where this page comes from