This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: exp sets the errno to ERANGE error .
- From: Szabolcs Nagy <Szabolcs dot Nagy at arm dot com>
- To: Umesh Kalappa <umesh dot kalappa0 at gmail dot com>, "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>
- Cc: nd <nd at arm dot com>
- Date: Tue, 7 May 2019 09:37:51 +0000
- Subject: Re: exp sets the errno to ERANGE error .
- References: <CAGfacvQD2ysaOspXS0MMXe9ECOuaOsMGOwhujAY_0V2aA4NHAw@mail.gmail.com>
On 07/05/2019 08:51, Umesh Kalappa wrote:
> Hi everyone ,
>
> we have situations ,where the following program sets the errno to
> 34(range error) in the version 2.28
>
> $cat test.c
> int main() {
> printf("errno %d\n", errno);
> printf("%f\n", exp(-1421.0));
> printf("errno %d\n", errno);
> }
>
> according the C11 standard the exp should not set the errno to ERANGE
> when it underflow to zero .
>
> so we think that glibc (atleast 2.28) is not consistent with the C
> standard and any comments regrading the same .
the c standard allows ERANGE for uflow.
"If the result underflows, the function returns an
implementation-defined value whose magnitude is no
greater than the smallest normalized positive number
in the specified type; if the integer expression
math_errhandling & MATH_ERRNO is nonzero, whether
errno acquires the value ERANGE is implementation-defined;"
http://port70.net/~nsz/c/c11/n1570.html#7.12.1p6
glibc documents its behaviour as
"When underflow occurs, the underflow exception is raised,
and zero (appropriately signed) or a subnormal value, as
appropriate for the mathematical result of the function and
the rounding mode, is returned. errno may be set to ERANGE,
but this is not guaranteed; it is intended that the GNU C
Library should set it when the underflow is to an appropriately
signed zero, but not necessarily for other underflows."
https://www.gnu.org/software/libc/manual/html_node/Math-Error-Reporting.html
>
> Thank you and looking forward for any suggestions / comments.
> ~Umesh
>