aboutsummaryrefslogtreecommitdiff
path: root/gcc/real.c
diff options
context:
space:
mode:
authorRoger Sayle <roger@eyesopen.com>2004-01-23 16:16:33 +0000
committerRoger Sayle <roger@eyesopen.com>2004-01-23 16:16:33 +0000
commitee974bdee412168d85fe0f3754ea1dc5c677613c (patch)
treea4e7871be466032d2019d3dd74d2f1702b848756 /gcc/real.c
parentd40d8139852c78a2dcc5739bfd767bd8192d778e (diff)
* real.c (real_floor, real_ceil): Tweak to allow input and output
arguments to overlap. (real_round): New function to implement round(3m) semantics. * real.h (real_round): Prototype here. * builtins.c (fold_builtin_round): New function to constant fold round, roundf and roundl. (fold_builtin): Call fold_builtin_round for BUILT_IN_ROUND{,F,L}. * gcc.dg/builtins-29.c: New test case. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@76428 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/real.c')
-rw-r--r--gcc/real.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/gcc/real.c b/gcc/real.c
index 5d9bc41dcb7..cd27d3e0501 100644
--- a/gcc/real.c
+++ b/gcc/real.c
@@ -4539,11 +4539,13 @@ void
real_floor (REAL_VALUE_TYPE *r, enum machine_mode mode,
const REAL_VALUE_TYPE *x)
{
- do_fix_trunc (r, x);
- if (! real_identical (r, x) && r->sign)
- do_add (r, r, &dconstm1, 0);
+ REAL_VALUE_TYPE t;
+
+ do_fix_trunc (&t, x);
+ if (! real_identical (&t, x) && x->sign)
+ do_add (&t, &t, &dconstm1, 0);
if (mode != VOIDmode)
- real_convert (r, mode, r);
+ real_convert (r, mode, &t);
}
/* Round X to the smallest integer not less then argument, i.e. round
@@ -4553,9 +4555,25 @@ void
real_ceil (REAL_VALUE_TYPE *r, enum machine_mode mode,
const REAL_VALUE_TYPE *x)
{
- do_fix_trunc (r, x);
- if (! real_identical (r, x) && ! r->sign)
- do_add (r, r, &dconst1, 0);
+ REAL_VALUE_TYPE t;
+
+ do_fix_trunc (&t, x);
+ if (! real_identical (&t, x) && ! x->sign)
+ do_add (&t, &t, &dconst1, 0);
+ if (mode != VOIDmode)
+ real_convert (r, mode, &t);
+}
+
+/* Round X to the nearest integer, but round halfway cases away from
+ zero. */
+
+void
+real_round (REAL_VALUE_TYPE *r, enum machine_mode mode,
+ const REAL_VALUE_TYPE *x)
+{
+ do_add (r, x, &dconsthalf, x->sign);
+ do_fix_trunc (r, r);
if (mode != VOIDmode)
real_convert (r, mode, r);
}
+