* math_error.7 draft 4, for review
@ 2008-07-21 10:23 Michael Kerrisk
[not found] ` <cfd18e0f0807210323m4912a31pa5359c2b7409167c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Michael Kerrisk @ 2008-07-21 10:23 UTC (permalink / raw)
To: aj-Et1tbQHTxzrQT0dZR+AlfA
Cc: Fabian Kreutz, Andrew Morgan, linux-man-u79uwXL29TY76Z2rM5mHXA
[Ooops -- wrong list CCed on previous mail; and this time, I'll update
the draft number]
Andreas,
The latest version of the page is below.
===
Hi Andreas,
(Andries suggested that you probably have the background knowledge to
help here.)
The math man pages in man-pages are in a somewhat sorry state, with
respect to the following:
* Few of the pages properly describe the special cases for Inf, -Inf,
NaN arguments (e.g., compare "man 3 log" with the POSIX.1 page "man 3p
log").
* There isn't a clear discussion of error cases, and how to determine
if an error occurrred using errno and/or fetestexcept(3).
I'm planning to fix each of the math man pages to address these
issues, and use a new page, math_error.7, as an anchor page referenced
by all of the math pages for discussion of how to handle errors.
Would you be willing to review this new page (below) to see whether it
correctly describes the glibc details? Might you also be willing to
look at a sampling of the changed math page pages that I'll make later
this week/early next week in order to let me know I'm on the right
track in terms of the changes I'm making?
Cheers,
Michael
.\" Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk
.\" <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.TH MATH_ERROR 7 2008-07-21 "Linux" "Linux Programmer's Manual"
.SH SYNOPSIS
.nf
.B #include <math.h>
.B #include <errno.h>
.B #include <fenv.h>
.fi
.SH NAME
math_error \- detecting errors from mathematical functions
.SH DESCRIPTION
On error, many of the mathematical functions declared in
.IR <math.h>
return a NaN (not a number).
However, rather than looking at the return value
(which is not always possible)
one can also check whether an error was signaled.
There are two signaling mechanisms:
the older one sets
.IR errno ;
the newer one uses the floating-point exception mechanism (the use of
.BR feclearexcept (3)
and
.BR fetestexcept (3),
as outlined below)
described in
.BR fenv (3).
C99 and POSIX.1-2001 specify a
.I math_errhandling
identifier,
which is supposed to indicate which of these two mechanisms is in use;
the standards require that at least one be in use,
but permit both to be available.
Although glibc does not support this identifier,
in practice it supports both mechanisms.
A portable program that needs to check for an error from a mathematical
function should set
.I errno
to zero, and make the following call
.in +4n
.nf
feclearexcept(FE_ALL_EXCEPT);
.fi
.in
before calling a mathematical function.
Upon return from the mathematical function, if
.I errno
is non-zero, or the following call (see
.BR fenv (3))
returns non-zero
.in +4n
.nf
fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW |
FE_UNDERFLOW);
.fi
.in
.\" enum
.\" {
.\" FE_INVALID = 0x01,
.\" __FE_DENORM = 0x02,
.\" FE_DIVBYZERO = 0x04,
.\" FE_OVERFLOW = 0x08,
.\" FE_UNDERFLOW = 0x10,
.\" FE_INEXACT = 0x20
.\" };
then an error occurred in the mathematical function.
The error conditions that can occur for mathematical functions
are described below.
.SS Domain Error
A
.I domain error
occurs when a mathematical function is supplied with an argument whose
value falls outside the domain for which the function
is defined (e.g., giving a negative argument to
.BR log (3)).
When a domain error occurs,
.I errno
is set to
.BR EDOM ,
and an "invalid"
.RB ( FE_INVALID )
floating-point exception is raised.
.SS Pole Error
A
.I pole error
occurs when the mathematical result of a function is an exact infinity
(e.g., the logarithm of 0 is negative infinity).
When a pole error occurs,
the function returns the (signed) value
.BR HUGE_VAL ,
.BR HUGE_VALF ,
or
.BR HUGE_VALL ,
depending on whether the function result type is
.IR double ,
.IR float ,
or
.IR "long double" .
The sign of the result is that which is mathematically correct for
the function.
.I errno
is set to
.BR ERANGE ,
and a "divide-by-zero"
.RB ( FE_DIVBYZERO )
floating-point exception is raised.
.SS Range Error
A
.I range error
occurs when the magnitude of the function result means that it
cannot be represented in the result type of the function.
The return value of the function depends on whether the range error
was an overflow or an underflow.
A floating result
.I overflows
if the result is finite,
but is too large to represented in the result type.
When an overflow occurs,
the function returns the value
.BR HUGE_VAL ,
.BR HUGE_VALF ,
or
.BR HUGE_VALL ,
depending on whether the function result type is
.IR double ,
.IR float ,
or
.IR "long double" .
.I errno
is set to
.BR ERANGE ,
and an "overflow"
.RB ( FE_OVERFLOW )
floating-point exception is raised.
A floating result
.I underflows
if the result is too small to be represented in the result type.
If an underflow occurs,
a mathematical function typically returns 0.0
(C99 says a function shall return "an implementation-defined value
whose magnitude is no greater than the smallest normalized
positive number in the specified type").
.\" FIXME(mtk) POSIX.1 says "may" for the following two cases; need to
.\" investigate this further for specific functions.
.I errno
may be set to
.BR ERANGE ,
and an "overflow"
.RB ( FE_UNDERFLOW )
floating-point exception may be raised.
Some functions deliver a range error if the supplied argument value,
or the correct function result, would be
.IR subnormal .
A subnormal value is one that is non-zero,
but with a magnitude that is so small that
it can't be presented in normalized form
(i.e., with a 1 in the most significant bit of the significand).
The representation of a subnormal number will contain one
or more leading zeros in the significand.
.SH NOTES
The
.I math_errhandling
identifier specified by C99 and POSIX.1-2001 is not supported.
.\" See CONFORMANCE in the glibc 2.8 (and earlier) source.
To avoid the complexities of using
.I errno
and
.BR fetestexcept (3)
for error checking,
it is often advised that one should instead check for bad argument
values before each call.
.\" http://www.securecoding.cert.org/confluence/display/seccode/FLP32-C.+Prevent+or+detect+domain+and+range+errors+in+math+functions
For example, the following code ensures that
.BR log (3)'s
argument is not a NaN and is not zero (a pole error) or
less than zero (a domain error):
.in +4n
.nf
double x, r;
if (isnan(x) || islessequal(x, 0)) {
/* Deal with NaN / pole error / domain error */
}
r = log(x);
.fi
.in
The discussion on this page does not apply to the complex
mathematical functions (i.e., those declared by
.IR <complex.h> ),
which in general are not required to return errors by C99
and POSIX.1-2001.
The
.BR gcc (1)
.I "-fno-math-errno"
option causes the executable to employ implementations of some
mathematical functions that are faster than the standard
implementations, but do not set
.I errno
on error.
(The
.BR gcc (1)
.I "-ffast-math"
option also enables
.IR "-fno-math-errno" .)
An error can still be tested for using
.BR fetestexcept (3).
.fi
.in
.SH SEE ALSO
.BR gcc (1),
.BR errno (3),
.BR fenv (3),
.BR fpclassify (3),
.BR INFINITY (3),
.BR isgreater (3),
.BR matherr (3),
.BR nan (3)
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread[parent not found: <cfd18e0f0807210323m4912a31pa5359c2b7409167c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: math_error.7 draft 4, for review [not found] ` <cfd18e0f0807210323m4912a31pa5359c2b7409167c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2008-07-21 10:25 ` Michael Kerrisk [not found] ` <cfd18e0f0807210325m7606441as19811b6802661a8c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 11+ messages in thread From: Michael Kerrisk @ 2008-07-21 10:25 UTC (permalink / raw) To: aj-Et1tbQHTxzrQT0dZR+AlfA Cc: Fabian Kreutz, Andries Brouwer, linux-man-u79uwXL29TY76Z2rM5mHXA [CC+= Andries] On Mon, Jul 21, 2008 at 12:23 PM, Michael Kerrisk <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > [Ooops -- wrong list CCed on previous mail; and this time, I'll update > the draft number] > > Andreas, > > The latest version of the page is below. > > === > > Hi Andreas, > > (Andries suggested that you probably have the background knowledge to > help here.) > > The math man pages in man-pages are in a somewhat sorry state, with > respect to the following: > > * Few of the pages properly describe the special cases for Inf, -Inf, > NaN arguments (e.g., compare "man 3 log" with the POSIX.1 page "man 3p > log"). > > * There isn't a clear discussion of error cases, and how to determine > if an error occurrred using errno and/or fetestexcept(3). > > I'm planning to fix each of the math man pages to address these > issues, and use a new page, math_error.7, as an anchor page referenced > by all of the math pages for discussion of how to handle errors. > > Would you be willing to review this new page (below) to see whether it > correctly describes the glibc details? Might you also be willing to > look at a sampling of the changed math page pages that I'll make later > this week/early next week in order to let me know I'm on the right > track in terms of the changes I'm making? > > Cheers, > > Michael > > > .\" Copyright (c) 2008, Linux Foundation, written by Michael Kerrisk > .\" <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > .\" > .\" Permission is granted to make and distribute verbatim copies of this > .\" manual provided the copyright notice and this permission notice are > .\" preserved on all copies. > .\" > .\" Permission is granted to copy and distribute modified versions of this > .\" manual under the conditions for verbatim copying, provided that the > .\" entire resulting derived work is distributed under the terms of a > .\" permission notice identical to this one. > .\" > .\" Since the Linux kernel and libraries are constantly changing, this > .\" manual page may be incorrect or out-of-date. The author(s) assume no > .\" responsibility for errors or omissions, or for damages resulting from > .\" the use of the information contained herein. The author(s) may not > .\" have taken the same level of care in the production of this manual, > .\" which is licensed free of charge, as they might when working > .\" professionally. > .\" > .\" Formatted or processed versions of this manual, if unaccompanied by > .\" the source, must acknowledge the copyright and authors of this work. > .\" > .TH MATH_ERROR 7 2008-07-21 "Linux" "Linux Programmer's Manual" > .SH SYNOPSIS > .nf > .B #include <math.h> > .B #include <errno.h> > .B #include <fenv.h> > .fi > .SH NAME > math_error \- detecting errors from mathematical functions > .SH DESCRIPTION > On error, many of the mathematical functions declared in > .IR <math.h> > return a NaN (not a number). > However, rather than looking at the return value > (which is not always possible) > one can also check whether an error was signaled. > There are two signaling mechanisms: > the older one sets > .IR errno ; > the newer one uses the floating-point exception mechanism (the use of > .BR feclearexcept (3) > and > .BR fetestexcept (3), > as outlined below) > described in > .BR fenv (3). > > C99 and POSIX.1-2001 specify a > .I math_errhandling > identifier, > which is supposed to indicate which of these two mechanisms is in use; > the standards require that at least one be in use, > but permit both to be available. > Although glibc does not support this identifier, > in practice it supports both mechanisms. > > A portable program that needs to check for an error from a mathematical > function should set > .I errno > to zero, and make the following call > .in +4n > .nf > > feclearexcept(FE_ALL_EXCEPT); > > .fi > .in > before calling a mathematical function. > > Upon return from the mathematical function, if > .I errno > is non-zero, or the following call (see > .BR fenv (3)) > returns non-zero > .in +4n > .nf > > fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | > FE_UNDERFLOW); > > .fi > .in > .\" enum > .\" { > .\" FE_INVALID = 0x01, > .\" __FE_DENORM = 0x02, > .\" FE_DIVBYZERO = 0x04, > .\" FE_OVERFLOW = 0x08, > .\" FE_UNDERFLOW = 0x10, > .\" FE_INEXACT = 0x20 > .\" }; > then an error occurred in the mathematical function. > > The error conditions that can occur for mathematical functions > are described below. > .SS Domain Error > A > .I domain error > occurs when a mathematical function is supplied with an argument whose > value falls outside the domain for which the function > is defined (e.g., giving a negative argument to > .BR log (3)). > When a domain error occurs, > .I errno > is set to > .BR EDOM , > and an "invalid" > .RB ( FE_INVALID ) > floating-point exception is raised. > .SS Pole Error > A > .I pole error > occurs when the mathematical result of a function is an exact infinity > (e.g., the logarithm of 0 is negative infinity). > When a pole error occurs, > the function returns the (signed) value > .BR HUGE_VAL , > .BR HUGE_VALF , > or > .BR HUGE_VALL , > depending on whether the function result type is > .IR double , > .IR float , > or > .IR "long double" . > The sign of the result is that which is mathematically correct for > the function. > .I errno > is set to > .BR ERANGE , > and a "divide-by-zero" > .RB ( FE_DIVBYZERO ) > floating-point exception is raised. > .SS Range Error > A > .I range error > occurs when the magnitude of the function result means that it > cannot be represented in the result type of the function. > The return value of the function depends on whether the range error > was an overflow or an underflow. > > A floating result > .I overflows > if the result is finite, > but is too large to represented in the result type. > When an overflow occurs, > the function returns the value > .BR HUGE_VAL , > .BR HUGE_VALF , > or > .BR HUGE_VALL , > depending on whether the function result type is > .IR double , > .IR float , > or > .IR "long double" . > .I errno > is set to > .BR ERANGE , > and an "overflow" > .RB ( FE_OVERFLOW ) > floating-point exception is raised. > > A floating result > .I underflows > if the result is too small to be represented in the result type. > If an underflow occurs, > a mathematical function typically returns 0.0 > (C99 says a function shall return "an implementation-defined value > whose magnitude is no greater than the smallest normalized > positive number in the specified type"). > .\" FIXME(mtk) POSIX.1 says "may" for the following two cases; need to > .\" investigate this further for specific functions. > .I errno > may be set to > .BR ERANGE , > and an "overflow" > .RB ( FE_UNDERFLOW ) > floating-point exception may be raised. > > Some functions deliver a range error if the supplied argument value, > or the correct function result, would be > .IR subnormal . > A subnormal value is one that is non-zero, > but with a magnitude that is so small that > it can't be presented in normalized form > (i.e., with a 1 in the most significant bit of the significand). > The representation of a subnormal number will contain one > or more leading zeros in the significand. > .SH NOTES > The > .I math_errhandling > identifier specified by C99 and POSIX.1-2001 is not supported. > .\" See CONFORMANCE in the glibc 2.8 (and earlier) source. > > To avoid the complexities of using > .I errno > and > .BR fetestexcept (3) > for error checking, > it is often advised that one should instead check for bad argument > values before each call. > .\" http://www.securecoding.cert.org/confluence/display/seccode/FLP32-C.+Prevent+or+detect+domain+and+range+errors+in+math+functions > For example, the following code ensures that > .BR log (3)'s > argument is not a NaN and is not zero (a pole error) or > less than zero (a domain error): > .in +4n > .nf > > double x, r; > > if (isnan(x) || islessequal(x, 0)) { > /* Deal with NaN / pole error / domain error */ > } > > r = log(x); > > .fi > .in > The discussion on this page does not apply to the complex > mathematical functions (i.e., those declared by > .IR <complex.h> ), > which in general are not required to return errors by C99 > and POSIX.1-2001. > > The > .BR gcc (1) > .I "-fno-math-errno" > option causes the executable to employ implementations of some > mathematical functions that are faster than the standard > implementations, but do not set > .I errno > on error. > (The > .BR gcc (1) > .I "-ffast-math" > option also enables > .IR "-fno-math-errno" .) > An error can still be tested for using > .BR fetestexcept (3). > .fi > .in > .SH SEE ALSO > .BR gcc (1), > .BR errno (3), > .BR fenv (3), > .BR fpclassify (3), > .BR INFINITY (3), > .BR isgreater (3), > .BR matherr (3), > .BR nan (3) > > > > -- > Michael Kerrisk > Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ > man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html > Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html > -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <cfd18e0f0807210325m7606441as19811b6802661a8c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: math_error.7 draft 4, for review [not found] ` <cfd18e0f0807210325m7606441as19811b6802661a8c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2008-07-25 9:30 ` Andreas Jaeger [not found] ` <m3zlo6b9b8.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org> 0 siblings, 1 reply; 11+ messages in thread From: Andreas Jaeger @ 2008-07-25 9:30 UTC (permalink / raw) To: Michael Kerrisk Cc: Fabian Kreutz, Andries Brouwer, linux-man-u79uwXL29TY76Z2rM5mHXA [-- Attachment #1: Type: text/plain, Size: 695 bytes --] "Michael Kerrisk" <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> writes: > [CC+= Andries] > > On Mon, Jul 21, 2008 at 12:23 PM, Michael Kerrisk > <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> [Ooops -- wrong list CCed on previous mail; and this time, I'll update >> the draft number] >> >> Andreas, >> >> The latest version of the page is below. This one looked ok to me, Andreas -- Andreas Jaeger, Director Platform/openSUSE, aj-l3A5Bk7waGM@public.gmane.org SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) Maxfeldstr. 5, 90409 Nürnberg, Germany GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126 [-- Attachment #2: Type: application/pgp-signature, Size: 188 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <m3zlo6b9b8.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org>]
* Re: math_error.7 draft 4, for review [not found] ` <m3zlo6b9b8.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org> @ 2008-07-25 9:36 ` Michael Kerrisk [not found] ` <cfd18e0f0807250236y476023fan90e97822e772859e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 11+ messages in thread From: Michael Kerrisk @ 2008-07-25 9:36 UTC (permalink / raw) To: Andreas Jaeger Cc: Fabian Kreutz, Andries Brouwer, linux-man-u79uwXL29TY76Z2rM5mHXA On Fri, Jul 25, 2008 at 11:30 AM, Andreas Jaeger <aj-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org> wrote: > "Michael Kerrisk" <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> writes: > >> [CC+= Andries] >> >> On Mon, Jul 21, 2008 at 12:23 PM, Michael Kerrisk >> <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>> [Ooops -- wrong list CCed on previous mail; and this time, I'll update >>> the draft number] >>> >>> Andreas, >>> >>> The latest version of the page is below. > > This one looked ok to me, Thanks Andreas. So I've been testing all of the math functions lately (on glibc 2.8), and I discover the following: a) on error, many functions set errno AND raise an exception (fetestexcept()). b) on error, a few functions set errno but DON"T raise an exception (fetestexcept()). c) on error, a few functions DON'T set errno BUT DO raise an exception (fetestexcept()). d) on error, a very few functions pursue a mixture of all of the above, depending on the error. My math_error.7 page currently implies that all functions should do a). Clearly I'll need to amend that. But the main question is, should I raise a pile of glibc bugs for the functions in cases b), c), and d)? Cheers, Michael -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <cfd18e0f0807250236y476023fan90e97822e772859e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: math_error.7 draft 4, for review [not found] ` <cfd18e0f0807250236y476023fan90e97822e772859e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2008-07-25 10:02 ` Andreas Jaeger [not found] ` <m37ibab7sr.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org> 0 siblings, 1 reply; 11+ messages in thread From: Andreas Jaeger @ 2008-07-25 10:02 UTC (permalink / raw) To: Michael Kerrisk Cc: Fabian Kreutz, Andries Brouwer, linux-man-u79uwXL29TY76Z2rM5mHXA [-- Attachment #1: Type: text/plain, Size: 1824 bytes --] "Michael Kerrisk" <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> writes: > On Fri, Jul 25, 2008 at 11:30 AM, Andreas Jaeger <aj-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org> wrote: >> "Michael Kerrisk" <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> writes: >> >>> [CC+= Andries] >>> >>> On Mon, Jul 21, 2008 at 12:23 PM, Michael Kerrisk >>> <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>>> [Ooops -- wrong list CCed on previous mail; and this time, I'll update >>>> the draft number] >>>> >>>> Andreas, >>>> >>>> The latest version of the page is below. >> >> This one looked ok to me, > > Thanks Andreas. > > So I've been testing all of the math functions lately (on glibc 2.8), > and I discover the following: > > a) on error, many functions set errno AND raise an exception (fetestexcept()). > b) on error, a few functions set errno but DON"T raise an exception > (fetestexcept()). > c) on error, a few functions DON'T set errno BUT DO raise an exception > (fetestexcept()). > d) on error, a very few functions pursue a mixture of all of the > above, depending on the error. > > My math_error.7 page currently implies that all functions should do > a). Clearly I'll need to amend that. > > But the main question is, should I raise a pile of glibc bugs for the > functions in cases b), c), and d)? I suggest to discuss on the libc-alpha mailing list first. We have not done the exception handling properly. errno setting should be correct, we have tests for these, Andreas -- Andreas Jaeger, Director Platform/openSUSE, aj-l3A5Bk7waGM@public.gmane.org SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) Maxfeldstr. 5, 90409 Nürnberg, Germany GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126 [-- Attachment #2: Type: application/pgp-signature, Size: 188 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <m37ibab7sr.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org>]
* Re: math_error.7 draft 4, for review [not found] ` <m37ibab7sr.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org> @ 2008-07-25 10:16 ` Michael Kerrisk [not found] ` <cfd18e0f0807250316k4bb6cbd1t8c6f20317f669c4a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 11+ messages in thread From: Michael Kerrisk @ 2008-07-25 10:16 UTC (permalink / raw) To: Andreas Jaeger Cc: Fabian Kreutz, Andries Brouwer, linux-man-u79uwXL29TY76Z2rM5mHXA On Fri, Jul 25, 2008 at 12:02 PM, Andreas Jaeger <aj-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org> wrote: > "Michael Kerrisk" <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> writes: > >> On Fri, Jul 25, 2008 at 11:30 AM, Andreas Jaeger <aj-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org> wrote: >>> "Michael Kerrisk" <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> writes: >>> >>>> [CC+= Andries] >>>> >>>> On Mon, Jul 21, 2008 at 12:23 PM, Michael Kerrisk >>>> <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>>>> [Ooops -- wrong list CCed on previous mail; and this time, I'll update >>>>> the draft number] >>>>> >>>>> Andreas, >>>>> >>>>> The latest version of the page is below. >>> >>> This one looked ok to me, >> >> Thanks Andreas. >> >> So I've been testing all of the math functions lately (on glibc 2.8), >> and I discover the following: >> >> a) on error, many functions set errno AND raise an exception (fetestexcept()). >> b) on error, a few functions set errno but DON"T raise an exception >> (fetestexcept()). >> c) on error, a few functions DON'T set errno BUT DO raise an exception >> (fetestexcept()). >> d) on error, a very few functions pursue a mixture of all of the >> above, depending on the error. >> >> My math_error.7 page currently implies that all functions should do >> a). Clearly I'll need to amend that. >> >> But the main question is, should I raise a pile of glibc bugs for the >> functions in cases b), c), and d)? > > I suggest to discuss on the libc-alpha mailing list first. Okay -- I have done so. > We have not done the exception handling properly. errno setting should > be correct, we have tests for these, Well, for example, according to my tests, cos(3) does not set errno. Is that what you would have expected? -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <cfd18e0f0807250316k4bb6cbd1t8c6f20317f669c4a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: math_error.7 draft 4, for review [not found] ` <cfd18e0f0807250316k4bb6cbd1t8c6f20317f669c4a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2008-07-25 10:36 ` Andreas Jaeger [not found] ` <m3y73q9ro3.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org> 0 siblings, 1 reply; 11+ messages in thread From: Andreas Jaeger @ 2008-07-25 10:36 UTC (permalink / raw) To: Michael Kerrisk Cc: Fabian Kreutz, Andries Brouwer, linux-man-u79uwXL29TY76Z2rM5mHXA [-- Attachment #1: Type: text/plain, Size: 962 bytes --] "Michael Kerrisk" <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> writes: > Well, for example, according to my tests, cos(3) does not set errno. > Is that what you would have expected? No, I wouldn't. And double checking, it's the other way round :-(. We test the exception handling, not the error handling, so tests like (libc/math/libm-test.inc) these TEST_f_f (cos, plus_infty, nan_value, INVALID_EXCEPTION); TEST_f_f (cos, minus_infty, nan_value, INVALID_EXCEPTION); test that cos with input plus/minus infinity returns a NaN and raises and invalid exception which is tested with fetestexcept. And if you have different results, please tell me, Andreas -- Andreas Jaeger, Director Platform/openSUSE, aj-l3A5Bk7waGM@public.gmane.org SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) Maxfeldstr. 5, 90409 Nürnberg, Germany GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126 [-- Attachment #2: Type: application/pgp-signature, Size: 188 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <m3y73q9ro3.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org>]
* Re: math_error.7 draft 4, for review [not found] ` <m3y73q9ro3.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org> @ 2008-07-25 10:49 ` Michael Kerrisk [not found] ` <cfd18e0f0807250349jaa38928kaac968720c377322-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 11+ messages in thread From: Michael Kerrisk @ 2008-07-25 10:49 UTC (permalink / raw) To: Andreas Jaeger Cc: Fabian Kreutz, Andries Brouwer, linux-man-u79uwXL29TY76Z2rM5mHXA On Fri, Jul 25, 2008 at 12:36 PM, Andreas Jaeger <aj-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org> wrote: > "Michael Kerrisk" <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> writes: > >> Well, for example, according to my tests, cos(3) does not set errno. >> Is that what you would have expected? > > No, I wouldn't. (Slightly confused here, since you seem to contradict my result, but then the text below seems to agree with my result. But maybe I'm just misreading your text.) > And double checking, it's the other way round :-(. We > test the exception handling, not the error handling, so tests like > (libc/math/libm-test.inc) these > > TEST_f_f (cos, plus_infty, nan_value, INVALID_EXCEPTION); > TEST_f_f (cos, minus_infty, nan_value, INVALID_EXCEPTION); > > test that cos with input plus/minus infinity returns a NaN and raises > and invalid exception which is tested with fetestexcept. And if you > have different results, please tell me, When I run the program belwo, this is what I see for a domain error from cos(): $ ./a.out inf errno == 0 fetestexcept() says: 1 FE_INVALID cos(inf)=nan Cheers, Michael /* t_cos.c */ #define _XOPEN_SOURCE 600 #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <string.h> #include <fenv.h> #include <math.h> #include <float.h> #include <ctype.h> /* Convert a string to a double, but allow a few special cases in the form of non-numeric strings */ static double strToDouble(char *str) { char *p; char *s; double retval; if (str == NULL) { fprintf(stderr, "Missing argument\n"); exit(EXIT_FAILURE); } s = strdup(str); if (s == NULL) { perror("strdup"); exit(EXIT_FAILURE); } for (p = s; *p; p++) *p = tolower(*p); if (strcmp(s, "-inf") == 0) retval = -HUGE_VAL; else if (strcmp(s, "inf") == 0 || strcmp(s, "+inf") == 0) retval = HUGE_VAL; else if (strcmp(s, "nan") == 0) retval = nan(""); else if (strcmp(s, "dbl_min") == 0) retval = DBL_MIN; else if (strcmp(s, "-dbl_min") == 0) retval = -DBL_MIN; else if (strcmp(s, "dbl_max") == 0) retval = DBL_MAX; else if (strcmp(s, "-dbl_max") == 0) retval = -DBL_MAX; else if (strncmp(s, "subnormal", 9) == 0 || strncmp(s, "-subnormal", 10) == 0) { char *h; int d, j; h = strchr(s, ':'); if (h == NULL) d = 4; else d = atoi(h + 1); printf("subnormal denominator is %d\n", 1 << d); retval = DBL_MIN; for (j = 0; j < d; j++) retval /= 2.0; if (s[0] == '-') retval = -retval; printf("Returning %e\n", retval); } else if (strchr("+-0123456789", s[0]) == NULL) { fprintf(stderr, "Bad argument: %s\n", s); exit(EXIT_FAILURE); } else retval = atof(s); free(s); return retval; } /* strToDouble */ static void clearErrors(void) { errno = 0; feclearexcept(FE_ALL_EXCEPT); } static void checkErrors(void) { int s; if (errno == 0) { fprintf(stderr, "errno == 0\n"); } else { int e = errno; perror("errno"); if (e == EDOM) fprintf(stderr, "errno == EDOM\n"); else if (e == ERANGE) fprintf(stderr, "errno == ERANGE\n"); else fprintf(stderr, "errno == %d\n", e); } s = fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT); printf("fetestexcept() says: %d", s); if (s & FE_INVALID) printf(" FE_INVALID"); if (s & FE_DIVBYZERO) printf(" FE_DIVBYZERO"); if (s & FE_OVERFLOW) printf(" FE_OVERFLOW"); if (s & FE_UNDERFLOW) printf(" FE_UNDERFLOW"); if (s & FE_INEXACT) printf(" FE_INEXACT"); printf("\n"); } int main(int argc, char *argv[]) { double x, r; x = strToDouble(argv[1]); clearErrors(); r = cos(x); checkErrors(); printf("cos(%e)=%e\n", x, r); exit(EXIT_SUCCESS); } /* main */ -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <cfd18e0f0807250349jaa38928kaac968720c377322-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: math_error.7 draft 4, for review [not found] ` <cfd18e0f0807250349jaa38928kaac968720c377322-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2008-07-25 12:50 ` Andreas Jaeger [not found] ` <m3myk6cel3.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org> 0 siblings, 1 reply; 11+ messages in thread From: Andreas Jaeger @ 2008-07-25 12:50 UTC (permalink / raw) To: Michael Kerrisk Cc: Fabian Kreutz, Andries Brouwer, linux-man-u79uwXL29TY76Z2rM5mHXA [-- Attachment #1: Type: text/plain, Size: 1740 bytes --] "Michael Kerrisk" <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> writes: > On Fri, Jul 25, 2008 at 12:36 PM, Andreas Jaeger <aj-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org> wrote: >> "Michael Kerrisk" <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> writes: >> >>> Well, for example, according to my tests, cos(3) does not set errno. >>> Is that what you would have expected? >> >> No, I wouldn't. > > (Slightly confused here, since you seem to contradict my result, but > then the text below seems to agree with my result. But maybe I'm just > misreading your text.) I was confused as well ;) >> And double checking, it's the other way round :-(. We >> test the exception handling, not the error handling, so tests like >> (libc/math/libm-test.inc) these >> >> TEST_f_f (cos, plus_infty, nan_value, INVALID_EXCEPTION); >> TEST_f_f (cos, minus_infty, nan_value, INVALID_EXCEPTION); >> >> test that cos with input plus/minus infinity returns a NaN and raises >> and invalid exception which is tested with fetestexcept. And if you >> have different results, please tell me, > > When I run the program belwo, this is what I see for a domain error from cos(): > > $ ./a.out inf > errno == 0 > fetestexcept() says: 1 FE_INVALID > cos(inf)=nan Which is the correct behaviour for the exception AFAIK. Setting of errno is indeed missing - if math_errhandling has the right value which is unfortunately missing, Andreas -- Andreas Jaeger, Director Platform/openSUSE, aj-l3A5Bk7waGM@public.gmane.org SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) Maxfeldstr. 5, 90409 Nürnberg, Germany GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126 [-- Attachment #2: Type: application/pgp-signature, Size: 188 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <m3myk6cel3.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org>]
* Re: math_error.7 draft 4, for review [not found] ` <m3myk6cel3.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org> @ 2008-07-25 12:56 ` Michael Kerrisk [not found] ` <cfd18e0f0807250556p40ae6cd3l8b6617fadabd6411-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 11+ messages in thread From: Michael Kerrisk @ 2008-07-25 12:56 UTC (permalink / raw) To: Andreas Jaeger Cc: Fabian Kreutz, Andries Brouwer, linux-man-u79uwXL29TY76Z2rM5mHXA On Fri, Jul 25, 2008 at 2:50 PM, Andreas Jaeger <aj-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org> wrote: > "Michael Kerrisk" <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> writes: > >> On Fri, Jul 25, 2008 at 12:36 PM, Andreas Jaeger <aj-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org> wrote: >>> "Michael Kerrisk" <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> writes: >>> >>>> Well, for example, according to my tests, cos(3) does not set errno. >>>> Is that what you would have expected? >>> >>> No, I wouldn't. >> >> (Slightly confused here, since you seem to contradict my result, but >> then the text below seems to agree with my result. But maybe I'm just >> misreading your text.) > > I was confused as well ;) > >>> And double checking, it's the other way round :-(. We >>> test the exception handling, not the error handling, so tests like >>> (libc/math/libm-test.inc) these >>> >>> TEST_f_f (cos, plus_infty, nan_value, INVALID_EXCEPTION); >>> TEST_f_f (cos, minus_infty, nan_value, INVALID_EXCEPTION); >>> >>> test that cos with input plus/minus infinity returns a NaN and raises >>> and invalid exception which is tested with fetestexcept. And if you >>> have different results, please tell me, >> >> When I run the program belwo, this is what I see for a domain error from cos(): >> >> $ ./a.out inf >> errno == 0 >> fetestexcept() says: 1 FE_INVALID >> cos(inf)=nan > > Which is the correct behaviour for the exception AFAIK. Yes. I think all of the functions that I tested gave the right exception (except a very few that don't give an exception, but do set errno). > Setting of > errno is indeed missing - if math_errhandling has the right value which > is unfortunately missing, Yes. My point is that there is no consistency across the math functions. (And math_errhandling only tells about error reporting behavior across all functions, so it's presence or absence isn't really relevant to this inconsistency.) Some set errno and give an exception, while some do one, but not the other. -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <cfd18e0f0807250556p40ae6cd3l8b6617fadabd6411-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: math_error.7 draft 4, for review [not found] ` <cfd18e0f0807250556p40ae6cd3l8b6617fadabd6411-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2008-07-25 13:11 ` Andreas Jaeger 0 siblings, 0 replies; 11+ messages in thread From: Andreas Jaeger @ 2008-07-25 13:11 UTC (permalink / raw) To: Michael Kerrisk Cc: Fabian Kreutz, Andries Brouwer, linux-man-u79uwXL29TY76Z2rM5mHXA [-- Attachment #1: Type: text/plain, Size: 922 bytes --] "Michael Kerrisk" <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> writes: > [...] > Yes. My point is that there is no consistency across the math > functions. (And math_errhandling only tells about error reporting > behavior across all functions, so it's presence or absence isn't > really relevant to this inconsistency.) Some set errno and give an > exception, while some do one, but not the other. My brain get's rusty, it's some time I looked at all of this. So, let me state what I remember thinking some more about this: I would expect that the exceptions should be *all* correct. Errno is a different story, Andreas -- Andreas Jaeger, Director Platform/openSUSE, aj-l3A5Bk7waGM@public.gmane.org SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) Maxfeldstr. 5, 90409 Nürnberg, Germany GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126 [-- Attachment #2: Type: application/pgp-signature, Size: 188 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2008-07-25 13:11 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-21 10:23 math_error.7 draft 4, for review Michael Kerrisk
[not found] ` <cfd18e0f0807210323m4912a31pa5359c2b7409167c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-21 10:25 ` Michael Kerrisk
[not found] ` <cfd18e0f0807210325m7606441as19811b6802661a8c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-25 9:30 ` Andreas Jaeger
[not found] ` <m3zlo6b9b8.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org>
2008-07-25 9:36 ` Michael Kerrisk
[not found] ` <cfd18e0f0807250236y476023fan90e97822e772859e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-25 10:02 ` Andreas Jaeger
[not found] ` <m37ibab7sr.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org>
2008-07-25 10:16 ` Michael Kerrisk
[not found] ` <cfd18e0f0807250316k4bb6cbd1t8c6f20317f669c4a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-25 10:36 ` Andreas Jaeger
[not found] ` <m3y73q9ro3.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org>
2008-07-25 10:49 ` Michael Kerrisk
[not found] ` <cfd18e0f0807250349jaa38928kaac968720c377322-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-25 12:50 ` Andreas Jaeger
[not found] ` <m3myk6cel3.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org>
2008-07-25 12:56 ` Michael Kerrisk
[not found] ` <cfd18e0f0807250556p40ae6cd3l8b6617fadabd6411-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-25 13:11 ` Andreas Jaeger
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox