annotate future.c @ 34:1e4b8ba97faf

Cleanup code handling dedrifing options This removes some code that does not make much sense to me.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Wed, 03 Oct 2012 12:56:22 +0200
parents 9d57d1fcbcd5
children be814b934eca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
1 /* welcome in the 2012 */
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
2
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
3 /* required by CVI */
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
4 #include <ansi_c.h>
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
5
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
6 /* an implementation of the C99 `round` function based on `floor` and `ceil` */
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
7 double round(double x)
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
8 {
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
9 if (x >= 0.0) {
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
10 double y = floor(x);
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
11 if (x - y >= 0.5)
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
12 y += 1.0;
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
13 return y;
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
14 } else {
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
15 double y = ceil(x);
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
16 if (x - y >= 0.5)
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
17 y -= 1.0;
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
18 return y;
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
19 }
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
20 }