public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
* math_error.7 draft 3, for review
@ 2008-07-16 13:47 Michael Kerrisk
       [not found] ` <cfd18e0f0807160647o776d8523yb2f1ed4f0d946911-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
       [not found] ` <cfd18e0f0807210314s6556f15bue41b1af46e28f77d@mail.gmail.com>
  0 siblings, 2 replies; 8+ messages in thread
From: Michael Kerrisk @ 2008-07-16 13:47 UTC (permalink / raw)
  To: aj-l3A5Bk7waGM
  Cc: linux-man-u79uwXL29TY76Z2rM5mHXA, Andries Brouwer, Fabian Kreutz

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-15 "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 an error was signaled.
There are two signaling mechanism:
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.

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 include 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).

If
.B_SVID_SOURCE
is defined, glibc provides the older
.I matherr ()
error-reporting framework defined by SVID.
.SH SEE ALSO
.BR gcc (1),
.BR errno (3),
.BR fenv (3),
.BR fpclassify (3),
.BR INFINITY (3),
.BR isgreater (3),
.BR nan (3)
.br
.I "info libc"
--
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] 8+ messages in thread

* Re: math_error.7 draft 3, for review
       [not found] ` <cfd18e0f0807160647o776d8523yb2f1ed4f0d946911-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2008-07-16 21:37   ` Andries E. Brouwer
  2008-07-21 11:36     ` Michael Kerrisk
  2008-07-21 10:12   ` Michael Kerrisk
  1 sibling, 1 reply; 8+ messages in thread
From: Andries E. Brouwer @ 2008-07-16 21:37 UTC (permalink / raw)
  To: Michael Kerrisk
  Cc: aj-l3A5Bk7waGM, linux-man-u79uwXL29TY76Z2rM5mHXA, Andries Brouwer,
	Fabian Kreutz

On Wed, Jul 16, 2008 at 03:47:41PM +0200, Michael Kerrisk wrote:

> There are two signaling mechanism:

mechanisms


> If
> .B_SVID_SOURCE
> is defined, glibc provides the older
> .I matherr ()
> error-reporting framework defined by SVID.

Typo: .B _SVID_SOURCE
But defining this does not suffice, one also needs the magic incantation
    _LIB_VERSION = _SVID_;

Example:

/* matherr demo; link with -lm */
#define _SVID_SOURCE
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int matherr(struct exception *x) {
        fprintf(stderr, "math error\n");
        exit(1);
}

int main(){
        double x;

        _LIB_VERSION = _SVID_;

        x = sqrt(-1.0);
        printf("x=%f\n", x);
        return 0;
}

Andries

--
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] 8+ messages in thread

* Re: math_error.7 draft 3, for review
       [not found] ` <cfd18e0f0807160647o776d8523yb2f1ed4f0d946911-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2008-07-16 21:37   ` Andries E. Brouwer
@ 2008-07-21 10:12   ` Michael Kerrisk
       [not found]     ` <cfd18e0f0807210312s78b1183ao5ec2932a5317decc-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  1 sibling, 1 reply; 8+ messages in thread
From: Michael Kerrisk @ 2008-07-21 10:12 UTC (permalink / raw)
  To: aj-Et1tbQHTxzrQT0dZR+AlfA
  Cc: linux-man-u79uwXL29TY76Z2rM5mHXA, Andries Brouwer, Fabian Kreutz

Hmmm -- no response from Andreas.  Perhaps the old suse address is no
longer active.  This looks like the up to date address.

Andreas, a new version of the page below will be sent in just a moment.

Cheers,

Michael

On Wed, Jul 16, 2008 at 3:47 PM, Michael Kerrisk
<mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:
> 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-15 "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 an error was signaled.
> There are two signaling mechanism:
> 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.
>
> 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 include 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).
>
> If
> .B_SVID_SOURCE
> is defined, glibc provides the older
> .I matherr ()
> error-reporting framework defined by SVID.
> .SH SEE ALSO
> .BR gcc (1),
> .BR errno (3),
> .BR fenv (3),
> .BR fpclassify (3),
> .BR INFINITY (3),
> .BR isgreater (3),
> .BR nan (3)
> .br
> .I "info libc"
>



-- 
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] 8+ messages in thread

