{
    "content": [
        {
            "type": "text",
            "text": "# MATH_ERROR (info)\n\n## NAME\n\nmatherror - detecting errors from mathematical functions\n\n## SYNOPSIS\n\n#include <math.h>\n#include <errno.h>\n#include <fenv.h>\n\n## DESCRIPTION\n\nWhen  an error occurs, most library functions indicate this fact by re-\nturning a special value (e.g., -1 or NULL).  Because they typically re-\nturn  a  floating-point  number, the mathematical functions declared in\n<math.h> indicate an error using other mechanisms.  There are  two  er-\nror-reporting  mechanisms: the older one sets errno; the newer one uses\nthe floating-point exception mechanism (the use of feclearexcept(3) and\nfetestexcept(3), as outlined below) described in fenv(3).\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **NOTES**\n- **SEE ALSO**\n- **COLOPHON**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "MATH_ERROR",
        "section": "",
        "mode": "info",
        "summary": "matherror - detecting errors from mathematical functions",
        "synopsis": "#include <math.h>\n#include <errno.h>\n#include <fenv.h>",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "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"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 72,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 34,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "COLOPHON",
                "lines": 6,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "matherror - detecting errors from mathematical functions\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "#include <math.h>\n#include <errno.h>\n#include <fenv.h>\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "When  an error occurs, most library functions indicate this fact by re-\nturning a special value (e.g., -1 or NULL).  Because they typically re-\nturn  a  floating-point  number, the mathematical functions declared in\n<math.h> indicate an error using other mechanisms.  There are  two  er-\nror-reporting  mechanisms: the older one sets errno; the newer one uses\nthe floating-point exception mechanism (the use of feclearexcept(3) and\nfetestexcept(3), as outlined below) described in fenv(3).\n\nA portable program that needs to check for an error from a mathematical\nfunction should set errno 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\nfollowing call (see fenv(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 de-\nscribed below.\n\nDomain error\nA domain error occurs when a mathematical function is supplied with  an\nargument whose value falls outside the domain for which the function is\ndefined (e.g., giving a negative argument to log(3)).   When  a  domain\nerror  occurs,  math functions commonly return a NaN (though some func-\ntions return a different value in this case); errno is set to EDOM, and\nan \"invalid\" (FEINVALID) floating-point exception is raised.\n\nPole error\nA  pole  error  occurs when the mathematical result of a function is an\nexact infinity (e.g., the logarithm of 0 is negative infinity).  When a\npole  error  occurs,  the function returns the (signed) value HUGEVAL,\nHUGEVALF, or HUGEVALL, depending on whether the function result  type\nis double, float, or long double.  The sign of the result is that which\nis mathematically correct for the function.  errno is  set  to  ERANGE,\nand  a  \"divide-by-zero\"  (FEDIVBYZERO)  floating-point  exception  is\nraised.\n\nRange error\nA range error occurs when the magnitude of the  function  result  means\nthat  it cannot be represented in the result type of the function.  The\nreturn value of the function depends on whether the range error was  an\noverflow or an underflow.\n\nA  floating  result overflows if the result is finite, but is too large\nto represented in the result type.  When an overflow occurs, the  func-\ntion  returns the value HUGEVAL, HUGEVALF, or HUGEVALL, depending on\nwhether the function result type is double, float, or long double.  er-\nrno  is  set  to ERANGE, and an \"overflow\" (FEOVERFLOW) floating-point\nexception is raised.\n\nA floating result underflows if the result is too small  to  be  repre-\nsented  in  the  result  type.   If an underflow occurs, a mathematical\nfunction typically returns 0.0 (C99 says a function  shall  return  \"an\nimplementation-defined  value  whose  magnitude  is no greater than the\nsmallest normalized positive number in the specified type\").  errno may\nbe  set to ERANGE, and an \"underflow\" (FEUNDERFLOW) floating-point ex-\nception may be raised.\n\nSome functions deliver a range error if the supplied argument value, or\nthe  correct function result, would be subnormal.  A subnormal value is\none that is nonzero, but with a magnitude that  is  so  small  that  it\ncan't  be presented in normalized form (i.e., with a 1 in the most sig-\nnificant bit of the significand).  The representation  of  a  subnormal\nnumber will contain one or more leading zeros in the significand.\n",
                "subsections": []
            },
            "NOTES": {
                "content": "The  matherrhandling  identifier  specified  by C99 and POSIX.1 is not\nsupported by glibc.  This identifier is supposed to indicate  which  of\nthe  two  error-notification  mechanisms (errno, exceptions retrievable\nvia fetestexcept(3)) is in use.  The standards require  that  at  least\none  be  in use, but permit both to be available.  The current (version\n2.8) situation under glibc is messy.   Most  (but  not  all)  functions\nraise  exceptions on errors.  Some also set errno.  A few functions set\nerrno, but don't raise an exception.  A very few functions do  neither.\nSee the individual manual pages for details.\n\nTo  avoid the complexities of using errno and fetestexcept(3) for error\nchecking, it is often advised that one should instead check for bad ar-\ngument  values  before  each call.  For example, the following code en-\nsures that log(3)'s argument is not a NaN and is not zero (a  pole  er-\nror) or 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\nfunctions (i.e., those declared by <complex.h>), which in  general  are\nnot required to return errors by C99 and POSIX.1.\n\nThe  gcc(1)  -fno-math-errno option causes the executable to employ im-\nplementations of some mathematical functions that are faster  than  the\nstandard  implementations,  but do not set errno on error.  (The gcc(1)\n-ffast-math option also enables -fno-math-errno.)  An error  can  still\nbe tested for using fetestexcept(3).\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "gcc(1),  errno(3),  fenv(3),  fpclassify(3), INFINITY(3), isgreater(3),\nmatherr(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\ndescription  of  the project, information about reporting bugs, and the\nlatest    version    of    this    page,    can     be     found     at\nhttps://www.kernel.org/doc/man-pages/.\n\nLinux                             2017-09-15                     MATHERROR(7)",
                "subsections": []
            }
        }
    }
}