TGMATH(3)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

okay bestie, welcome to tgmath(3) β€” Library Functions Manual β€” and it's giving type-generic macros πŸ’… no cap, this header is lowkey iconic.

πŸ’– NAME πŸ’–

tgmath β€” type-generic macros ✨

πŸŽ€ SYNOPSIS πŸŽ€

#include <tgmath.h>

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so <tgmath.h> hands you type-generic macros for <math.h> and <complex.h> functions that have float (suffixed with f), double, and long double (suffixed with l) versions. The arguments that vary across the three functions and have type float, double, and long double, respectively, are called generic arguments. periodt.

Here are the actual rules for which function gets called when a type-generic macro is invoked, fr fr:

  • If any generic argument has type long double or long double complex, the long double function is called.
  • Else, if any generic argument has type double, double complex, or an integer type, the double version is invoked.
  • Otherwise, the macro expands to the float implementation.

For these macros below, both real and complex functions exist. The real functions are prototyped in <math.h> and the complex equivalents in <complex.h>. The complex function is called if any of the generic arguments is a complex value. Otherwise, the real equivalent is called. iykyk 🌸

  • acos() β€” real function: acos(); complex function: cacos()
  • asin() β€” real function: asin(); complex function: casin()
  • atan() β€” real function: atan(); complex function: catan()
  • acosh() β€” real function: acosh(); complex function: cacosh()
  • asinh() β€” real function: asinh(); complex function: casinh()
  • atanh() β€” real function: atanh(); complex function: catanh()
  • cos() β€” real function: cos(); complex function: ccos()
  • sin() β€” real function: sin(); complex function: csin()
  • tan() β€” real function: tan(); complex function: ctan()
  • cosh() β€” real function: cosh(); complex function: ccosh()
  • sinh() β€” real function: sinh(); complex function: csinh()
  • tanh() β€” real function: tanh(); complex function: ctanh()
  • exp() β€” real function: exp(); complex function: cexp()
  • log() β€” real function: log(); complex function: clog()
  • pow() β€” real function: pow(); complex function: cpow()
  • sqrt() β€” real function: sqrt(); complex function: csqrt()
  • fabs() β€” real function: fabs(); complex function: cabs()

No complex functions exist for the following macros, so passing a complex value to a generic argument invokes undefined behaviour. not me making it dramatic, it's literally in the spec 😭

  • atan2()
  • cbrt()
  • ceil()
  • copysign()
  • erf()
  • erfc()
  • exp2()
  • expm1()
  • fdim()
  • floor()
  • fma()
  • fmax()
  • fmin()
  • fmod()
  • frexp()
  • hypot()
  • ilogb()
  • ldexp()
  • lgamma()
  • llrint()
  • llround()
  • log10()
  • log1p()
  • log2()
  • logb()
  • lrint()
  • lround()
  • nearbyint()
  • nextafter()
  • nexttoward()
  • remainder()
  • remquo()
  • rint()
  • round()
  • scalbn()
  • scalbln()
  • tgamma()
  • trunc()

The following macros always expand to a complex function, no real option, periodt:

  • carg()
  • cimag()
  • conj()
  • cproj()
  • creal()

This header includes <complex.h> and <math.h>. 🫢

🌟 STANDARDS 🌟

The header <tgmath.h> conforms to ISO/IEC 9899:1999 (β€œISO C99”). slay ✨

πŸ’… HISTORY πŸ’…

The header <tgmath.h> first appeared in FreeBSD 5.3. iconic behavior πŸ‘‘

🧚 COMPILER SUPPORT 🧚

Before ISO/IEC 9899:2011 (β€œISO C11”), the header <tgmath.h> could not be implemented with strictly conforming C code and needed special compiler support. As of ISO/IEC 9899:2011 (β€œISO C11”), this header file can be implemented using the _Generic() language keyword. In addition to compilers that support this keyword, this header file works with GCC. 🌈

πŸ’€ BUGS πŸ’€

Many of the functions mentioned here are not prototyped in <math.h> or <complex.h> as they are not yet implemented. This prevents the corresponding type-generic macro from working at all. yeah bestie, that's a real one πŸ˜­πŸ’”


xoxo, from Debian πŸ’– dated January 4, 2012 πŸ’– TGMATH(3) πŸŽ€

πŸ“¦ where this page comes from