| 41 | } |
| 42 | } |
| 43 | char * |
| 44 | rtodms(char *s, double r, int pos, int neg) { |
| 45 | int deg, min, sign; |
| 46 | char *ss = s; |
| 47 | double sec; |
| 48 | |
| 49 | if (r < 0) { |
| 50 | r = -r; |
| 51 | if (!pos) { *ss++ = '-'; sign = 0; } |
| 52 | else sign = neg; |
| 53 | } else |
| 54 | sign = pos; |
| 55 | r = floor(r * CONV + .5); |
| 56 | sec = fmod(r / RES, 60.); |
| 57 | r = floor(r / RES60); |
| 58 | min = (int)fmod(r, 60.); |
| 59 | r = floor(r / 60.); |
| 60 | deg = (int)r; |
| 61 | |
| 62 | if (dolong) |
| 63 | (void)sprintf(ss,format,deg,min,sec,sign); |
| 64 | else if (sec != 0.0) { |
| 65 | char *p, *q; |
| 66 | /* double prime + pos/neg suffix (if included) + NUL */ |
| 67 | size_t suffix_len = sign ? 3 : 2; |
| 68 | |
| 69 | (void)sprintf(ss,format,deg,min,sec,sign); |
| 70 | /* Replace potential decimal comma by decimal point for non C locale */ |
| 71 | for( p = ss; *p != '\0'; ++p ) { |
| 72 | if( *p == ',' ) { |
| 73 | *p = '.'; |
| 74 | break; |
| 75 | } |
| 76 | } |
| 77 | for (q = p = ss + strlen(ss) - suffix_len; *p == '0'; --p) ; |
| 78 | if (*p != '.') |
| 79 | ++p; |
| 80 | if (++q != p) |
| 81 | (void)memmove(p, q, suffix_len); |
| 82 | } else if (min) |
| 83 | (void)sprintf(ss,"%dd%d'%c",deg,min,sign); |
| 84 | else |
| 85 | (void)sprintf(ss,"%dd%c",deg, sign); |
| 86 | return s; |
| 87 | } |
no test coverage detected