24 +
"d not in [-" + to_string(
Math::qd)
25 +
"d, " + to_string(
Math::qd) +
"d]");
26 if (isnan(lat) || isnan(lon)) {
32 if (lat ==
Math::qd) lat *= (1 - numeric_limits<real>::epsilon() / 2);
33 prec = max(0, min(
int(maxprec_), prec));
35 x = int(floor(lon * m_)) - lonorig_ * m_,
36 y = int(floor(lat * m_)) - latorig_ * m_,
37 ilon = x * mult1_ / m_,
38 ilat = y * mult1_ / m_;
39 x -= ilon * m_ / mult1_; y -= ilat * m_ / mult1_;
42 for (
int c = lonlen_; c--;) {
43 gars1[c] = digits_[ ilon % baselon_]; ilon /= baselon_;
45 for (
int c = latlen_; c--;) {
46 gars1[lonlen_ + c] = letters_[ilat % baselat_]; ilat /= baselat_;
49 ilon = x / mult3_; ilat = y / mult3_;
50 gars1[baselen_] = digits_[mult2_ * (mult2_ - 1 - ilat) + ilon + 1];
52 ilon = x % mult3_; ilat = y % mult3_;
53 gars1[baselen_ + 1] = digits_[mult3_ * (mult3_ - 1 - ilat) + ilon + 1];
56 gars.resize(baselen_ + prec);
57 copy(gars1, gars1 + baselen_ + prec, gars.begin());
61 int& prec,
bool centerp) {
62 int len = int(gars.length());
64 toupper(gars[0]) ==
'I' &&
65 toupper(gars[1]) ==
'N' &&
66 toupper(gars[2]) ==
'V') {
71 throw GeographicErr(
"GARS must have at least 5 characters " + gars);
73 throw GeographicErr(
"GARS can have at most 7 characters " + gars);
74 int prec1 = len - baselen_;
76 for (
int c = 0; c < lonlen_; ++c) {
80 ilon = ilon * baselon_ + k;
82 if (!(ilon >= 1 && ilon <= 2 *
Math::td))
83 throw GeographicErr(
"Initial digits in GARS must lie in [1, 720] " +
87 for (
int c = 0; c < latlen_; ++c) {
90 throw GeographicErr(
"Illegal letters in GARS " + gars.substr(3,2));
91 ilat = ilat * baselat_ + k;
94 throw GeographicErr(
"GARS letters must lie in [AA, QZ] " + gars);
97 lat1 = ilat + latorig_ * unit,
98 lon1 = ilon + lonorig_ * unit;
101 if (!(k >= 1 && k <= mult2_ * mult2_))
102 throw GeographicErr(
"6th character in GARS must [1, 4] " + gars);
105 lat1 = mult2_ * lat1 + (mult2_ - 1 - k / mult2_);
106 lon1 = mult2_ * lon1 + (k % mult2_);
110 throw GeographicErr(
"7th character in GARS must [1, 9] " + gars);
113 lat1 = mult3_ * lat1 + (mult3_ - 1 - k / mult3_);
114 lon1 = mult3_ * lon1 + (k % mult3_);
118 unit *= 2; lat1 = 2 * lat1 + 1; lon1 = 2 * lon1 + 1;