tgmath.h(3)                POSIX Programmer's Manual               tgmath.h(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.


NNAAMMEE
       tgmath.h -- type-generic macros

SSYYNNOOPPSSIISS
       #include <tgmath.h>

DDEESSCCRRIIPPTTIIOONN
       The functionality described on this reference page is aligned with the
       ISO C standard. Any conflict between the requirements described here
       and the ISO C standard is unintentional. This volume of POSIX.1-2008
       defers to the ISO C standard.

       The _<_t_g_m_a_t_h_._h_> header shall include the headers _<_m_a_t_h_._h_> and
       _<_c_o_m_p_l_e_x_._h_> and shall define several type-generic macros.

       Of the functions contained within the _<_m_a_t_h_._h_> and _<_c_o_m_p_l_e_x_._h_> headers
       without an _f (ffllooaatt) or _l (lloonngg ddoouubbllee) suffix, several have one or
       more parameters whose corresponding real type is ddoouubbllee.  For each such
       function, except _m_o_d_f(), _j_0(), _j_1(), _j_n(), _y_0(), _y_1(), and _y_n(), there
       shall be a corresponding type-generic macro. The parameters whose
       corresponding real type is ddoouubbllee in the function synopsis are generic
       parameters. Use of the macro invokes a function whose corresponding
       real type and type domain are determined by the arguments for the
       generic parameters.

       Use of the macro invokes a function whose generic parameters have the
       corresponding real type determined as follows:

        *  First, if any argument for generic parameters has type lloonngg ddoouubbllee,
           the type determined is lloonngg ddoouubbllee.

        *  Otherwise, if any argument for generic parameters has type ddoouubbllee
           or is of integer type, the type determined is ddoouubbllee.

        *  Otherwise, the type determined is ffllooaatt.

       For each unsuffixed function in the _<_m_a_t_h_._h_> header for which there is
       a function in the _<_c_o_m_p_l_e_x_._h_> header with the same name except for a _c
       prefix, the corresponding type-generic macro (for both functions) has
       the same name as the function in the _<_m_a_t_h_._h_> header. The corresponding
       type-generic macro for _f_a_b_s() and _c_a_b_s() is _f_a_b_s().

           +------------------+----------------------+--------------------+
           |<<mmaatthh..hh>> FFuunnccttiioonn | <<ccoommpplleexx..hh>> FFuunnccttiioonn | TTyyppee--GGeenneerriicc MMaaccrroo |
           +------------------+----------------------+--------------------+
           |_a_c_o_s()            | _c_a_c_o_s()              | _a_c_o_s()             |
           |_a_s_i_n()            | _c_a_s_i_n()              | _a_s_i_n()             |
           |_a_t_a_n()            | _c_a_t_a_n()              | _a_t_a_n()             |
           |_a_c_o_s_h()           | _c_a_c_o_s_h()             | _a_c_o_s_h()            |
           |_a_s_i_n_h()           | _c_a_s_i_n_h()             | _a_s_i_n_h()            |
           |_a_t_a_n_h()           | _c_a_t_a_n_h()             | _a_t_a_n_h()            |
           |_c_o_s()             | _c_c_o_s()               | _c_o_s()              |
           |_s_i_n()             | _c_s_i_n()               | _s_i_n()              |
           |_t_a_n()             | _c_t_a_n()               | _t_a_n()              |
           |_c_o_s_h()            | _c_c_o_s_h()              | _c_o_s_h()             |
           |_s_i_n_h()            | _c_s_i_n_h()              | _s_i_n_h()             |
           |_t_a_n_h()            | _c_t_a_n_h()              | _t_a_n_h()             |
           |_e_x_p()             | _c_e_x_p()               | _e_x_p()              |
           |_l_o_g()             | _c_l_o_g()               | _l_o_g()              |
           |_p_o_w()             | _c_p_o_w()               | _p_o_w()              |
           |_s_q_r_t()            | _c_s_q_r_t()              | _s_q_r_t()             |
           |_f_a_b_s()            | _c_a_b_s()               | _f_a_b_s()             |
           +------------------+----------------------+--------------------+
       If at least one argument for a generic parameter is complex, then use
       of the macro invokes a complex function; otherwise, use of the macro
       invokes a real function.

       For each unsuffixed function in the _<_m_a_t_h_._h_> header without a _c-
       prefixed counterpart in the _<_c_o_m_p_l_e_x_._h_> header, except for _m_o_d_f(),
       _j_0(), _j_1(), _j_n(), _y_0(), _y_1(), and _y_n(), the corresponding type-generic
       macro has the same name as the function.  These type-generic macros
       are:


              _a_t_a_n_2()      _f_m_a()      _l_l_r_o_u_n_d()      _r_e_m_a_i_n_d_e_r()
              _c_b_r_t()       _f_m_a_x()     _l_o_g_1_0()        _r_e_m_q_u_o()
              _c_e_i_l()       _f_m_i_n()     _l_o_g_1_p()        _r_i_n_t()
              _c_o_p_y_s_i_g_n()   _f_m_o_d()     _l_o_g_2()         _r_o_u_n_d()
              _e_r_f()        _f_r_e_x_p()    _l_o_g_b()         _s_c_a_l_b_l_n()
              _e_r_f_c()       _h_y_p_o_t()    _l_r_i_n_t()        _s_c_a_l_b_n()
              _e_x_p_2()       _i_l_o_g_b()    _l_r_o_u_n_d()       _t_g_a_m_m_a()
              _e_x_p_m_1()      _l_d_e_x_p()    _n_e_a_r_b_y_i_n_t()    _t_r_u_n_c()
              _f_d_i_m()       _l_g_a_m_m_a()   _n_e_x_t_a_f_t_e_r()
              _f_l_o_o_r()      _l_l_r_i_n_t()   _n_e_x_t_t_o_w_a_r_d()

       If all arguments for generic parameters are real, then use of the macro
       invokes a real function; otherwise, use of the macro results in
       undefined behavior.

       For each unsuffixed function in the _<_c_o_m_p_l_e_x_._h_> header that is not a _c-
       prefixed counterpart to a function in the _<_m_a_t_h_._h_> header, the
       corresponding type-generic macro has the same name as the function.
       These type-generic macros are:

              _c_a_r_g() _c_i_m_a_g() _c_o_n_j() _c_p_r_o_j() _c_r_e_a_l()

       Use of the macro with any real or complex argument invokes a complex
       function.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       With the declarations:

           ##iinncclluuddee <<ttggmmaatthh..hh>>
           iinntt nn;;
           ffllooaatt ff;;
           ddoouubbllee dd;;
           lloonngg ddoouubbllee lldd;;
           ffllooaatt ccoommpplleexx ffcc;;
           ddoouubbllee ccoommpplleexx ddcc;;
           lloonngg ddoouubbllee ccoommpplleexx llddcc;;

       functions invoked by use of type-generic macros are shown in the
       following table:

                 +-----------------+-------------------------------+
                 |     MMaaccrroo       |          UUssee IInnvvookkeess          |
                 +-----------------+-------------------------------+
                 |_e_x_p(_n)           | _e_x_p(_n), the function          |
                 |_a_c_o_s_h(_f)         | _a_c_o_s_h_f(_f)                     |
                 |_s_i_n(_d)           | _s_i_n(_d), the function          |
                 |_a_t_a_n(_l_d)         | _a_t_a_n_l(_l_d)                     |
                 |_l_o_g(_f_c)          | _c_l_o_g_f(_f_c)                     |
                 |_s_q_r_t(_d_c)         | _c_s_q_r_t(_d_c)                     |
                 |_p_o_w(_l_d_c_,_f)       | _c_p_o_w_l(_l_d_c_, _f)                 |
                 |_r_e_m_a_i_n_d_e_r(_n_,_n)   | _r_e_m_a_i_n_d_e_r(_n_, _n), the function |
                 |_n_e_x_t_a_f_t_e_r(_d_,_f)   | _n_e_x_t_a_f_t_e_r(_d_, _f), the function |
                 |_n_e_x_t_t_o_w_a_r_d(_f_,_l_d) | _n_e_x_t_t_o_w_a_r_d_f(_f_, _l_d)            |
                 |_c_o_p_y_s_i_g_n(_n_,_l_d)   | _c_o_p_y_s_i_g_n_l(_n_, _l_d)              |
                 |_c_e_i_l(_f_c)         | Undefined behavior            |
                 |_r_i_n_t(_d_c)         | Undefined behavior            |
                 |_f_m_a_x(_l_d_c_,_l_d)     | Undefined behavior            |
                 |_c_a_r_g(_n)          | _c_a_r_g(_n), the function         |
                 |_c_p_r_o_j(_f)         | _c_p_r_o_j_f(_f)                     |
                 |_c_r_e_a_l(_d)         | _c_r_e_a_l(_d), the function        |
                 |_c_i_m_a_g(_l_d)        | _c_i_m_a_g_l(_l_d)                    |
                 |_c_a_b_s(_f_c)         | _c_a_b_s_f(_f_c)                     |
                 |_c_a_r_g(_d_c)         | _c_a_r_g(_d_c), the function        |
                 |_c_p_r_o_j(_l_d_c)       | _c_p_r_o_j_l(_l_d_c)                   |
                 +-----------------+-------------------------------+
