Skip to content

Commit 27afb99

Browse files
authored
Merge pull request #67 from r-spatial/dewey-dev
More fixes for Solaris
2 parents 08cbc06 + efeec67 commit 27afb99

File tree

13 files changed

+98
-58
lines changed

13 files changed

+98
-58
lines changed

data-raw/update-s2.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ print_next <- function() {
8787
cli::cat_bullet("Remove extra semi-colons because of FROMHOST_TYPE_MAP macro (utils/endian/endian.h#565)")
8888
cli::cat_bullet(
8989
"Check for definition of IS_LITTLE_ENDIAN and IS_BIG_ENDIAN to allow configure script ",
90-
"override (s2/base/port.h:273) without macro redefinition warnings"
90+
"override (s2/base/port.h:273) without macro redefinition warnings (for CRAN Solaris)"
91+
)
92+
cli::cat_bullet(
93+
"Replace calls to log(<int literal>), sqrt(<int literal>), and ldexp(<int literal>, ...) ",
94+
"with an explicit doouble (e.g., sqrt(3) -> sqrt(3.0) to fix build errors on CRAN Solaris"
9195
)
9296
cli::cat_bullet("Replace `abort()` with `cpp_compat_abort()`")
9397
cli::cat_bullet("Replace `cerr`/`cout` with `cpp_compat_cerr`/`cpp_compat_cout`")

inst/include/s2/base/port.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ inline void UnalignedCopy64(const void *src, void *dst) {
900900
((__GNUC__ >= 3 || defined(__clang__)) && defined(__ANDROID__)) || \
901901
defined(__ASYLO__))
902902
inline void *aligned_malloc(size_t size, size_t minimum_alignment) {
903-
#if defined(__ANDROID__) || defined(OS_ANDROID) || defined(__ASYLO__) || defined(_WIN32)
903+
#if defined(__ANDROID__) || defined(OS_ANDROID) || defined(__ASYLO__) || defined(_WIN32) || defined(__sun) || defined(sun)
904904
# if defined(_WIN32)
905905
return _aligned_malloc(size, minimum_alignment);
906906
# else

src/s2/s2builder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ void S2Builder::Init(const Options& options) {
272272
// error in the calculation to compare this distance against the bound.
273273
double d = sin(edge_snap_radius);
274274
edge_snap_radius_sin2_ = d * d;
275-
edge_snap_radius_sin2_ += ((9.5 * d + 2.5 + 2 * sqrt(3)) * d +
275+
edge_snap_radius_sin2_ += ((9.5 * d + 2.5 + 2 * sqrt(3.0)) * d +
276276
9 * DBL_EPSILON) * DBL_EPSILON;
277277

278278
// Initialize the current label set.

src/s2/s2edge_clipping.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ bool ClipToPaddedFace(const S2Point& a_xyz, const S2Point& b_xyz, int face,
356356
// TODO(ericv): This is a temporary hack until I rewrite S2::RobustCrossProd;
357357
// it avoids loss of precision in Normalize() when the vector is so small
358358
// that it underflows.
359-
if (max(fabs(n[0]), max(fabs(n[1]), fabs(n[2]))) < ldexp(1, -511)) {
360-
n *= ldexp(1, 563);
359+
if (max(fabs(n[0]), max(fabs(n[1]), fabs(n[2]))) < ldexp(1.0, -511)) {
360+
n *= ldexp(1.0, 563);
361361
} // END OF HACK
362362
n = n.Normalize();
363363
S2PointUVW a_tangent = n.CrossProd(a);

src/s2/s2edge_crosser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ inline int S2EdgeCrosser::CrossingSignInternal2(const S2Point& d) {
5252
// DotProd() below is DBL_EPSILON. (There is also a small relative error
5353
// term that is insignificant because we are comparing the result against a
5454
// constant that is very close to zero.)
55-
static const double kError = (1.5 + 1/sqrt(3)) * DBL_EPSILON;
55+
static const double kError = (1.5 + 1/sqrt(3.0)) * DBL_EPSILON;
5656
if ((c_->DotProd(a_tangent_) > kError && d.DotProd(a_tangent_) > kError) ||
5757
(c_->DotProd(b_tangent_) > kError && d.DotProd(b_tangent_) > kError)) {
5858
return -1;

src/s2/s2edge_crossings.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ static bool GetIntersectionSimple(const Vector3<T>& a0, const Vector3<T>& a1,
164164
// long as "result_len" is at least kMinResultLen defined below.
165165

166166
constexpr T T_ERR = s2pred::rounding_epsilon<T>();
167-
static const T kMinNormalLength = (16 * sqrt(3) + 24) * DBL_ERR;
167+
static const T kMinNormalLength = (16 * sqrt(3.0) + 24) * DBL_ERR;
168168
static const T kMinResultLen =
169-
12 / (kIntersectionError.radians() / T_ERR - (2 + 2 * sqrt(3)));
169+
12 / (kIntersectionError.radians() / T_ERR - (2 + 2 * sqrt(3.0)));
170170

171171
// On some platforms "long double" is the same as "double", and on these
172172
// platforms this method always returns false (e.g. ARM, Win32). Rather
@@ -240,7 +240,7 @@ static T GetProjection(const Vector3<T>& x,
240240
// |(A.B)'-(A.B)| <= (1.5 * (A.B) + 1.5 * ||A|| * ||B||) * T_ERR
241241
// ||(X-Y)'-(X-Y)|| <= ||X-Y|| * T_ERR
242242
constexpr T T_ERR = s2pred::rounding_epsilon<T>();
243-
*error = (((3.5 + 2 * sqrt(3)) * a_norm_len + 32 * sqrt(3) * DBL_ERR)
243+
*error = (((3.5 + 2 * sqrt(3.0)) * a_norm_len + 32 * sqrt(3.0) * DBL_ERR)
244244
* dist + 1.5 * fabs(result)) * T_ERR;
245245
return result;
246246
}

src/s2/s2edge_distances.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ static double GetUpdateMinInteriorDistanceMaxError(S1ChordAngle dist) {
229229
// parallel to the plane containing the edge respectively.
230230
double b = min(1.0, 0.5 * dist.length2());
231231
double a = sqrt(b * (2 - b));
232-
return ((2.5 + 2 * sqrt(3) + 8.5 * a) * a +
233-
(2 + 2 * sqrt(3) / 3 + 6.5 * (1 - b)) * b +
234-
(23 + 16 / sqrt(3)) * DBL_EPSILON) * DBL_EPSILON;
232+
return ((2.5 + 2 * sqrt(3.0) + 8.5 * a) * a +
233+
(2 + 2 * sqrt(3.0) / 3 + 6.5 * (1 - b)) * b +
234+
(23 + 16 / sqrt(3.0)) * DBL_EPSILON) * DBL_EPSILON;
235235
}
236236

237237
double GetUpdateMinDistanceMaxError(S1ChordAngle dist) {

src/s2/s2metrics.cc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ const LengthMetric kAvgAngleSpan(M_PI / 2); // 1.571
4848
// This is true for all projections.
4949

5050
const LengthMetric kMinWidth(
51-
S2_PROJECTION == S2_LINEAR_PROJECTION ? sqrt(2. / 3) : // 0.816
52-
S2_PROJECTION == S2_TAN_PROJECTION ? M_PI / (2 * sqrt(2)) : // 1.111
53-
S2_PROJECTION == S2_QUADRATIC_PROJECTION ? 2 * sqrt(2) / 3 : // 0.943
51+
S2_PROJECTION == S2_LINEAR_PROJECTION ? sqrt(2.0 / 3.0) : // 0.816
52+
S2_PROJECTION == S2_TAN_PROJECTION ? M_PI / (2 * sqrt(2.0)) : // 1.111
53+
S2_PROJECTION == S2_QUADRATIC_PROJECTION ? 2 * sqrt(2.0) / 3 : // 0.943
5454
0);
5555

5656
const LengthMetric kMaxWidth(kMaxAngleSpan.deriv());
@@ -63,9 +63,9 @@ const LengthMetric kAvgWidth(
6363
0);
6464

6565
const LengthMetric kMinEdge(
66-
S2_PROJECTION == S2_LINEAR_PROJECTION ? 2 * sqrt(2) / 3 : // 0.943
67-
S2_PROJECTION == S2_TAN_PROJECTION ? M_PI / (2 * sqrt(2)) : // 1.111
68-
S2_PROJECTION == S2_QUADRATIC_PROJECTION ? 2 * sqrt(2) / 3 : // 0.943
66+
S2_PROJECTION == S2_LINEAR_PROJECTION ? 2 * sqrt(2.0) / 3 : // 0.943
67+
S2_PROJECTION == S2_TAN_PROJECTION ? M_PI / (2 * sqrt(2.0)) : // 1.111
68+
S2_PROJECTION == S2_QUADRATIC_PROJECTION ? 2 * sqrt(2.0) / 3 : // 0.943
6969
0);
7070

7171
const LengthMetric kMaxEdge(kMaxAngleSpan.deriv());
@@ -78,14 +78,14 @@ const LengthMetric kAvgEdge(
7878
0);
7979

8080
const LengthMetric kMinDiag(
81-
S2_PROJECTION == S2_LINEAR_PROJECTION ? 2 * sqrt(2) / 3 : // 0.943
82-
S2_PROJECTION == S2_TAN_PROJECTION ? M_PI * sqrt(2) / 3 : // 1.481
83-
S2_PROJECTION == S2_QUADRATIC_PROJECTION ? 8 * sqrt(2) / 9 : // 1.257
81+
S2_PROJECTION == S2_LINEAR_PROJECTION ? 2 * sqrt(2.0) / 3 : // 0.943
82+
S2_PROJECTION == S2_TAN_PROJECTION ? M_PI * sqrt(2.0) / 3 : // 1.481
83+
S2_PROJECTION == S2_QUADRATIC_PROJECTION ? 8 * sqrt(2.0) / 9 : // 1.257
8484
0);
8585

8686
const LengthMetric kMaxDiag(
87-
S2_PROJECTION == S2_LINEAR_PROJECTION ? 2 * sqrt(2) : // 2.828
88-
S2_PROJECTION == S2_TAN_PROJECTION ? M_PI * sqrt(2. / 3) : // 2.565
87+
S2_PROJECTION == S2_LINEAR_PROJECTION ? 2 * sqrt(2.0) : // 2.828
88+
S2_PROJECTION == S2_TAN_PROJECTION ? M_PI * sqrt(2.0 / 3.0) : // 2.565
8989
S2_PROJECTION == S2_QUADRATIC_PROJECTION ? 2.438654594434021032 : // 2.439
9090
0);
9191

@@ -96,9 +96,9 @@ const LengthMetric kAvgDiag(
9696
0);
9797

9898
const AreaMetric kMinArea(
99-
S2_PROJECTION == S2_LINEAR_PROJECTION ? 4 / (3 * sqrt(3)) : // 0.770
100-
S2_PROJECTION == S2_TAN_PROJECTION ? (M_PI*M_PI) / (4*sqrt(2)) : // 1.745
101-
S2_PROJECTION == S2_QUADRATIC_PROJECTION ? 8 * sqrt(2) / 9 : // 1.257
99+
S2_PROJECTION == S2_LINEAR_PROJECTION ? 4 / (3 * sqrt(3.0)) : // 0.770
100+
S2_PROJECTION == S2_TAN_PROJECTION ? (M_PI*M_PI) / (4*sqrt(2.0)) : // 1.745
101+
S2_PROJECTION == S2_QUADRATIC_PROJECTION ? 8 * sqrt(2.0) / 9 : // 1.257
102102
0);
103103

104104
const AreaMetric kMaxArea(
@@ -111,12 +111,12 @@ const AreaMetric kAvgArea(4 * M_PI / 6); // 2.094
111111
// This is true for all projections.
112112

113113
const double kMaxEdgeAspect = (
114-
S2_PROJECTION == S2_LINEAR_PROJECTION ? sqrt(2) : // 1.414
115-
S2_PROJECTION == S2_TAN_PROJECTION ? sqrt(2) : // 1.414
114+
S2_PROJECTION == S2_LINEAR_PROJECTION ? sqrt(2.0) : // 1.414
115+
S2_PROJECTION == S2_TAN_PROJECTION ? sqrt(2.0) : // 1.414
116116
S2_PROJECTION == S2_QUADRATIC_PROJECTION ? 1.442615274452682920 : // 1.443
117117
0);
118118

119-
const double kMaxDiagAspect = sqrt(3); // 1.732
119+
const double kMaxDiagAspect = sqrt(3.0); // 1.732
120120
// This is true for all projections.
121121

122122
} // namespace S2

src/s2/s2polygon.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ void S2Polygon::InitToSimplifiedInCell(
10731073
// want the bound in terms of (u = 2 * s - 1) rather than "s" itself.
10741074
// Consulting s2metrics.cc, this value is sqrt(2/3)/2 = sqrt(1/6).
10751075
// Going back to the original problem, this gives:
1076-
double boundary_tolerance_uv = sqrt(6) * boundary_tolerance.radians();
1076+
double boundary_tolerance_uv = sqrt(6.0) * boundary_tolerance.radians();
10771077

10781078
// The first pass yields a collection of simplified polylines that preserve
10791079
// the original cyclic vertex order.

src/s2/s2predicates.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ inline double GetSin2Distance(const S2Point& x, const S2Point& y,
341341
// distances as small as DBL_ERR.
342342
S2Point n = (x - y).CrossProd(x + y);
343343
double d2 = 0.25 * n.Norm2();
344-
*error = ((21 + 4 * sqrt(3)) * DBL_ERR * d2 +
345-
32 * sqrt(3) * DBL_ERR * DBL_ERR * sqrt(d2) +
344+
*error = ((21 + 4 * sqrt(3.0)) * DBL_ERR * d2 +
345+
32 * sqrt(3.0) * DBL_ERR * DBL_ERR * sqrt(d2) +
346346
768 * DBL_ERR * DBL_ERR * DBL_ERR * DBL_ERR);
347347
return d2;
348348
}
@@ -359,8 +359,8 @@ inline long double GetSin2Distance(const Vector3_ld& x, const Vector3_ld& y,
359359
// the additional effort.)
360360
Vector3_ld n = (x - y).CrossProd(x + y);
361361
long double d2 = 0.25 * n.Norm2() / (x.Norm2() * y.Norm2());
362-
*error = ((13 + 4 * sqrt(3)) * LD_ERR * d2 +
363-
32 * sqrt(3) * DBL_ERR * LD_ERR * sqrt(d2) +
362+
*error = ((13 + 4 * sqrt(3.0)) * LD_ERR * d2 +
363+
32 * sqrt(3.0) * DBL_ERR * LD_ERR * sqrt(d2) +
364364
768 * DBL_ERR * DBL_ERR * LD_ERR * LD_ERR);
365365
return d2;
366366
}
@@ -593,7 +593,7 @@ int TriageCompareLineSin2Distance(const Vector3<T>& x, const Vector3<T>& a0,
593593
T n2sin2_r_error = 6 * T_ERR * n2sin2_r;
594594
T ax2, xDn = (x - GetClosestVertex(x, a0, a1, &ax2)).DotProd(n);
595595
T xDn2 = xDn * xDn;
596-
const T c1 = (((3.5 + 2 * sqrt(3)) * n1 + 32 * sqrt(3) * DBL_ERR) *
596+
const T c1 = (((3.5 + 2 * sqrt(3.0)) * n1 + 32 * sqrt(3.0) * DBL_ERR) *
597597
T_ERR * sqrt(ax2));
598598
T xDn2_error = 4 * T_ERR * xDn2 + (2 * fabs(xDn) + c1) * c1;
599599

@@ -633,7 +633,7 @@ int TriageCompareLineCos2Distance(const Vector3<T>& x, const Vector3<T>& a0,
633633
// The length of M = X.CrossProd(N) is the cosine of the distance.
634634
T m2 = x.CrossProd(n).Norm2();
635635
T m1 = sqrt(m2);
636-
T m1_error = ((1 + 8 / sqrt(3)) * n1 + 32 * sqrt(3) * DBL_ERR) * T_ERR;
636+
T m1_error = ((1 + 8 / sqrt(3.0)) * n1 + 32 * sqrt(3.0) * DBL_ERR) * T_ERR;
637637
T m2_error = 3 * T_ERR * m2 + (2 * m1 + m1_error) * m1_error;
638638

639639
// If we are using extended precision, then it is worthwhile to recompute
@@ -684,7 +684,7 @@ int TriageCompareEdgeDistance(const Vector3<T>& x, const Vector3<T>& a0,
684684
T a1_sign = a1_dir.DotProd(m);
685685
T n2 = n.Norm2();
686686
T n1 = sqrt(n2);
687-
T n1_error = ((3.5 + 8 / sqrt(3)) * n1 + 32 * sqrt(3) * DBL_ERR) * T_ERR;
687+
T n1_error = ((3.5 + 8 / sqrt(3.0)) * n1 + 32 * sqrt(3.0) * DBL_ERR) * T_ERR;
688688
T a0_sign_error = n1_error * a0_dir.Norm();
689689
T a1_sign_error = n1_error * a1_dir.Norm();
690690
if (fabs(a0_sign) < a0_sign_error || fabs(a1_sign) < a1_sign_error) {
@@ -771,8 +771,8 @@ int TriageCompareEdgeDirections(
771771
Vector3<T> nb = (b0 - b1).CrossProd(b0 + b1);
772772
T na_len = na.Norm(), nb_len = nb.Norm();
773773
T cos_ab = na.DotProd(nb);
774-
T cos_ab_error = ((5 + 4 * sqrt(3)) * na_len * nb_len +
775-
32 * sqrt(3) * DBL_ERR * (na_len + nb_len)) * T_ERR;
774+
T cos_ab_error = ((5 + 4 * sqrt(3.0)) * na_len * nb_len +
775+
32 * sqrt(3.0) * DBL_ERR * (na_len + nb_len)) * T_ERR;
776776
return (cos_ab > cos_ab_error) ? 1 : (cos_ab < -cos_ab_error) ? -1 : 0;
777777
}
778778

@@ -836,9 +836,9 @@ Vector3<T> GetCircumcenter(const Vector3<T>& a, const Vector3<T>& b,
836836
T bc_len = bc_diff.Norm();
837837
Vector3<T> mab = nab.CrossProd(ab_sum);
838838
Vector3<T> mbc = nbc.CrossProd(bc_sum);
839-
*error = (((16 + 24 * sqrt(3)) * T_ERR +
839+
*error = (((16 + 24 * sqrt(3.0)) * T_ERR +
840840
8 * DBL_ERR * (ab_len + bc_len)) * nab_len * nbc_len +
841-
128 * sqrt(3) * DBL_ERR * T_ERR * (nab_len + nbc_len) +
841+
128 * sqrt(3.0) * DBL_ERR * T_ERR * (nab_len + nbc_len) +
842842
3 * 4096 * DBL_ERR * DBL_ERR * T_ERR * T_ERR);
843843
return mab.CrossProd(mbc);
844844
}
@@ -860,7 +860,7 @@ int TriageEdgeCircumcenterSign(const Vector3<T>& x0, const Vector3<T>& x1,
860860

861861
T z_len = z.Norm();
862862
T nx_len = nx.Norm();
863-
T nx_error = ((1 + 2 * sqrt(3)) * nx_len + 32 * sqrt(3) * DBL_ERR) * T_ERR;
863+
T nx_error = ((1 + 2 * sqrt(3.0)) * nx_len + 32 * sqrt(3.0) * DBL_ERR) * T_ERR;
864864
T result_error = ((3 * T_ERR * nx_len + nx_error) * z_len + z_error * nx_len);
865865
return (result > result_error) ? 1 : (result < -result_error) ? -1 : 0;
866866
}
@@ -1174,7 +1174,7 @@ Excluded TriageVoronoiSiteExclusion(const Vector3<T>& a, const Vector3<T>& b,
11741174
T n2 = n.Norm2();
11751175
T n1 = sqrt(n2);
11761176
// This factor is used in the error terms of dot products with "n" below.
1177-
T Dn_error = ((3.5 + 2 * sqrt(3)) * n1 + 32 * sqrt(3) * DBL_ERR) * T_ERR;
1177+
T Dn_error = ((3.5 + 2 * sqrt(3.0)) * n1 + 32 * sqrt(3.0) * DBL_ERR) * T_ERR;
11781178

11791179
T cos_r = 1 - 0.5 * r2;
11801180
T sin2_r = r2 * (1 - 0.25 * r2);
@@ -1216,8 +1216,8 @@ Excluded TriageVoronoiSiteExclusion(const Vector3<T>& a, const Vector3<T>& b,
12161216
Vector3<T> aXb = (a - b).CrossProd(a + b); // 2 * a.CrossProd(b)
12171217
T aXb1 = aXb.Norm();
12181218
T sin_d = 0.5 * aXb.DotProd(n);
1219-
T sin_d_error = (4 * DBL_ERR + (2.5 + 2 * sqrt(3)) * T_ERR) * aXb1 * n1 +
1220-
16 * sqrt(3) * DBL_ERR * T_ERR * (aXb1 + n1);
1219+
T sin_d_error = (4 * DBL_ERR + (2.5 + 2 * sqrt(3.0)) * T_ERR) * aXb1 * n1 +
1220+
16 * sqrt(3.0) * DBL_ERR * T_ERR * (aXb1 + n1);
12211221

12221222
// If LHS(3) is definitely less than RHS(3), neither site excludes the other.
12231223
T result = abs_lhs3 - sin_d;

0 commit comments

Comments
 (0)