round.c
Go to the documentation of this file.
1 /* round.c
2  *
3  * Round double to nearest or even integer valued double
4  *
5  *
6  *
7  * SYNOPSIS:
8  *
9  * double x, y, round();
10  *
11  * y = round(x);
12  *
13  *
14  *
15  * DESCRIPTION:
16  *
17  * Returns the nearest integer to x as a double precision
18  * floating point result. If x ends in 0.5 exactly, the
19  * nearest even integer is chosen.
20  *
21  *
22  *
23  * ACCURACY:
24  *
25  * If x is greater than 1/(2*MACHEP), its closest machine
26  * representation is already an integer, so rounding does
27  * not change it.
28  */
29 
30 /*
31  * Cephes Math Library Release 2.1: January, 1989
32  * Copyright 1984, 1987, 1989 by Stephen L. Moshier
33  * Direct inquiries to 30 Frost Street, Cambridge, MA 02140
34  */
35 
36 #include "mconf.h"
37 
38 double round(double x)
39 {
40  double y, r;
41 
42  /* Largest integer <= x */
43  y = floor(x);
44 
45  /* Fractional part */
46  r = x - y;
47 
48  /* Round up to nearest. */
49  if (r > 0.5)
50  goto rndup;
51 
52  /* Round to even */
53  if (r == 0.5) {
54  r = y - 2.0 * floor(0.5 * y);
55  if (r == 1.0) {
56  rndup:
57  y += 1.0;
58  }
59  }
60 
61  /* Else round down. */
62  return (y);
63 }
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
round
double round(double x)
Definition: round.c:38
y
Scalar * y
Definition: level1_cplx_impl.h:124
mconf.h
floor
const EIGEN_DEVICE_FUNC FloorReturnType floor() const
Definition: ArrayCwiseUnaryOps.h:481


gtsam
Author(s):
autogenerated on Thu Jun 13 2024 03:05:00