summary refs log tree commit diff
path: root/sysdeps/s390/fix-fp-int-convert-overflow.h
diff options
context:
space:
mode:
authorStefan Liebler <stli@de.ibm.com>2016-01-18 12:48:06 +0100
committerStefan Liebler <stli@de.ibm.com>2016-01-18 12:48:06 +0100
commitc4d17461e062e730fca4076dd47a2733b3914c51 (patch)
tree89346046c4bad9bad11d8e8cbbc17c89856c5b2c /sysdeps/s390/fix-fp-int-convert-overflow.h
parent4e58b6485989a9462e88d5f683e2100902afd574 (diff)
downloadglibc-c4d17461e062e730fca4076dd47a2733b3914c51.tar.gz
glibc-c4d17461e062e730fca4076dd47a2733b3914c51.tar.xz
glibc-c4d17461e062e730fca4076dd47a2733b3914c51.zip
S/390: Do not raise inexact exception in lrint/lround. [BZ #19486]
I get some math test-failures on s390 for float/double/ldouble for
various lrint/lround functions like:
lrint (0x1p64): Exception "Inexact" set
lrint (-0x1p64): Exception "Inexact" set
lround (0x1p64): Exception "Inexact" set
lround (-0x1p64): Exception "Inexact" set
...

GCC emits "convert to fixed" instructions for casting floating point
values to integer values. These instructions raise invalid and inexact
exceptions if the floating point value exceeds the integer type ranges.

This patch enables the various FIX_DBL_LONG_CONVERT_OVERFLOW macros in
order to avoid a cast from floating point to integer type and raise the
invalid exception with feraiseexcept.
The ldbl-128 rint/round functions are now using the same logic.

ChangeLog:

	[BZ #19486]
	* sysdeps/s390/fix-fp-int-convert-overflow.h: New File.
	* sysdeps/generic/fix-fp-int-convert-overflow.h
	(FIX_LDBL_LONG_CONVERT_OVERFLOW,
	FIX_LDBL_LLONG_CONVERT_OVERFLOW): New define.
	* sysdeps/arm/fix-fp-int-convert-overflow.h: Likewise.
	* sysdeps/mips/mips32/fpu/fix-fp-int-convert-overflow.h:
	Likewise.
	* sysdeps/ieee754/ldbl-128/s_lrintl.c (__lrintl):
	Avoid conversions to long int where inexact exceptions
	could be raised.
	* sysdeps/ieee754/ldbl-128/s_lroundl.c (__lroundl):
	Likewise.
	* sysdeps/ieee754/ldbl-128/s_llrintl.c (__llrintl):
	Avoid conversions to long long int where inexact exceptions
	could be raised.
	* sysdeps/ieee754/ldbl-128/s_llroundl.c (__llroundl):
	Likewise.
Diffstat (limited to 'sysdeps/s390/fix-fp-int-convert-overflow.h')
-rw-r--r--sysdeps/s390/fix-fp-int-convert-overflow.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/sysdeps/s390/fix-fp-int-convert-overflow.h b/sysdeps/s390/fix-fp-int-convert-overflow.h
new file mode 100644
index 0000000000..61279edc19
--- /dev/null
+++ b/sysdeps/s390/fix-fp-int-convert-overflow.h
@@ -0,0 +1,33 @@
+/* Fix for conversion of floating point to integer overflow.  S390 version.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef FIX_FP_INT_CONVERT_OVERFLOW_H
+#define FIX_FP_INT_CONVERT_OVERFLOW_H	1
+
+/* GCC emits "convert to fixed" instructions for casting floating point values
+   to integer values. These instructions raise invalid and inexact exceptions
+   if the floating point value exceeds the integer type ranges.  */
+#define FIX_FLT_LLONG_CONVERT_OVERFLOW 1
+#define FIX_DBL_LLONG_CONVERT_OVERFLOW 1
+#define FIX_LDBL_LLONG_CONVERT_OVERFLOW 1
+
+#define FIX_FLT_LONG_CONVERT_OVERFLOW 1
+#define FIX_DBL_LONG_CONVERT_OVERFLOW 1
+#define FIX_LDBL_LONG_CONVERT_OVERFLOW 1
+
+#endif /* fix-fp-int-convert-overflow.h */