Mercurial > hg > fxanalyse
annotate future.c @ 80:46fe62febcd0
Add dedrifting DDS reset functionality
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Mon, 18 Mar 2013 12:34:05 +0100 |
parents | 9d57d1fcbcd5 |
children | be814b934eca |
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 } |