From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Add set/get functions for negative infinity in real.*
Date: Tue, 23 Aug 2022 12:33:21 +0200 [thread overview]
Message-ID: <20220823103321.879429-1-aldyh@redhat.com> (raw)
For the frange implementation with endpoints I'm about to contribute,
we need to set REAL_VALUE_TYPEs with negative infinity. The support
is already there in real.cc, but it is awkward to get at. One could
call real_inf() and then negate the value, but I've added the ability
to pass the sign argument like many of the existing real.* functions.
I've declared the functions in such a way to avoid changes to the
existing code base:
// Unchanged function returning true for either +-INF.
bool real_isinf (const REAL_VALUE_TYPE *r);
// New overload to be able to specify the sign.
bool real_isinf (const REAL_VALUE_TYPE *r, int sign);
// Replacement function for setting INF, defaults to +INF.
void real_inf (REAL_VALUE_TYPE *, int sign = 0);
Tested on x86-64 Linux.
OK?
gcc/ChangeLog:
* real.cc (real_isinf): New overload.
(real_inf): Add sign argument.
* real.h (real_isinf): New overload.
(real_inf): Add sign argument.
---
gcc/real.cc | 14 +++++++++++---
gcc/real.h | 5 ++++-
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/gcc/real.cc b/gcc/real.cc
index 4e63b1449c5..f570ca8e85b 100644
--- a/gcc/real.cc
+++ b/gcc/real.cc
@@ -1234,6 +1234,14 @@ real_isinf (const REAL_VALUE_TYPE *r)
return (r->cl == rvc_inf);
}
+/* Determine whether a floating-point value X is infinite with SIGN. */
+
+bool
+real_isinf (const REAL_VALUE_TYPE *r, int sign)
+{
+ return real_isinf (r) && r->sign == sign;
+}
+
/* Determine whether a floating-point value X is a NaN. */
bool
@@ -2484,12 +2492,12 @@ dconst_sqrt2_ptr (void)
return &value;
}
-/* Fills R with +Inf. */
+/* Fills R with Inf with SIGN. */
void
-real_inf (REAL_VALUE_TYPE *r)
+real_inf (REAL_VALUE_TYPE *r, int sign)
{
- get_inf (r, 0);
+ get_inf (r, sign);
}
/* Fills R with a NaN whose significand is described by STR. If QUIET,
diff --git a/gcc/real.h b/gcc/real.h
index 845ef29e3a4..76360b603fb 100644
--- a/gcc/real.h
+++ b/gcc/real.h
@@ -277,6 +277,9 @@ extern bool real_compare (int, const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *)
/* Determine whether a floating-point value X is infinite. */
extern bool real_isinf (const REAL_VALUE_TYPE *);
+/* Determine whether a floating-point value X is infinite with SIGN. */
+extern bool real_isinf (const REAL_VALUE_TYPE *, int sign);
+
/* Determine whether a floating-point value X is a NaN. */
extern bool real_isnan (const REAL_VALUE_TYPE *);
@@ -331,7 +334,7 @@ extern long real_to_target (long *, const REAL_VALUE_TYPE *, format_helper);
extern void real_from_target (REAL_VALUE_TYPE *, const long *,
format_helper);
-extern void real_inf (REAL_VALUE_TYPE *);
+extern void real_inf (REAL_VALUE_TYPE *, int sign = 0);
extern bool real_nan (REAL_VALUE_TYPE *, const char *, int, format_helper);
--
2.37.1
next reply other threads:[~2022-08-23 10:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-23 10:33 Aldy Hernandez [this message]
2022-08-26 15:43 ` Aldy Hernandez
2022-08-26 15:43 ` Aldy Hernandez
2022-08-26 16:08 ` Jeff Law
2022-08-26 16:25 ` Aldy Hernandez
2022-08-26 16:34 ` Jeff Law
2022-08-26 16:07 ` Jeff Law
2022-08-26 16:24 ` Aldy Hernandez
2022-08-26 16:33 ` Jeff Law
2022-08-26 16:38 ` Aldy Hernandez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220823103321.879429-1-aldyh@redhat.com \
--to=aldyh@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).