LAL  7.5.0.1-fe68b98
GPStoFloatTest.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 David Chin, Reinhard Prix
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19 
20 #include <stdio.h>
21 #include <math.h>
22 #include <stdlib.h>
23 #include <time.h>
24 
25 #include <lal/LALStdlib.h>
26 #include <lal/Date.h>
27 
28 
29 static int test_random_doubles(unsigned int seed)
30 {
31  int i;
32 
33  srand(seed);
34 
35  for(i = 0; i < 100000000; i++) {
36  double in;
37  double out;
38  LIGOTimeGPS gps;
39 
40  in = rand() * 2000000000.0 / RAND_MAX;
41  in += (double) rand() / RAND_MAX;
42 
43  out = XLALGPSGetREAL8(XLALGPSSetREAL8(&gps, in));
44 
45  /* max allowed round-trip error is 1 ns */
46  if(fabs(in - out) > 1e-9) {
47  fprintf(stderr, "XLALGPSSetREAL8() + XLALGPSGetREAL8() failed: input = %.17g s, output = %.17g s, difference = %.16g ns ~ %.2g%% (seed was %u)\n", in, out, (in - out) * 1e9, fabs(in - out) / in * 100.0, seed);
48  return -1;
49  }
50  }
51 
52  return 0;
53 }
54 
55 
56 
57 int main(void)
58 {
59 
60  /* 5 */
61  if(test_random_doubles(time(NULL)))
62  return 5;
63 
64  return 0;
65 }
int main(void)
static int test_random_doubles(unsigned int seed)
#define fprintf
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
Sets GPS time given GPS seconds as a REAL8.
Definition: XLALTime.c:73
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
Returns the GPS time as a REAL8.
Definition: XLALTime.c:91
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
Definition: LALDatatypes.h:458