* Re: math_error.7 draft 3, for review
  2008-07-16 21:37   ` Andries E. Brouwer
@ 2008-07-21 11:36     ` Michael Kerrisk
       [not found]       ` <cfd18e0f0807210436h558aae2cu46f0100c439a8e4a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Kerrisk @ 2008-07-21 11:36 UTC (permalink / raw)
  To: Andries E. Brouwer
  Cc: aj-Et1tbQHTxzrQT0dZR+AlfA, linux-man-u79uwXL29TY76Z2rM5mHXA,
	Fabian Kreutz

Hi Andries,

Reading the POSIX.1 specs of various functions, I see that sometimes
they talk of the return value of a function as being +0, sometimes
+-0, and sometimes -0.  Does one need to care about this?  (e.g., in
updating them man-pages, I'm inclined to group the 0 cases togetehr,
where possible).  If one does need to care, then could you explain to
me why?  Are there cases where one gets bitten by not caring?  (I've
had a browse through the C standard, but I'm not sure that I am yet
any the wiser.)

Hmmm -- just now, I find the Wikipedia article:
http://en.wikipedia.org/wiki/%E2%88%920_(number).  So, are these the
only cases that matter (quoting test from wp):

* using the copysign() function, which is defined by IEEE 754 to copy
the sign of the zero, to some non-zero number
* dividing the number into a positive number—the resulting Infinity
will reflect the sign of the zero.

?

It starts to sound like I should care about postive and negative zero
when rewriting the man pages, or?

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] 8+ messages in thread

* Re: math_error.7 draft 3, for review
       [not found]       ` <cfd18e0f0807210436h558aae2cu46f0100c439a8e4a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2008-07-21 14:15         ` Andries E. Brouwer
  2008-07-21 14:43           ` Michael Kerrisk
  0 siblings, 1 reply; 8+ messages in thread
From: Andries E. Brouwer @ 2008-07-21 14:15 UTC (permalink / raw)
  To: Michael Kerrisk
  Cc: Andries E. Brouwer, aj-Et1tbQHTxzrQT0dZR+AlfA,
	linux-man-u79uwXL29TY76Z2rM5mHXA, Fabian Kreutz

On Mon, Jul 21, 2008 at 01:36:52PM +0200, Michael Kerrisk wrote:
> Hi Andries,
> 
> Reading the POSIX.1 specs of various functions, I see that sometimes
> they talk of the return value of a function as being +0, sometimes
> +-0, and sometimes -0.  Does one need to care about this?

Yes.

These are different floating point values, and sometimes the
difference is important. In cases of total loss of precision
it is the only bit left. At a branch cut one has a discontinuity
and for example the imaginary part of clog(0.0) will be 0
while the imaginary part of clog(-0.0) is pi*I.

Andries

--
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] 8+ messages in thread

* Re: math_error.7 draft 3, for review
  2008-07-21 14:15         ` Andries E. Brouwer
@ 2008-07-21 14:43           ` Michael Kerrisk
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Kerrisk @ 2008-07-21 14:43 UTC (permalink / raw)
  To: Andries E. Brouwer
  Cc: aj-Et1tbQHTxzrQT0dZR+AlfA, linux-man-u79uwXL29TY76Z2rM5mHXA,
	Fabian Kreutz

On Mon, Jul 21, 2008 at 4:15 PM, Andries E. Brouwer
<Andries.Brouwer-rh8NL+sEX9E@public.gmane.org> wrote:
> On Mon, Jul 21, 2008 at 01:36:52PM +0200, Michael Kerrisk wrote:
>> Hi Andries,
>>
>> Reading the POSIX.1 specs of various functions, I see that sometimes
>> they talk of the return value of a function as being +0, sometimes
>> +-0, and sometimes -0.  Does one need to care about this?
>
> Yes.
>
> These are different floating point values, and sometimes the
> difference is important. In cases of total loss of precision
> it is the only bit left. At a branch cut one has a discontinuity
> and for example the imaginary part of clog(0.0) will be 0
> while the imaginary part of clog(-0.0) is pi*I.

Thanks Andries.  I will attend to the difference in my updates.

Cheers,

Michael

-- 
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] 8+ messages in thread

