26 #include <lal/LALDebugLevel.h>
27 #include <lal/LALMalloc.h>
28 #include <lal/LALStdio.h>
29 #include <lal/XLALError.h>
60 fprintf(stdout,
"Input = \"%s\"\n\tOutput =\t%" LAL_INT8_FORMAT " ns with \"%s\" remainder, errno %d\n\tCorrect =\t%" LAL_INT8_FORMAT " ns with \"%s\" remainder, errno %d\n\t\t===> %s\n", testcase->
string,
XLALGPSToINT8NS(&gps), endptr,
XLALGetBaseErrno(),
XLALGPSToINT8NS(&gpsCorrect), testcase->
remainder, testcase->
xlal_errno, failure ?
"*** FAIL ***" :
"Pass");
71 {
"1234.5", 1234, 500000000,
"", 0},
72 {
"712345678", 712345678, 0,
"", 0},
73 {
"00000000712346678", 712346678, 0,
"", 0},
74 {
"000000000000000000000000000000000712347678", 712347678, 0,
"", 0},
75 {
"000000000000000000712348678.00000000000000", 712348678, 0,
"", 0},
76 {
"000000000000000000712349678.00000000000001", 712349678, 0,
"", 0},
77 {
"722345678.", 722345678, 0,
"", 0},
78 {
"1722346678.", 1722346678, 0,
"", 0},
79 {
"01722347678.", 1722347678, 0,
"", 0},
80 {
"001722348678.", 1722348678, 0,
"", 0},
81 {
"732345678.0", 732345678, 0,
"", 0},
82 {
"742345678.7", 742345678, 700000000,
"", 0},
83 {
"752345678.000861", 752345678, 861000,
"", 0},
84 {
"762345678.000862547", 762345678, 862547,
"", 0},
85 {
"772345678.0008635474", 772345678, 863547,
"", 0},
87 {
"792345678.000865547687287", 792345678, 865548,
"", 0},
88 {
"702345678.9999999994", 702345678, 999999999,
"", 0},
90 {
"722345678.9999999996", 722345679, 0,
"", 0},
91 {
"2000000000", 2000000000, 0,
"", 0},
92 {
"752345678e0", 752345678, 0,
"", 0},
93 {
"762345678e+0", 762345678, 0,
"", 0},
94 {
"772345678e-0", 772345678, 0,
"", 0},
95 {
"782345678e00", 782345678, 0,
"", 0},
96 {
"792345678e+00", 792345678, 0,
"", 0},
97 {
"702345678e-00", 702345678, 0,
"", 0},
98 {
"712345678.e0", 712345678, 0,
"", 0},
99 {
"722345678.e+0", 722345678, 0,
"", 0},
100 {
"732345678.e-0", 732345678, 0,
"", 0},
101 {
"742345678.00e0", 742345678, 0,
"", 0},
102 {
"752345678.00e+0", 752345678, 0,
"", 0},
103 {
"762345678.00e-0", 762345678, 0,
"", 0},
104 {
"772345678.06e0", 772345678, 60000000,
"", 0},
105 {
"782345678.06e+0", 782345678, 60000000,
"", 0},
106 {
"792345678.06e-0", 792345678, 60000000,
"", 0},
107 {
"7023.45678e5", 702345678, 0,
"", 0},
108 {
"7123.457785255e+05", 712345778, 525500000,
"", 0},
109 {
"7223458785255e-4", 722345878, 525500000,
"", 0},
110 {
"43d", 43, 0,
"d", 0},
111 {
"44.3873qr", 44, 387300000,
"qr", 0},
112 {
"45.3973 qr", 45, 397300000,
" qr", 0},
113 {
"46.3073 e2", 46, 307300000,
" e2", 0},
114 {
"47.3173e2", 4731, 730000000,
"", 0},
115 {
"6.85e7", 68500000, 0,
"", 0},
116 {
"6.9512345678901e7", 69512345, 678901000,
"", 0},
117 {
"6.05e7dkjf", 60500000, 0,
"dkjf", 0},
118 {
"6.15ex0", 6, 150000000,
"ex0", 0},
119 {
"6.25E7", 62500000, 0,
"", 0},
120 {
"6.35E7dkjf", 63500000, 0,
"dkjf", 0},
121 {
"6.45Ex0", 6, 450000000,
"Ex0", 0},
122 {
"752345678.5433e258", LONG_MAX, 0,
"",
XLAL_ERANGE},
123 {
"762345678.5533e258r574", LONG_MAX, 0,
"r574",
XLAL_ERANGE},
124 {
"772345678.5633e.258", 772345678, 563300000,
"e.258", 0},
125 {
"782345678.5733.258", 782345678, 573300000,
".258", 0},
126 {
"792345678.5833+258", 792345678, 583300000,
"+258", 0},
127 {
"702345678.5933-258", 702345678, 593300000,
"-258", 0},
128 {
"712345678.5033.258E02", 712345678, 503300000,
".258E02", 0},
129 {
"-722345678.5133", -722345679, 486700000,
"", 0},
130 {
"-742345678.000000625", -742345679, 999999375,
"", 0},
131 {
"-743345678.9999999994", -743345679, 1,
"", 0},
133 {
"-752345678.9999999996", -752345679, 0,
"", 0},
134 {
"5e-2", 0, 50000000,
"", 0},
135 {
"7e-7", 0, 700,
"", 0},
136 {
"6e-10", 0, 1,
"", 0},
137 {
"8e-11", 0, 0,
"", 0},
138 {
"-7e-12", 0, 0,
"", 0},
139 {
"-4e-6", -1, 999996000,
"", 0},
140 {
"-4.2e-2", -1, 958000000,
"", 0},
141 {
".5244", 0, 524400000,
"", 0},
142 {
"-.5244", -1, 475600000,
"", 0},
147 {
"e3", 0, 0,
"e3", 0},
149 {
"0x", 0, 0,
"x", 0},
150 {
"0.0000000000000000000000000000000000000001e40", 1, 0,
"", 0},
151 {
"10000000000000000000000000000000000000000e-40", 1, 0,
"", 0},
152 {NULL, 0, 0, NULL, 0}
157 {
"-73234567800.5233", LONG_MIN, 0,
"",
XLAL_ERANGE},
158 {NULL, 0, 0, NULL, 0}
161 {
"0x0", 0, 0,
"", 0},
162 {
"0x00", 0, 0,
"", 0},
163 {
"00x0", 0, 0,
"x0", 0},
164 {
"00x00", 0, 0,
"x00", 0},
165 {
"0x2CD7E24E.8", 752345678, 500000000,
"", 0},
166 {
"0x10P-6", 0, 250000000,
"", 0},
167 {NULL, 0, 0, NULL, 0}
174 for(testcase = general_testcases; testcase->
string; testcase++)
180 rc = strtol(
"7323456785", NULL, 0);
181 if ((rc == 0) && (errno == ERANGE))
182 for(testcase = overflow_testcases; testcase->
string; testcase++)
185 fprintf(stderr,
"WARNING: your C library can parse ints that LIGOTimeGPS can't store!\n");
189 if(strtod(
"0x.8", NULL) == 0.5)
190 for(testcase = hexfloat_testcases; testcase->
string; testcase++)
193 fprintf(stderr,
"WARNING: your C library can't parse hex floats!\n");
217 else if(strcmp(s, testcase->
correct))
233 {1, 1,
"1.000000001"},
235 {1, -1,
"0.999999999"},
236 {0, 1,
"0.000000001"},
238 {0, -1,
"-0.000000001"},
239 {-1, 1,
"-0.999999999"},
241 {-1, -1,
"-1.000000001"},
244 {0, 999999999,
"0.999999999"},
245 {0, -999999999,
"-0.999999999"},
246 {0, 1000000000,
"1"},
247 {0, -1000000000,
"-1"},
248 {0, 1000000001,
"1.000000001"},
249 {0, -1000000001,
"-1.000000001"},
250 {0, 2345678901,
"2.345678901"},
251 {0, -2345678901,
"-2.345678901"},
253 {2145678901, 0,
"2145678901"},
254 {2145678901, 1,
"2145678901.000000001"},
255 {2145678901, 2,
"2145678901.000000002"},
256 {2145678901, 3,
"2145678901.000000003"},
257 {2145678901, 4,
"2145678901.000000004"},
258 {2145678901, 5,
"2145678901.000000005"},
259 {-2145678901, 0,
"-2145678901"},
260 {-2145678901, -1,
"-2145678901.000000001"},
261 {-2145678901, -2,
"-2145678901.000000002"},
262 {-2145678901, -3,
"-2145678901.000000003"},
263 {-2145678901, -4,
"-2145678901.000000004"},
264 {-2145678901, -5,
"-2145678901.000000005"},
272 for(testcase = general_testcases; testcase->
correct; testcase++)
286 fprintf(stdout,
"Summary of GPS string conversion tests: ");
291 fprintf(stdout,
"all succeeded\n");
int XLALStrToGPS(LIGOTimeGPS *t, const char *nptr, char **endptr)
Parse an ASCII string into a LIGOTimeGPS structure.
static int test_XLALGPSToStr(void)
static int runtest_XLALStrToGPS(const struct TESTCASE_StrToGPS *testcase)
static int runtest_XLALGPSToStr(const struct TESTCASE_GPSToStr *testcase)
static int test_XLALStrToGPS(void)
char * XLALGPSToStr(char *, const LIGOTimeGPS *t)
Return a string containing the ASCII base 10 representation of a LIGOTimeGPS.
uint64_t UINT8
Eight-byte unsigned integer; on some platforms this is equivalent to unsigned long int instead.
int XLALGetBaseErrno(void)
Gets the XLAL base error number ignoring the internal-function-failed flag.
int XLALClearErrno(void)
Clears the XLAL error number, returns the old value.
@ XLAL_ERANGE
Output range error.
int XLALGPSCmp(const LIGOTimeGPS *t0, const LIGOTimeGPS *t1)
Compares two GPS times.
LIGOTimeGPS * XLALGPSSet(LIGOTimeGPS *epoch, INT4 gpssec, INT8 gpsnan)
Sets GPS time given GPS integer seconds and residual nanoseconds.
INT8 XLALGPSToINT8NS(const LIGOTimeGPS *epoch)
Converts GPS time to nano seconds stored as an INT8.
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.