RRAATTIIOONNAALLEE
       Type-generic macros allow calling a function whose type is determined
       by the argument type, as is the case for C operators such as ''++'' and
       ''**''.  For example, with a type-generic _c_o_s() macro, the expression
       _c_o_s((ffllooaatt)_x) will have type ffllooaatt.  This feature enables writing more
       portably efficient code and alleviates need for awkward casting and
       suffixing in the process of porting or adjusting precision. Generic
       math functions are a widely appreciated feature of Fortran.

       The only arguments that affect the type resolution are the arguments
       corresponding to the parameters that have type ddoouubbllee in the synopsis.
       Hence the type of a type-generic call to _n_e_x_t_t_o_w_a_r_d(), whose second
       parameter is lloonngg ddoouubbllee in the synopsis, is determined solely by the
       type of the first argument.

       The term ``type-generic'' was chosen over the proposed alternatives of
       intrinsic and overloading. The term is more specific than intrinsic,
       which already is widely used with a more general meaning, and reflects
       a closer match to Fortran's generic functions than to C++ overloading.

       The macros are placed in their own header in order not to silently
       break old programs that include the _<_m_a_t_h_._h_> header; for example, with:

           pprriinnttff ((""%%ee"",, ssiinn((xx))))

       _m_o_d_f(ddoouubbllee, ddoouubbllee **) is excluded because no way was seen to make it
       safe without complicating the type resolution.

       The implementation might, as an extension, endow appropriate ones of
       the macros that POSIX.1-2008 specifies only for real arguments with the
       ability to invoke the complex functions.

       POSIX.1-2008 does not prescribe any particular implementation mechanism
       for generic macros. It could be implemented simply with built-in
       macros. The generic macro for _s_q_r_t(), for example, could be implemented
       with:

           ##uunnddeeff ssqqrrtt
           ##ddeeffiinnee ssqqrrtt((xx)) ____BBUUIILLTTIINN__GGEENNEERRIICC__ssqqrrtt((xx))

       Generic macros are designed for a useful level of consistency with C++
       overloaded math functions.

       The great majority of existing C programs are expected to be unaffected
       when the _<_t_g_m_a_t_h_._h_> header is included instead of the _<_m_a_t_h_._h_> or
       _<_c_o_m_p_l_e_x_._h_> headers. Generic macros are similar to the
       ISO/IEC 9899:1999 standard library masking macros, though the semantic
       types of return values differ.

       The ability to overload on integer as well as floating types would have
       been useful for some functions; for example, _c_o_p_y_s_i_g_n().  Overloading
       with different numbers of arguments would have allowed reusing names;
       for example, _r_e_m_a_i_n_d_e_r() for _r_e_m_q_u_o().  However, these facilities would
       have complicated the specification; and their natural consistent use,
       such as for a floating _a_b_s() or a two-argument _a_t_a_n(), would have
       introduced further inconsistencies with the ISO/IEC 9899:1999 standard
       for insufficient benefit.

       The ISO C standard in no way limits the implementation's options for
       efficiency, including inlining library functions.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       <<mmaatthh..hh>>, <<ccoommpplleexx..hh>>

       The System Interfaces volume of POSIX.1-2008, _c_a_b_s(), _f_a_b_s(), _m_o_d_f()

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
       event of any discrepancy between this version and the original IEEE and
       The Open Group Standard, the original IEEE and The Open Group Standard
       is the referee document. The original Standard can be obtained online
       at http://www.unix.org/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2013                          tgmath.h(3)