* Re: math_error.7 draft 3, for review
       [not found]     ` <cfd18e0f0807210312s78b1183ao5ec2932a5317decc-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2008-07-25  9:31       ` Andreas Jaeger
  0 siblings, 0 replies; 8+ messages in thread
From: Andreas Jaeger @ 2008-07-25  9:31 UTC (permalink / raw)
  To: Michael Kerrisk
  Cc: linux-man-u79uwXL29TY76Z2rM5mHXA, Andries Brouwer, Fabian Kreutz

[-- Attachment #1: Type: text/plain, Size: 633 bytes --]

"Michael Kerrisk" <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> writes:

> Hmmm -- no response from Andreas.  Perhaps the old suse address is no
> longer active.  This looks like the up to date address.

It is active - but I've been travelling ;-)

> Andreas, a new version of the page below will be sent in just a moment.

OK, thanks,
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] 8+ messages in thread

* Re: math_error.7 draft 3, for review
       [not found]       ` <m3r69ib8sz.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org>
@ 2008-07-25  9:51         ` Michael Kerrisk
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Kerrisk @ 2008-07-25  9:51 UTC (permalink / raw)
  To: Michael Kerrisk, Fabian Kreutz, Andries Brouwer,
	linux-man-u79uwXL29TY76Z2rM5mHXA

[CC-=LKML (my mistake at start of thread; += linux-man]

Hi Andreas,

On Fri, Jul 25, 2008 at 11:41 AM, Andreas Jaeger <aj-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org> wrote:
> "Michael Kerrisk" <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
>> [ooops -- sorry for the noise.  Wrong list CCed]
>>
>> On 7/21/08, Michael Kerrisk <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:
>>> 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?
>
> In general glibc should follow the ISO C99 and Posix Standards and if
> there is any discrepancy between those and the glibc implementation,
> it's a bug.  That should help you to verify the details as well.
>
> I'll try to answer questions and should be able to look at them but I
> cannot double check each and every case myself.

Understood.  Actually, since I wrote the earlier message, I've got
more confident about the direction the pages are going in anyway.

See also my question in the other thread: should I provide bug reports
for the discrepant cases?

>>>  .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.
>
> I just noticed something that's also in draft 4, so let me cite from the
> CONFORMANCE file of glibc:
>
>   Implementing MATH_ERRNO, MATH_ERREXCEPT and math_errhandling in
>   <math.h> needs compiler support: see
>
>   http://sources.redhat.com/ml/libc-hacker/2000-06/msg00008.html
>   http://sources.redhat.com/ml/libc-hacker/2000-06/msg00014.html
>   http://sources.redhat.com/ml/libc-hacker/2000-06/msg00015.html
>
> I check gcc and glibc and this is still missing,

Yes, understood.  But I had the impression that this piece is just
about whether we can use math_errhandling to determine which of errno
or fetestexcept() can be used to check for errors.  Glibc doesn't
provide math_errhandling, but the tendency seems to be that both
mechanisms are supported, with a few discrepancies.

-- 
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] 8+ messages in thread

end of thread, other threads:[~2008-07-25  9:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-16 13:47 math_error.7 draft 3, for review Michael Kerrisk
     [not found] ` <cfd18e0f0807160647o776d8523yb2f1ed4f0d946911-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-16 21:37   ` Andries E. Brouwer
2008-07-21 11:36     ` Michael Kerrisk
     [not found]       ` <cfd18e0f0807210436h558aae2cu46f0100c439a8e4a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-21 14:15         ` Andries E. Brouwer
2008-07-21 14:43           ` Michael Kerrisk
2008-07-21 10:12   ` Michael Kerrisk
     [not found]     ` <cfd18e0f0807210312s78b1183ao5ec2932a5317decc-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-25  9:31       ` Andreas Jaeger
     [not found] ` <cfd18e0f0807210314s6556f15bue41b1af46e28f77d@mail.gmail.com>
     [not found]   ` <517f3f820807210326x30ce95dayf18d72ba0ce03588@mail.gmail.com>
     [not found]     ` <m3r69ib8sz.fsf@gromit.moeb>
     [not found]       ` <m3r69ib8sz.fsf-Qr39nsLl7G5WFLYQ/5USTw@public.gmane.org>
2008-07-25  9:51         ` Michael Kerrisk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox