{
    "mode": "man",
    "parameter": "math_error",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/math_error/7/json",
    "generated": "2026-06-02T23:30:23Z",
    "synopsis": "",
    "sections": {
        "NAME": {
            "content": "matherror - detecting errors from mathematical functions\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "",
            "subsections": [
                {
                    "name": "#include <math.h>",
                    "content": ""
                },
                {
                    "name": "#include <errno.h>",
                    "content": ""
                },
                {
                    "name": "#include <fenv.h>",
                    "content": ""
                }
            ]
        },
        "DESCRIPTION": {
            "content": "When  an error occurs, most library functions indicate this fact by returning a special value\n(e.g., -1 or NULL).  Because they typically return a floating-point number, the  mathematical\nfunctions  declared  in <math.h> indicate an error using other mechanisms.  There are two er‐\nror-reporting mechanisms: the older one sets errno; the newer one uses the floating-point ex‐\nception  mechanism  (the  use of feclearexcept(3) and fetestexcept(3), as outlined below) de‐\nscribed in fenv(3).\n\nA portable program that needs to check for an error from a mathematical function  should  set\nerrno to zero, and make the following call\n\nfeclearexcept(FEALLEXCEPT);\n\nbefore calling a mathematical function.\n\nUpon  return  from the mathematical function, if errno is nonzero, or the following call (see\nfenv(3)) returns nonzero\n\nfetestexcept(FEINVALID | FEDIVBYZERO | FEOVERFLOW |\nFEUNDERFLOW);\n\nthen an error occurred in the mathematical function.\n\nThe error conditions that can occur for mathematical functions are described below.\n",
            "subsections": [
                {
                    "name": "Domain error",
                    "content": "A domain error occurs when a mathematical function is supplied with an argument  whose  value\nfalls  outside the domain for which the function is defined (e.g., giving a negative argument\nto log(3)).  When a domain error occurs, math functions commonly return a  NaN  (though  some\nfunctions  return  a  different  value  in this case); errno is set to EDOM, and an \"invalid\"\n(FEINVALID) floating-point exception is raised.\n"
                },
                {
                    "name": "Pole error",
                    "content": "A pole error occurs when the mathematical result of a function is an  exact  infinity  (e.g.,\nthe logarithm of 0 is negative infinity).  When a pole error occurs, the function returns the\n(signed) value HUGEVAL, HUGEVALF, or HUGEVALL, depending on whether  the  function  result\ntype  is  double,  float, or long double.  The sign of the result is that which is mathemati‐\ncally correct for the function.  errno is set  to  ERANGE,  and  a  \"divide-by-zero\"  (FEDI‐‐\nVBYZERO) floating-point exception is raised.\n"
                },
                {
                    "name": "Range error",
                    "content": "A range error occurs when the magnitude of the function result means that it cannot be repre‐\nsented in the result type of the function.  The return  value  of  the  function  depends  on\nwhether the range error was an overflow or an underflow.\n\nA  floating  result overflows if the result is finite, but is too large to represented in the\nresult type.  When an overflow occurs, the function returns the value HUGEVAL, HUGEVALF, or\nHUGEVALL,  depending  on  whether the function result type is double, float, or long double.\nerrno is set to ERANGE, and an \"overflow\" (FEOVERFLOW) floating-point exception is raised.\n\nA floating result underflows if the result is too small to be represented in the result type.\nIf  an  underflow  occurs, a mathematical function typically returns 0.0 (C99 says a function\nshall return \"an implementation-defined value whose magnitude is no greater than the smallest\nnormalized  positive number in the specified type\").  errno may be set to ERANGE, and an \"un‐\nderflow\" (FEUNDERFLOW) floating-point exception may be raised.\n\nSome functions deliver a range error if the supplied argument value, or the correct  function\nresult,  would  be subnormal.  A subnormal value is one that is nonzero, but with a magnitude\nthat is so small that it can't be presented in normalized form (i.e., with a 1  in  the  most\nsignificant  bit  of the significand).  The representation of a subnormal number will contain\none or more leading zeros in the significand.\n"
                }
            ]
        },
        "NOTES": {
            "content": "The matherrhandling identifier specified by C99 and POSIX.1 is not supported by glibc.  This\nidentifier is supposed to indicate which of the two error-notification mechanisms (errno, ex‐\nceptions retrievable via fetestexcept(3)) is in use.  The standards require that at least one\nbe  in use, but permit both to be available.  The current (version 2.8) situation under glibc\nis messy.  Most (but not all) functions raise exceptions on errors.  Some also set errno.   A\nfew functions set errno, but don't raise an exception.  A very few functions do neither.  See\nthe individual manual pages for details.\n\nTo avoid the complexities of using errno and fetestexcept(3) for error checking, it is  often\nadvised that one should instead check for bad argument values before each call.  For example,\nthe following code ensures that log(3)'s argument is not a NaN and is not zero (a pole error)\nor less than zero (a domain error):\n\ndouble x, r;\n\nif (isnan(x) || islessequal(x, 0)) {\n/* Deal with NaN / pole error / domain error */\n}\n\nr = log(x);\n\nThe discussion on this page does not apply to the complex mathematical functions (i.e., those\ndeclared by <complex.h>), which in general are not required  to  return  errors  by  C99  and\nPOSIX.1.\n\nThe  gcc(1)  -fno-math-errno  option  causes the executable to employ implementations of some\nmathematical functions that are faster than the standard implementations, but do not set  er‐\nrno  on  error.   (The gcc(1) -ffast-math option also enables -fno-math-errno.)  An error can\nstill be tested for using fetestexcept(3).\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "gcc(1), errno(3), fenv(3), fpclassify(3), INFINITY(3), isgreater(3), matherr(3), nan(3)\n\ninfo libc\n",
            "subsections": []
        },
        "COLOPHON": {
            "content": "This page is part of release 5.10 of the Linux  man-pages  project.   A  description  of  the\nproject,  information about reporting bugs, and the latest version of this page, can be found\nat https://www.kernel.org/doc/man-pages/.\n\n\n\nLinux                                        2017-09-15                                MATHERROR(7)",
            "subsections": []
        }
    },
    "summary": "matherror - detecting errors from mathematical functions",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "gcc",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/gcc/1/json"
        },
        {
            "name": "errno",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/errno/3/json"
        },
        {
            "name": "fenv",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/fenv/3/json"
        },
        {
            "name": "fpclassify",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/fpclassify/3/json"
        },
        {
            "name": "INFINITY",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/INFINITY/3/json"
        },
        {
            "name": "isgreater",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/isgreater/3/json"
        },
        {
            "name": "matherr",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/matherr/3/json"
        },
        {
            "name": "nan",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/nan/3/json"
        }
    ]
}