Topic: What Is a Domain Error?


Author: jdavison@shell.inch.com (John Michael Davison)
Date: 1999/03/24
Raw View
        In reference to Section 19.1.2 (p. 350) of ISO/IEC 14882:1998(E), I
asked:

>         What is a "domain error?"

        James Kuyper ("kuyper@wizard.net") writes:

>The set of values that a function can take as arguments is called the
>function's domain. A domain error occurs when the function is passed an
>argument which is outside its domain.

        Isn't this what the "invalid_argument" exception is for?

>A few simple examples are log(-0.5), sqrt(-1.0), acos(-2.0), . These are all
>perfectly well defined for complex numbers, but for a real-valued functions,
>they're all domain errors.

        Is it fair to say that a "domain error" (in the context of Section
19.1.2 (p. 350) of ISO/IEC 14882:1998(E)) is specific to real-valued
(typically transcendental) functions whose domains are proper subsets of type
"float"?

        Robert Youdan ("rob@event-horizons.com.au") says something like this:

>Any mathematical operation for which there is no real solution (ie may result
>in NAN) is a domain error. Examples which should cause domain errors are: 0.0
>/ 0.0, asin(2.0), sqrt(-1.0).

        William Roeder ("roeder@titan.com") gives some examples but no
definiton:

>square root(-1), sine(4), singularities.

        George W. Bayles ("georgeb@cajunbro.com") writes:

>I'm guessing its the kind of error that happens when the parameter you pass to
>a function has a value that isn't within the "domain" of the function. For
>example, asin(x) and acos(x) are defined for values of x in the range -1.0 and
>+1.0 inclusive.

        It appears that I'm not the only one who isn't exactly sure what a
"domain error" is.

        Clarification would be appreciated.  (A defect report or request for
clarification would be appreciated too!  The phrase "domain error" is much too
vague.)

        Thanks to James Kuyper, Robert Youdan, William Roeder, and George W.
Bayles for responding.
--
John Davison
jdavison@inch.com


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: jdavison@shell.inch.com (John Michael Davison)
Date: 1999/03/24
Raw View
        Section 19.1.2 (p. 350) of ISO/IEC 14882:1998(E) says:

          The class domain_error defines the type of objects thrown
          as exceptions by the implementation to report domain
          errors.

        What is a "domain error?"
--
John Davison
jdavison@inch.com
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]