69 LOCAL const char digits[] =
"0123456789";
70 LOCAL const char cDegree[] =
"°";
71 LOCAL const char cMinute[] =
"′";
72 LOCAL const char cSecond[] =
"″";
74 LOCAL const char decimalChar =
'.';
75 LOCAL const char fieldSeparator =
',';
111 const unsigned minLen = 8 + (
sizeof(cDegree) - 1) + (
sizeof(cMinute) - 1)
112 + (
sizeof(cSecond) - 1);
120 if (
sizeof(angle_asxd) > 4) {
122 if (decimals > 9) { decimals = 9; }
125 if (decimals > 3) { decimals = 3; }
129 reqLen = minLen + decimals + (decimals > 0 ? 1 : 0);
135 for (i = 0; i < decimals; i++) {
138 angle_asxd = lround(angle_deg * 3600.0 * roundup);
140 angle_asxd = -angle_asxd;
147 i -=
sizeof(cSecond) - 1;
148 memcpy(&destStr[i], cSecond,
sizeof(cSecond) - 1);
150 q = ldiv(angle_asxd, 10);
151 destStr[--i] = digits[q.rem];
152 for (j = decimals; j > 0; j--) {
154 destStr[--i] = decimalChar;
156 q = ldiv(q.quot, 10);
157 destStr[--i] = digits[q.rem];
160 destStr[--i] = digits[q.rem];
163 i -=
sizeof(cMinute) - 1;
164 memcpy(&destStr[i], cMinute,
sizeof(cMinute) - 1);
166 q = ldiv(q.quot, 10);
167 destStr[--i] = digits[q.rem];
169 destStr[--i] = digits[q.rem];
172 i -=
sizeof(cDegree) - 1;
173 memcpy(&destStr[i], cDegree,
sizeof(cDegree) - 1);
179 for (j = 0; (j < 1) || (q.quot != 0); j++) {
180 q = ldiv(q.quot, 10);
181 destStr[--i] = digits[q.rem];
183 destStr[--i] = (angle_deg < 0.0) ?
'-' :
'+';
222 if (
sizeof(angle_sxd) > 4) {
224 if (decimals > 9) { decimals = 9; }
227 if (decimals > 4) { decimals = 4; }
231 reqLen = 9 + decimals + (decimals > 0 ? 1 : 0);
238 for (i = 0; i < decimals; i++) {
241 angle_sxd = lround(angle_h * 3600.0 * roundup);
243 angle_sxd = -angle_sxd;
249 q = ldiv(angle_sxd, 10);
250 destStr[--i] = digits[q.rem];
251 for (j = decimals; j > 0; j--) {
253 destStr[--i] = decimalChar;
255 q = ldiv(q.quot, 10);
256 destStr[--i] = digits[q.rem];
259 destStr[--i] = digits[q.rem];
263 q = ldiv(q.quot, 10);
264 destStr[--i] = digits[q.rem];
266 destStr[--i] = digits[q.rem];
274 for (j = 0; j < 2; j++) {
275 q = ldiv(q.quot, 10);
276 destStr[--i] = digits[q.rem];
279 destStr[--i] = (angle_h < 0.0) ?
'-' :
'+';
327 bool isNegative =
false;
328 bool pointFound =
false;
336 double results[4] = {0.0, -1.0, 0.0, 0.0};
337 double *res = results;
340 stStarting, stDegHr, stSeparator1, stMins,
341 stSeparator2, stSecs, stEnding
342 } decodeState = stStarting;
344 for (ch = angleStr; *ch !=
'\0'; ch++) {
345 switch (decodeState) {
347 if (*ch ==
'-') { isNegative =
true; }
352 *(++res) = (
double)(*ch -
'0');
360 if (*ch == decimalChar) {
364 }
else if (isdigit(*ch)) {
367 frac = (double)(*ch -
'0') / divideBy;
370 *res = (10.0 * *res) + (
double)(*ch -
'0');
375 if ((pointFound) || (decodeState == stSecs)) {
379 }
else if (*ch == fieldSeparator) {
383 decodeState = stEnding;
409 if (results[1] < 0.0) {
414 if (results[3] >= 60.0) { status = INVALID_ANGLE; }
415 if (results[2] >= 60.0) { status = INVALID_ANGLE; }
416 if (error != NULL) { *error = status; }
417 if (endPtr != NULL) { *endPtr = ch; }
419 results[0] = results[1] + results[2] / 60.0 + results[3] / 3600.0;
420 if (isNegative) { results[0] = -results[0]; }
433 int y, m, d, h, mins;
437 printf(
"%04d-%02d-%02d %02d:%02d:%06.3f", y, m, d, h, mins, s);