diff --git a/include/lsst/sphgeom/BigInteger.h b/include/lsst/sphgeom/BigInteger.h index 89ca2ba..0a54de5 100644 --- a/include/lsst/sphgeom/BigInteger.h +++ b/include/lsst/sphgeom/BigInteger.h @@ -36,7 +36,7 @@ #include #include #include - +#include namespace lsst { namespace sphgeom { @@ -53,7 +53,7 @@ class BigInteger { public: /// This constructor creates a zero-valued integer with the given digit /// array. - BigInteger(uint32_t * digits, unsigned capacity) : + BigInteger(std::uint32_t * digits, unsigned capacity) : _digits(digits), _capacity(capacity), _size(0), @@ -65,7 +65,7 @@ class BigInteger { _checkCapacity(b._size); _sign = b._sign; _size = b._size; - std::memcpy(_digits, b._digits, sizeof(uint32_t) * b._size); + std::memcpy(_digits, b._digits, sizeof(std::uint32_t) * b._size); } return *this; } @@ -82,26 +82,26 @@ class BigInteger { unsigned getCapacity() const { return _capacity; } /// `getDigits` returns the underlying digit array. - uint32_t const * getDigits() const { return _digits; } + std::uint32_t const * getDigits() const { return _digits; } /// `setToZero` sets this integer to zero. void setToZero() { _sign = 0; _size = 0; } /// `setTo` sets this integer to the given signed 64 bit integer value. - void setTo(int64_t x) { + void setTo(std::int64_t x) { if (x < 0) { - setTo(static_cast(-x)); + setTo(static_cast(-x)); _sign = -1; } else { - setTo(static_cast(x)); + setTo(static_cast(x)); } } /// `setTo` sets this integer to the given unsigned 64 bit integer value. - void setTo(uint64_t x) { + void setTo(std::uint64_t x) { _checkCapacity(2); - _digits[0] = static_cast(x); - _digits[1] = static_cast(x >> 32); + _digits[0] = static_cast(x); + _digits[1] = static_cast(x >> 32); _size = (_digits[1] == 0) ? (_digits[0] != 0) : 2; _sign = (_size != 0); } @@ -129,7 +129,7 @@ class BigInteger { } } - uint32_t * _digits; // Unowned + std::uint32_t * _digits; // Unowned unsigned _capacity; unsigned _size; int _sign; diff --git a/include/lsst/sphgeom/Box.h b/include/lsst/sphgeom/Box.h index 19edc25..508468c 100644 --- a/include/lsst/sphgeom/Box.h +++ b/include/lsst/sphgeom/Box.h @@ -35,6 +35,7 @@ /// longitude/latitude angle boxes on the unit sphere. #include +#include #include "AngleInterval.h" #include "LonLat.h" @@ -60,7 +61,7 @@ namespace sphgeom { /// - Box::allLongitudes().contains(b.getLon()) class Box : public Region { public: - static constexpr uint8_t TYPE_CODE = 'b'; + static constexpr std::uint8_t TYPE_CODE = 'b'; // Factory functions static Box fromDegrees(double lon1, double lat1, double lon2, double lat2) { @@ -340,14 +341,14 @@ class Box : public Region { Relationship relate(ConvexPolygon const &) const override; Relationship relate(Ellipse const &) const override; - std::vector encode() const override; + std::vector encode() const override; ///@{ /// `decode` deserializes a Box from a byte string produced by encode. - static std::unique_ptr decode(std::vector const & s) { + static std::unique_ptr decode(std::vector const & s) { return decode(s.data(), s.size()); } - static std::unique_ptr decode(uint8_t const * buffer, size_t n); + static std::unique_ptr decode(std::uint8_t const * buffer, size_t n); ///@} private: diff --git a/include/lsst/sphgeom/Chunker.h b/include/lsst/sphgeom/Chunker.h index 7aa2ba5..2a9e17f 100644 --- a/include/lsst/sphgeom/Chunker.h +++ b/include/lsst/sphgeom/Chunker.h @@ -48,8 +48,8 @@ namespace sphgeom { /// /// TODO(smm): implement a more memory efficient representation than this. struct SubChunks { - int32_t chunkId; - std::vector subChunkIds; + std::int32_t chunkId; + std::vector subChunkIds; SubChunks() : chunkId(-1) {} @@ -72,8 +72,8 @@ struct SubChunks { /// subchunks. class Chunker { public: - Chunker(int32_t numStripes, - int32_t numSubStripesPerStripe); + Chunker(std::int32_t numStripes, + std::int32_t numSubStripesPerStripe); bool operator==(Chunker const & c) const { return _numStripes == c._numStripes && @@ -87,19 +87,19 @@ class Chunker { /// `getNumStripes` returns the number of fixed-height latitude intervals /// in the sky subdivision. - int32_t getNumStripes() const { + std::int32_t getNumStripes() const { return _numStripes; } /// `getNumSubStripesPerStripe` returns the number of fixed-height latitude /// sub-intervals in each stripe. - int32_t getNumSubStripesPerStripe() const { + std::int32_t getNumSubStripesPerStripe() const { return _numSubStripesPerStripe; } /// `getChunksIntersecting` returns all the chunks that potentially /// intersect the given region. - std::vector getChunksIntersecting(Region const & r) const; + std::vector getChunksIntersecting(Region const & r) const; /// `getSubChunksIntersecting` returns all the sub-chunks that potentially /// intersect the given region. @@ -107,33 +107,33 @@ class Chunker { /// `getAllChunks` returns the complete set of chunk IDs for the unit /// sphere. - std::vector getAllChunks() const; + std::vector getAllChunks() const; /// `getAllSubChunks` returns the complete set of sub-chunk IDs /// for the given chunk. - std::vector getAllSubChunks(int32_t chunkId) const; + std::vector getAllSubChunks(std::int32_t chunkId) const; /// Return 'true' if the specified chunk number is valid - bool valid(int32_t chunkId) const; + bool valid(std::int32_t chunkId) const; - Box getChunkBoundingBox(int32_t stripe, int32_t chunk) const; - Box getSubChunkBoundingBox(int32_t subStripe, int32_t subChunk) const; + Box getChunkBoundingBox(std::int32_t stripe, std::int32_t chunk) const; + Box getSubChunkBoundingBox(std::int32_t subStripe, std::int32_t subChunk) const; /// Return the stripe for the specified chunkId - int32_t getStripe(int32_t chunkId) const { + std::int32_t getStripe(std::int32_t chunkId) const { return chunkId / (2 * _numStripes); } /// Return the chunk for the given chunkId and stripe - int32_t getChunk(int32_t chunkId, int32_t stripe) const { + std::int32_t getChunk(std::int32_t chunkId, std::int32_t stripe) const { return chunkId - stripe*2*_numStripes; } private: struct Stripe { Angle chunkWidth; - int32_t numChunksPerStripe; - int32_t numSubChunksPerChunk; + std::int32_t numChunksPerStripe; + std::int32_t numSubChunksPerChunk; Stripe() : chunkWidth(0), @@ -144,19 +144,19 @@ class Chunker { struct SubStripe { Angle subChunkWidth; - int32_t numSubChunksPerChunk; + std::int32_t numSubChunksPerChunk; SubStripe() : subChunkWidth(), numSubChunksPerChunk(0) {} }; - int32_t _getChunkId(int32_t stripe, int32_t chunk) const { + std::int32_t _getChunkId(std::int32_t stripe, std::int32_t chunk) const { return stripe * 2 * _numStripes + chunk; } - int32_t _getSubChunkId(int32_t stripe, int32_t subStripe, - int32_t chunk, int32_t subChunk) const { - int32_t y = subStripe - stripe * _numSubStripesPerStripe; - int32_t x = subChunk - + std::int32_t _getSubChunkId(std::int32_t stripe, std::int32_t subStripe, + std::int32_t chunk, std::int32_t subChunk) const { + std::int32_t y = subStripe - stripe * _numSubStripesPerStripe; + std::int32_t x = subChunk - chunk * _subStripes[subStripe].numSubChunksPerChunk; return y * _maxSubChunksPerSubStripeChunk + x; } @@ -164,15 +164,15 @@ class Chunker { void _getSubChunks(std::vector & subChunks, Region const & r, NormalizedAngleInterval const & lon, - int32_t stripe, - int32_t chunk, - int32_t minSS, - int32_t maxSS) const; - - int32_t _numStripes; - int32_t _numSubStripesPerStripe; - int32_t _numSubStripes; - int32_t _maxSubChunksPerSubStripeChunk; + std::int32_t stripe, + std::int32_t chunk, + std::int32_t minSS, + std::int32_t maxSS) const; + + std::int32_t _numStripes; + std::int32_t _numSubStripesPerStripe; + std::int32_t _numSubStripes; + std::int32_t _maxSubChunksPerSubStripeChunk; Angle _subStripeHeight; std::vector _stripes; std::vector _subStripes; diff --git a/include/lsst/sphgeom/Circle.h b/include/lsst/sphgeom/Circle.h index 0e33111..979ac6a 100644 --- a/include/lsst/sphgeom/Circle.h +++ b/include/lsst/sphgeom/Circle.h @@ -35,6 +35,7 @@ /// regions on the unit sphere. #include +#include #include "Region.h" #include "UnitVector3d.h" @@ -52,7 +53,7 @@ namespace sphgeom { /// angles. class Circle : public Region { public: - static constexpr uint8_t TYPE_CODE = 'c'; + static constexpr std::uint8_t TYPE_CODE = 'c'; static Circle empty() { return Circle(); } @@ -251,14 +252,14 @@ class Circle : public Region { Relationship relate(ConvexPolygon const &) const override; Relationship relate(Ellipse const &) const override; - std::vector encode() const override; + std::vector encode() const override; ///@{ /// `decode` deserializes a Circle from a byte string produced by encode. - static std::unique_ptr decode(std::vector const & s) { + static std::unique_ptr decode(std::vector const & s) { return decode(s.data(), s.size()); } - static std::unique_ptr decode(uint8_t const * buffer, size_t n); + static std::unique_ptr decode(std::uint8_t const * buffer, size_t n); ///@} private: diff --git a/include/lsst/sphgeom/CompoundRegion.h b/include/lsst/sphgeom/CompoundRegion.h index df5b060..c4b6067 100644 --- a/include/lsst/sphgeom/CompoundRegion.h +++ b/include/lsst/sphgeom/CompoundRegion.h @@ -37,6 +37,7 @@ #include #include #include +#include #include "Region.h" #include "UnitVector3d.h" @@ -82,10 +83,10 @@ class CompoundRegion : public Region { ///@{ /// `decode` deserializes a CompoundRegion from a byte string produced by /// encode. - static std::unique_ptr decode(std::vector const &s) { + static std::unique_ptr decode(std::vector const &s) { return decode(s.data(), s.size()); } - static std::unique_ptr decode(uint8_t const *buffer, size_t n); + static std::unique_ptr decode(std::uint8_t const *buffer, size_t n); ///@} protected: @@ -107,7 +108,7 @@ class CompoundRegion : public Region { /// nested operand regions and combining the results. class UnionRegion : public CompoundRegion { public: - static constexpr uint8_t TYPE_CODE = 'u'; + static constexpr std::uint8_t TYPE_CODE = 'u'; using CompoundRegion::CompoundRegion; @@ -119,15 +120,15 @@ class UnionRegion : public CompoundRegion { using Region::contains; bool contains(UnitVector3d const &v) const override; Relationship relate(Region const &r) const override; - std::vector encode() const override { return _encode(TYPE_CODE); } + std::vector encode() const override { return _encode(TYPE_CODE); } ///@{ /// `decode` deserializes a UnionRegion from a byte string produced by /// encode. - static std::unique_ptr decode(std::vector const &s) { + static std::unique_ptr decode(std::vector const &s) { return decode(s.data(), s.size()); } - static std::unique_ptr decode(uint8_t const *buffer, size_t n) { + static std::unique_ptr decode(std::uint8_t const *buffer, size_t n) { return std::make_unique(_decode(TYPE_CODE, buffer, n)); } ///@} @@ -140,7 +141,7 @@ class UnionRegion : public CompoundRegion { /// its nested operand regions and combining the results. class IntersectionRegion : public CompoundRegion { public: - static constexpr uint8_t TYPE_CODE = 'i'; + static constexpr std::uint8_t TYPE_CODE = 'i'; using CompoundRegion::CompoundRegion; @@ -152,15 +153,15 @@ class IntersectionRegion : public CompoundRegion { using Region::contains; bool contains(UnitVector3d const &v) const override; Relationship relate(Region const &r) const override; - std::vector encode() const override { return _encode(TYPE_CODE); } + std::vector encode() const override { return _encode(TYPE_CODE); } ///@{ /// `decode` deserializes a IntersetionRegion from a byte string produced /// by encode. - static std::unique_ptr decode(std::vector const &s) { + static std::unique_ptr decode(std::vector const &s) { return decode(s.data(), s.size()); } - static std::unique_ptr decode(uint8_t const *buffer, size_t n) { + static std::unique_ptr decode(std::uint8_t const *buffer, size_t n) { return std::make_unique(_decode(TYPE_CODE, buffer, n)); } ///@} diff --git a/include/lsst/sphgeom/ConvexPolygon.h b/include/lsst/sphgeom/ConvexPolygon.h index 8426589..c512775 100644 --- a/include/lsst/sphgeom/ConvexPolygon.h +++ b/include/lsst/sphgeom/ConvexPolygon.h @@ -36,6 +36,7 @@ #include #include +#include #include "Region.h" #include "UnitVector3d.h" @@ -63,7 +64,7 @@ namespace sphgeom { /// convex hull of a point set. class ConvexPolygon : public Region { public: - static constexpr uint8_t TYPE_CODE = 'p'; + static constexpr std::uint8_t TYPE_CODE = 'p'; /// `convexHull` returns the convex hull of the given set of points if it /// exists and throws an exception otherwise. Though points are supplied @@ -157,14 +158,14 @@ class ConvexPolygon : public Region { Relationship relate(ConvexPolygon const &) const override; Relationship relate(Ellipse const &) const override; - std::vector encode() const override; + std::vector encode() const override; ///@{ /// `decode` deserializes a ConvexPolygon from a byte string produced by encode. - static std::unique_ptr decode(std::vector const & s) { + static std::unique_ptr decode(std::vector const & s) { return decode(s.data(), s.size()); } - static std::unique_ptr decode(uint8_t const * buffer, size_t n); + static std::unique_ptr decode(std::uint8_t const * buffer, size_t n); ///@} private: diff --git a/include/lsst/sphgeom/Ellipse.h b/include/lsst/sphgeom/Ellipse.h index 88fdcc2..40d40f4 100644 --- a/include/lsst/sphgeom/Ellipse.h +++ b/include/lsst/sphgeom/Ellipse.h @@ -176,7 +176,7 @@ namespace sphgeom { /// but tan is finite since a is rational and cannot be exactly equal to ±π/2. class Ellipse : public Region { public: - static constexpr uint8_t TYPE_CODE = 'e'; + static constexpr std::uint8_t TYPE_CODE = 'e'; static Ellipse empty() { return Ellipse(); } @@ -303,14 +303,14 @@ class Ellipse : public Region { Relationship relate(ConvexPolygon const &) const override; Relationship relate(Ellipse const &) const override; - std::vector encode() const override; + std::vector encode() const override; ///@{ /// `decode` deserializes an Ellipse from a byte string produced by encode. - static std::unique_ptr decode(std::vector const & s) { + static std::unique_ptr decode(std::vector const & s) { return decode(s.data(), s.size()); } - static std::unique_ptr decode(uint8_t const * buffer, size_t n); + static std::unique_ptr decode(std::uint8_t const * buffer, size_t n); ///@} private: diff --git a/include/lsst/sphgeom/HtmPixelization.h b/include/lsst/sphgeom/HtmPixelization.h index d12f504..9f44b4d 100644 --- a/include/lsst/sphgeom/HtmPixelization.h +++ b/include/lsst/sphgeom/HtmPixelization.h @@ -62,12 +62,12 @@ class HtmPixelization : public Pixelization { /// `level` returns the subdivision level of the given HTM index. /// /// If i is not a valid HTM index, -1 is returned. - static int level(uint64_t i); + static int level(std::uint64_t i); /// `triangle` returns the triangle corresponding to the given HTM index. /// /// If i is not a valid HTM index, a std::invalid_argument is thrown. - static ConvexPolygon triangle(uint64_t i); + static ConvexPolygon triangle(std::uint64_t i); /// `asString` converts the given HTM index to a human readable string. /// @@ -80,7 +80,7 @@ class HtmPixelization : public Pixelization { /// of the HTM triangle-tree. /// /// If i is not a valid HTM index, a std::invalid_argument is thrown. - static std::string asString(uint64_t i); + static std::string asString(std::uint64_t i); /// This constructor creates an HTM pixelization of the sphere with /// the given subdivision level. If `level` ∉ [0, MAX_LEVEL], @@ -91,17 +91,17 @@ class HtmPixelization : public Pixelization { int getLevel() const { return _level; } RangeSet universe() const override { - return RangeSet(static_cast(8) << 2 * _level, - static_cast(16) << 2 * _level); + return RangeSet(static_cast(8) << 2 * _level, + static_cast(16) << 2 * _level); } - std::unique_ptr pixel(uint64_t i) const override { + std::unique_ptr pixel(std::uint64_t i) const override { return std::unique_ptr(new ConvexPolygon(triangle(i))); } - uint64_t index(UnitVector3d const &) const override; + std::uint64_t index(UnitVector3d const &) const override; - std::string toString(uint64_t i) const override { return asString(i); } + std::string toString(std::uint64_t i) const override { return asString(i); } private: int _level; diff --git a/include/lsst/sphgeom/Mq3cPixelization.h b/include/lsst/sphgeom/Mq3cPixelization.h index c3cab56..8c4c208 100644 --- a/include/lsst/sphgeom/Mq3cPixelization.h +++ b/include/lsst/sphgeom/Mq3cPixelization.h @@ -62,14 +62,14 @@ class Mq3cPixelization : public Pixelization { /// `level` returns the subdivision level of the given modified Q3C index. /// /// If i is not a valid modified Q3C index, -1 is returned. - static int level(uint64_t i); + static int level(std::uint64_t i); /// `quad` returns the quadrilateral corresponding to the modified Q3C /// pixel with index `i`. /// /// If `i` is not a valid modified Q3C index, a std::invalid_argument /// is thrown. - static ConvexPolygon quad(uint64_t i); + static ConvexPolygon quad(std::uint64_t i); /// `neighborhood` returns the indexes of all pixels that share a vertex /// with pixel `i` (including `i` itself). A Q3C pixel has 8 - k adjacent @@ -78,7 +78,7 @@ class Mq3cPixelization : public Pixelization { /// /// If `i` is not a valid modified Q3C index, a std::invalid_argument /// is thrown. - static std::vector neighborhood(uint64_t i); + static std::vector neighborhood(std::uint64_t i); /// `toString` converts the given modified-Q3C index to a human readable /// string. @@ -92,7 +92,7 @@ class Mq3cPixelization : public Pixelization { /// /// If i is not a valid modified-Q3C index, a std::invalid_argument is /// thrown. - static std::string asString(uint64_t i); + static std::string asString(std::uint64_t i); /// This constructor creates a modified Q3C pixelization of the sphere /// with the given subdivision level. If `level` ∉ [0, MAX_LEVEL], @@ -103,15 +103,15 @@ class Mq3cPixelization : public Pixelization { int getLevel() const { return _level; } RangeSet universe() const override { - return RangeSet(static_cast(10) << 2 * _level, - static_cast(16) << 2 * _level); + return RangeSet(static_cast(10) << 2 * _level, + static_cast(16) << 2 * _level); } - std::unique_ptr pixel(uint64_t i) const override; + std::unique_ptr pixel(std::uint64_t i) const override; - uint64_t index(UnitVector3d const & v) const override; + std::uint64_t index(UnitVector3d const & v) const override; - std::string toString(uint64_t i) const override { return asString(i); } + std::string toString(std::uint64_t i) const override { return asString(i); } private: int _level; diff --git a/include/lsst/sphgeom/Pixelization.h b/include/lsst/sphgeom/Pixelization.h index 2d8705b..a24c008 100644 --- a/include/lsst/sphgeom/Pixelization.h +++ b/include/lsst/sphgeom/Pixelization.h @@ -98,13 +98,13 @@ class Pixelization { /// assigned to exactly one pixel by the pixelization. /// /// If i is not a valid pixel index, a std::invalid_argument is thrown. - virtual std::unique_ptr pixel(uint64_t i) const = 0; + virtual std::unique_ptr pixel(std::uint64_t i) const = 0; /// `index` computes the index of the pixel for v. - virtual uint64_t index(UnitVector3d const & v) const = 0; + virtual std::uint64_t index(UnitVector3d const & v) const = 0; /// `toString` converts the given pixel index to a human-readable string. - virtual std::string toString(uint64_t i) const = 0; + virtual std::string toString(std::uint64_t i) const = 0; /// `envelope` returns the indexes of the pixels intersecting the /// spherical region r. diff --git a/include/lsst/sphgeom/Q3cPixelization.h b/include/lsst/sphgeom/Q3cPixelization.h index b442f18..6cb8a32 100644 --- a/include/lsst/sphgeom/Q3cPixelization.h +++ b/include/lsst/sphgeom/Q3cPixelization.h @@ -71,7 +71,7 @@ class Q3cPixelization : public Pixelization { /// index `i`. /// /// If `i` is not a valid Q3C index, a std::invalid_argument is thrown. - ConvexPolygon quad(uint64_t i) const; + ConvexPolygon quad(std::uint64_t i) const; /// `neighborhood` returns the indexes of all pixels that share a vertex /// with pixel `i` (including `i` itself). A Q3C pixel has 8 - k adjacent @@ -79,15 +79,15 @@ class Q3cPixelization : public Pixelization { /// vertices (0, 1, or 4). /// /// If `i` is not a valid Q3C index, a std::invalid_argument is thrown. - std::vector neighborhood(uint64_t i) const; + std::vector neighborhood(std::uint64_t i) const; RangeSet universe() const override { - return RangeSet(0, static_cast(6) << 2 * _level); + return RangeSet(0, static_cast(6) << 2 * _level); } - std::unique_ptr pixel(uint64_t i) const override; + std::unique_ptr pixel(std::uint64_t i) const override; - uint64_t index(UnitVector3d const & v) const override; + std::uint64_t index(UnitVector3d const & v) const override; /// `toString` converts the given Q3C index to a human readable string. /// @@ -99,7 +99,7 @@ class Q3cPixelization : public Pixelization { /// on F. /// /// If i is not a valid Q3C index, a std::invalid_argument is thrown. - std::string toString(uint64_t i) const override; + std::string toString(std::uint64_t i) const override; private: int _level; diff --git a/include/lsst/sphgeom/RangeSet.h b/include/lsst/sphgeom/RangeSet.h index f001e74..e0e7ac4 100644 --- a/include/lsst/sphgeom/RangeSet.h +++ b/include/lsst/sphgeom/RangeSet.h @@ -63,7 +63,7 @@ namespace sphgeom { /// > http://www.aanda.org/articles/aa/abs/2015/08/aa26549-15/aa26549-15.html /// /// The beginning and end points of the disjoint, non-empty, half-open integer -/// ranges in the set are stored in a std::vector, with monotonically +/// ranges in the set are stored in a std::vector, with monotonically /// increasing values, except for the last one. Each pair of consecutive /// elements [begin, end) in the vector is a non-empty half-open range, where /// the value of end is defined as the integer obtained by adding one to the @@ -72,7 +72,7 @@ namespace sphgeom { /// Mathematically, a half-open range with largest element equal to 2^64 - 1 /// would have an end point of 2^64. But arithmetic for unsigned 64 bit /// integers is modular, and adding 1 to 2^64 - 1 "wraps around" to 0. So in -/// practice, ranges containing the largest uint64_t value have an end point +/// practice, ranges containing the largest std::uint64_t value have an end point /// of 0. Note that overflow is undefined for signed integers, which motivates /// the use of unsigned 64 bit integers for this class. /// @@ -98,8 +98,8 @@ namespace sphgeom { /// input, either directly or in the form of a tuple. The values in a range /// are generated by starting with a value equal to first, and incrementing /// it until last is reached. If first == last, the range is full (it contains -/// all possible uint64_t values), and if first > last, it wraps around - -/// that is, it contains all uint64_t values except for [last, first). +/// all possible std::uint64_t values), and if first > last, it wraps around - +/// that is, it contains all std::uint64_t values except for [last, first). /// /// The ranges in a set can be iterated over. Set modification may /// invalidate all iterators. @@ -129,13 +129,13 @@ class RangeSet { struct Iterator { // For std::iterator_traits using difference_type = ptrdiff_t; - using value_type = std::tuple; + using value_type = std::tuple; using pointer = void; - using reference = std::tuple; + using reference = std::tuple; using iterator_category = std::input_iterator_tag; Iterator() = default; - explicit Iterator(uint64_t const * ptr) : p{ptr} {} + explicit Iterator(std::uint64_t const * ptr) : p{ptr} {} friend void swap(Iterator & a, Iterator & b) { std::swap(a.p, b.p); @@ -168,20 +168,20 @@ class RangeSet { bool operator<=(Iterator const & i) const { return p <= i.p; } bool operator>=(Iterator const & i) const { return p >= i.p; } - std::tuple operator*() { + std::tuple operator*() { return std::make_tuple(p[0], p[1]); } - std::tuple operator[](ptrdiff_t n) const { + std::tuple operator[](ptrdiff_t n) const { return std::make_tuple(p[2 * n], p[2 * n + 1]); } - uint64_t const * p = nullptr; + std::uint64_t const * p = nullptr; }; using difference_type = ptrdiff_t; using size_type = size_t; - using value_type = std::tuple; + using value_type = std::tuple; using const_iterator = Iterator; RangeSet(RangeSet const &) = default; @@ -195,26 +195,26 @@ class RangeSet { ///@{ /// This constructor creates a set containing the given integer(s) /// or integer range(s). - explicit RangeSet(uint64_t u) { + explicit RangeSet(std::uint64_t u) { insert(u); } - RangeSet(uint64_t first, uint64_t last) { + RangeSet(std::uint64_t first, std::uint64_t last) { insert(first, last); } template < typename U, typename = typename std::enable_if< - std::is_convertible::value + std::is_convertible::value >::type > explicit RangeSet(std::tuple const & range) { - insert(static_cast(std::get<0>(range)), - static_cast(std::get<1>(range))); + insert(static_cast(std::get<0>(range)), + static_cast(std::get<1>(range))); } - RangeSet(std::initializer_list); + RangeSet(std::initializer_list); // Note: the standard library for GCC unfortunately declares explicit conversion // constructors for tuples - the use of std::pair is required for code like: @@ -222,7 +222,7 @@ class RangeSet { // RangeSet s = {{0, 1}, {2, 3}}; // // to compile. - RangeSet(std::initializer_list>); + RangeSet(std::initializer_list>); ///@} /// This generic constructor creates a set containing the integers or @@ -289,42 +289,42 @@ class RangeSet { /// the given integers extend or follow the last (largest) range in this /// set. Otherwise, the worst case run time is O(N), where N is the number /// of ranges in the set. - void insert(uint64_t u) { + void insert(std::uint64_t u) { insert(u, u + 1); } template < typename U, typename = typename std::enable_if< - std::is_convertible::value + std::is_convertible::value >::type > void insert(std::tuple const & range) { insert(std::get<0>(range), std::get<1>(range)); } - void insert(uint64_t first, uint64_t last); + void insert(std::uint64_t first, std::uint64_t last); ///@} ///@{ /// `erase` removes the given integers from this set. /// /// The strong exception safety guarantee is provided. - void erase(uint64_t u) { + void erase(std::uint64_t u) { erase(u, u + 1); } template < typename U, typename = typename std::enable_if< - std::is_convertible::value + std::is_convertible::value >::type > void erase(std::tuple const & range) { erase(std::get<0>(range), std::get<1>(range)); } - void erase(uint64_t first, uint64_t last); + void erase(std::uint64_t first, std::uint64_t last); ///@} /// \name Set operations @@ -429,9 +429,9 @@ class RangeSet { ///@{ /// `intersects` returns true iff the intersection of this set /// and the given integers is non-empty. - bool intersects(uint64_t u) const { return intersects(u, u + 1); } + bool intersects(std::uint64_t u) const { return intersects(u, u + 1); } - bool intersects(uint64_t first, uint64_t last) const; + bool intersects(std::uint64_t first, std::uint64_t last) const; bool intersects(RangeSet const & s) const; ///@} @@ -439,9 +439,9 @@ class RangeSet { ///@{ /// `contains` returns true iff every one of the given integers is in /// this set. - bool contains(uint64_t u) const { return contains(u, u + 1); } + bool contains(std::uint64_t u) const { return contains(u, u + 1); } - bool contains(uint64_t first, uint64_t last) const; + bool contains(std::uint64_t first, std::uint64_t last) const; bool contains(RangeSet const & s) const; ///@} @@ -449,9 +449,9 @@ class RangeSet { ///@{ /// `isWithin` returns true iff every integer in this set is also one of /// the given integers. - bool isWithin(uint64_t u) const { return isWithin(u, u + 1); } + bool isWithin(std::uint64_t u) const { return isWithin(u, u + 1); } - bool isWithin(uint64_t first, uint64_t last) const; + bool isWithin(std::uint64_t first, std::uint64_t last) const; bool isWithin(RangeSet const & s) const { return s.contains(*this); } ///@} @@ -459,9 +459,9 @@ class RangeSet { ///@{ /// `isDisjointFrom` returns true iff the intersection of this set /// and the given integers is empty. - bool isDisjointFrom(uint64_t u) const { return !intersects(u); } + bool isDisjointFrom(std::uint64_t u) const { return !intersects(u); } - bool isDisjointFrom(uint64_t first, uint64_t last) const { + bool isDisjointFrom(std::uint64_t first, std::uint64_t last) const { return !intersects(first, last); } @@ -480,10 +480,10 @@ class RangeSet { /// of the sphere that overlap a region R, then this operation can be /// thought of as computing a lower resolution representation of the /// coverage of R. - RangeSet & simplify(uint32_t n); + RangeSet & simplify(std::uint32_t n); /// `simplified` returns a simplified copy of this set. - RangeSet simplified(uint32_t n) const { + RangeSet simplified(std::uint32_t n) const { RangeSet rs(*this); rs.simplify(n); return rs; @@ -495,10 +495,10 @@ class RangeSet { /// Given ranges that correspond to pixel indexes in a hierarchical /// pixelization of the sphere like HTM or Q3C, scaling by 4 corresponds /// to increasing the subdivision level of the pixelization by 1. - RangeSet & scale(uint64_t i); + RangeSet & scale(std::uint64_t i); /// `scaled` returns a scaled copy of this set. - RangeSet scaled(uint64_t i) const { + RangeSet scaled(std::uint64_t i) const { RangeSet rs(*this); rs.scale(i); return rs; @@ -549,7 +549,7 @@ class RangeSet { /// /// Note that 0 is returned both for full and empty sets (a full set /// contains 2^64 integers, which is 0 modulo 2^64). - uint64_t cardinality() const; + std::uint64_t cardinality() const; void swap(RangeSet & s) { using std::swap; @@ -565,50 +565,50 @@ class RangeSet { bool isValid() const; private: - std::vector _ranges = {0, 0}; + std::vector _ranges = {0, 0}; // The offset of the first range in _ranges. It is 0 (false) if the // first integer in the set is 0, and 1 (true) otherwise. bool _offset = true; // `_begin` returns a pointer to the first range in this set. - uint64_t const * _begin() const { return _ranges.data() + _offset; } + std::uint64_t const * _begin() const { return _ranges.data() + _offset; } // `_end` returns a pointer to the range after the last one in this set. - uint64_t const * _end() const { + std::uint64_t const * _end() const { size_t s = _ranges.size(); return _ranges.data() + (s - ((s & 1) ^ _offset)); } // `_beginc` returns a pointer to the first range in // the complement of this set. - uint64_t const * _beginc() const { return _ranges.data() + !_offset; } + std::uint64_t const * _beginc() const { return _ranges.data() + !_offset; } // `_endc` returns a pointer to the range after the last one in // the complement of this set. - uint64_t const * _endc() const { + std::uint64_t const * _endc() const { size_t s = _ranges.size(); return _ranges.data() + (s - ((s & 1) ^ !_offset)); } - void _insert(uint64_t first, uint64_t last); + void _insert(std::uint64_t first, std::uint64_t last); - static void _intersectOne(std::vector &, - uint64_t const *, - uint64_t const *, uint64_t const *); + static void _intersectOne(std::vector &, + std::uint64_t const *, + std::uint64_t const *, std::uint64_t const *); - static void _intersect(std::vector &, - uint64_t const *, uint64_t const *, - uint64_t const *, uint64_t const *); + static void _intersect(std::vector &, + std::uint64_t const *, std::uint64_t const *, + std::uint64_t const *, std::uint64_t const *); - void _intersect(uint64_t const *, uint64_t const *, - uint64_t const *, uint64_t const *); + void _intersect(std::uint64_t const *, std::uint64_t const *, + std::uint64_t const *, std::uint64_t const *); - static bool _intersectsOne(uint64_t const *, - uint64_t const *, uint64_t const *); + static bool _intersectsOne(std::uint64_t const *, + std::uint64_t const *, std::uint64_t const *); - static bool _intersects(uint64_t const *, uint64_t const *, - uint64_t const *, uint64_t const *); + static bool _intersects(std::uint64_t const *, std::uint64_t const *, + std::uint64_t const *, std::uint64_t const *); }; diff --git a/include/lsst/sphgeom/Region.h b/include/lsst/sphgeom/Region.h index ea29451..d58725e 100644 --- a/include/lsst/sphgeom/Region.h +++ b/include/lsst/sphgeom/Region.h @@ -35,6 +35,7 @@ #include #include +#include #include "Relationship.h" @@ -137,15 +138,15 @@ class Region { /// `encode` serializes this region into an opaque byte string. Byte strings /// emitted by encode can be deserialized with decode. - virtual std::vector encode() const = 0; + virtual std::vector encode() const = 0; ///@{ /// `decode` deserializes a Region from a byte string produced by encode. - static std::unique_ptr decode(std::vector const & s) { + static std::unique_ptr decode(std::vector const & s) { return decode(s.data(), s.size()); } - static std::unique_ptr decode(uint8_t const * buffer, size_t n); + static std::unique_ptr decode(std::uint8_t const * buffer, size_t n); ///@} }; diff --git a/include/lsst/sphgeom/codec.h b/include/lsst/sphgeom/codec.h index 659f640..0bacd0d 100644 --- a/include/lsst/sphgeom/codec.h +++ b/include/lsst/sphgeom/codec.h @@ -53,77 +53,77 @@ namespace sphgeom { /// `encodeDouble` appends an IEEE double in little-endian byte order /// to the end of buffer. -inline void encodeDouble(double item, std::vector & buffer) { +inline void encodeDouble(double item, std::vector & buffer) { #ifdef OPTIMIZED_LITTLE_ENDIAN - auto ptr = reinterpret_cast(&item); + auto ptr = reinterpret_cast(&item); buffer.insert(buffer.end(), ptr, ptr + 8); #else - union { uint64_t u; double d; }; + union { std::uint64_t u; double d; }; d = item; - buffer.push_back(static_cast(u)); - buffer.push_back(static_cast(u >> 8)); - buffer.push_back(static_cast(u >> 16)); - buffer.push_back(static_cast(u >> 24)); - buffer.push_back(static_cast(u >> 32)); - buffer.push_back(static_cast(u >> 40)); - buffer.push_back(static_cast(u >> 48)); - buffer.push_back(static_cast(u >> 56)); + buffer.push_back(static_cast(u)); + buffer.push_back(static_cast(u >> 8)); + buffer.push_back(static_cast(u >> 16)); + buffer.push_back(static_cast(u >> 24)); + buffer.push_back(static_cast(u >> 32)); + buffer.push_back(static_cast(u >> 40)); + buffer.push_back(static_cast(u >> 48)); + buffer.push_back(static_cast(u >> 56)); #endif } /// `decodeDouble` extracts an IEEE double from the 8 byte little-endian byte /// sequence in buffer. -inline double decodeDouble(uint8_t const * buffer) { +inline double decodeDouble(std::uint8_t const * buffer) { #ifdef OPTIMIZED_LITTLE_ENDIAN return *reinterpret_cast(buffer); #else - union { uint64_t u; double d; }; - u = static_cast(buffer[0]) + - (static_cast(buffer[1]) << 8) + - (static_cast(buffer[2]) << 16) + - (static_cast(buffer[3]) << 24) + - (static_cast(buffer[4]) << 32) + - (static_cast(buffer[5]) << 40) + - (static_cast(buffer[6]) << 48) + - (static_cast(buffer[7]) << 56); + union { std::uint64_t u; double d; }; + u = static_cast(buffer[0]) + + (static_cast(buffer[1]) << 8) + + (static_cast(buffer[2]) << 16) + + (static_cast(buffer[3]) << 24) + + (static_cast(buffer[4]) << 32) + + (static_cast(buffer[5]) << 40) + + (static_cast(buffer[6]) << 48) + + (static_cast(buffer[7]) << 56); return d; #endif } /// `encodeU64` appends an uint64 in little-endian byte order /// to the end of buffer. -inline void encodeU64(std::uint64_t item, std::vector & buffer) { +inline void encodeU64(std::uint64_t item, std::vector & buffer) { #ifdef OPTIMIZED_LITTLE_ENDIAN - auto ptr = reinterpret_cast(&item); + auto ptr = reinterpret_cast(&item); buffer.insert(buffer.end(), ptr, ptr + 8); #else - union { uint64_t u; double d; }; + union { std::uint64_t u; double d; }; d = item; - buffer.push_back(static_cast(u)); - buffer.push_back(static_cast(u >> 8)); - buffer.push_back(static_cast(u >> 16)); - buffer.push_back(static_cast(u >> 24)); - buffer.push_back(static_cast(u >> 32)); - buffer.push_back(static_cast(u >> 40)); - buffer.push_back(static_cast(u >> 48)); - buffer.push_back(static_cast(u >> 56)); + buffer.push_back(static_cast(u)); + buffer.push_back(static_cast(u >> 8)); + buffer.push_back(static_cast(u >> 16)); + buffer.push_back(static_cast(u >> 24)); + buffer.push_back(static_cast(u >> 32)); + buffer.push_back(static_cast(u >> 40)); + buffer.push_back(static_cast(u >> 48)); + buffer.push_back(static_cast(u >> 56)); #endif } /// `decodeU64` extracts an uint64 from the 8 byte little-endian byte /// sequence in buffer. -inline std::uint64_t decodeU64(uint8_t const * buffer) { +inline std::uint64_t decodeU64(std::uint8_t const * buffer) { #ifdef OPTIMIZED_LITTLE_ENDIAN - return *reinterpret_cast(buffer); + return *reinterpret_cast(buffer); #else - std::uint64_t u = static_cast(buffer[0]) + - (static_cast(buffer[1]) << 8) + - (static_cast(buffer[2]) << 16) + - (static_cast(buffer[3]) << 24) + - (static_cast(buffer[4]) << 32) + - (static_cast(buffer[5]) << 40) + - (static_cast(buffer[6]) << 48) + - (static_cast(buffer[7]) << 56); + std::uint64_t u = static_cast(buffer[0]) + + (static_cast(buffer[1]) << 8) + + (static_cast(buffer[2]) << 16) + + (static_cast(buffer[3]) << 24) + + (static_cast(buffer[4]) << 32) + + (static_cast(buffer[5]) << 40) + + (static_cast(buffer[6]) << 48) + + (static_cast(buffer[7]) << 56); return u; #endif } diff --git a/include/lsst/sphgeom/curve.h b/include/lsst/sphgeom/curve.h index 905db4e..9df7499 100644 --- a/include/lsst/sphgeom/curve.h +++ b/include/lsst/sphgeom/curve.h @@ -52,10 +52,10 @@ /// a single 64 bit integer constant (0x8d3ec79a6b5021f4). The implementation /// then looks like: /// -/// inline uint64_t hilbertIndex(uint32_t x, uint32_t y, uint32_t m) { -/// uint64_t const z = mortonIndex(x, y); -/// uint64_t h = 0; -/// uint64_t i = 0; +/// inline std::uint64_t hilbertIndex(std::uint32_t x, std::uint32_t y, std::uint32_t m) { +/// std::uint64_t const z = mortonIndex(x, y); +/// std::uint64_t h = 0; +/// std::uint64_t i = 0; /// for (m = 2 * m; m != 0;) { /// m -= 2; /// i = (i & 0xc) | ((z >> m) & 3); @@ -102,14 +102,14 @@ namespace sphgeom { /// > Using de Bruijn Sequences to Index a 1 in a Computer Word /// > C. E. Leiserson, H. Prokop, and K. H. Randall. /// > http://supertech.csail.mit.edu/papers/debruijn.pdf -inline uint8_t log2(uint64_t x) { - alignas(64) static uint8_t const PERFECT_HASH_TABLE[64] = { +inline std::uint8_t log2(std::uint64_t x) { + alignas(64) static std::uint8_t const PERFECT_HASH_TABLE[64] = { 0, 1, 2, 7, 3, 13, 8, 19, 4, 25, 14, 28, 9, 34, 20, 40, 5, 17, 26, 38, 15, 46, 29, 48, 10, 31, 35, 54, 21, 50, 41, 57, 63, 6, 12, 18, 24, 27, 33, 39, 16, 37, 45, 47, 30, 53, 49, 56, 62, 11, 23, 32, 36, 44, 52, 55, 61, 22, 43, 51, 60, 42, 59, 58 }; - uint64_t const DE_BRUIJN_SEQUENCE = UINT64_C(0x0218a392cd3d5dbf); + std::uint64_t const DE_BRUIJN_SEQUENCE = UINT64_C(0x0218a392cd3d5dbf); // First ensure that all bits below the MSB are set. x |= (x >> 1); x |= (x >> 2); @@ -129,13 +129,13 @@ inline uint8_t log2(uint64_t x) { return PERFECT_HASH_TABLE[(DE_BRUIJN_SEQUENCE * x) >> 58]; } -inline uint8_t log2(uint32_t x) { +inline std::uint8_t log2(std::uint32_t x) { // See https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn - alignas(32) static uint8_t const PERFECT_HASH_TABLE[32] = { + alignas(32) static std::uint8_t const PERFECT_HASH_TABLE[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 }; - uint32_t const DE_BRUIJN_SEQUENCE = UINT32_C(0x07c4acdd); + std::uint32_t const DE_BRUIJN_SEQUENCE = UINT32_C(0x07c4acdd); x |= (x >> 1); x |= (x >> 2); x |= (x >> 4); @@ -152,11 +152,11 @@ inline uint8_t log2(uint32_t x) { /// order function. See https://en.wikipedia.org/wiki/Z-order_curve /// for more information. #if defined(NO_SIMD) || !defined(__x86_64__) - inline uint64_t mortonIndex(uint32_t x, uint32_t y) { + inline std::uint64_t mortonIndex(std::uint32_t x, std::uint32_t y) { // This is just a 64-bit extension of: // http://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN - uint64_t b = y; - uint64_t a = x; + std::uint64_t b = y; + std::uint64_t a = x; b = (b | (b << 16)) & UINT64_C(0x0000ffff0000ffff); a = (a | (a << 16)) & UINT64_C(0x0000ffff0000ffff); b = (b | (b << 8)) & UINT64_C(0x00ff00ff00ff00ff); @@ -170,7 +170,7 @@ inline uint8_t log2(uint32_t x) { return a | (b << 1); } #else - inline uint64_t mortonIndex(__m128i xy) { + inline std::uint64_t mortonIndex(__m128i xy) { xy = _mm_and_si128(_mm_or_si128(xy, _mm_slli_epi64(xy, 16)), _mm_set1_epi32(0x0000ffff)); xy = _mm_and_si128(_mm_or_si128(xy, _mm_slli_epi64(xy, 8)), @@ -183,12 +183,12 @@ inline uint8_t log2(uint32_t x) { _mm_set1_epi32(0x55555555)); __m128i y = _mm_unpackhi_epi64(xy, _mm_setzero_si128()); __m128i r = _mm_or_si128(xy, _mm_slli_epi64(y, 1)); - return static_cast(_mm_cvtsi128_si64(r)); + return static_cast(_mm_cvtsi128_si64(r)); } - inline uint64_t mortonIndex(uint32_t x, uint32_t y) { - __m128i xy = _mm_set_epi64x(static_cast(y), - static_cast(x)); + inline std::uint64_t mortonIndex(std::uint32_t x, std::uint32_t y) { + __m128i xy = _mm_set_epi64x(static_cast(y), + static_cast(x)); return mortonIndex(xy); } #endif @@ -199,9 +199,9 @@ inline uint8_t log2(uint32_t x) { /// tuple, and the 32 odd bits in the second. This is the inverse of /// mortonIndex(). #if defined(NO_SIMD) || !defined(__x86_64__) - inline std::tuple mortonIndexInverse(uint64_t z) { - uint64_t x = z & UINT64_C(0x5555555555555555); - uint64_t y = (z >> 1) & UINT64_C(0x5555555555555555); + inline std::tuple mortonIndexInverse(std::uint64_t z) { + std::uint64_t x = z & UINT64_C(0x5555555555555555); + std::uint64_t y = (z >> 1) & UINT64_C(0x5555555555555555); x = (x | (x >> 1)) & UINT64_C(0x3333333333333333); y = (y | (y >> 1)) & UINT64_C(0x3333333333333333); x = (x | (x >> 2)) & UINT64_C(0x0f0f0f0f0f0f0f0f); @@ -210,13 +210,13 @@ inline uint8_t log2(uint32_t x) { y = (y | (y >> 4)) & UINT64_C(0x00ff00ff00ff00ff); x = (x | (x >> 8)) & UINT64_C(0x0000ffff0000ffff); y = (y | (y >> 8)) & UINT64_C(0x0000ffff0000ffff); - return std::make_tuple(static_cast(x | (x >> 16)), - static_cast(y | (y >> 16))); + return std::make_tuple(static_cast(x | (x >> 16)), + static_cast(y | (y >> 16))); } #else - inline __m128i mortonIndexInverseSimd(uint64_t z) { - __m128i xy = _mm_set_epi64x(static_cast(z >> 1), - static_cast(z)); + inline __m128i mortonIndexInverseSimd(std::uint64_t z) { + __m128i xy = _mm_set_epi64x(static_cast(z >> 1), + static_cast(z)); xy = _mm_and_si128(xy, _mm_set1_epi32(0x55555555)); xy = _mm_and_si128(_mm_or_si128(xy, _mm_srli_epi64(xy, 1)), _mm_set1_epi32(0x33333333)); @@ -230,18 +230,18 @@ inline uint8_t log2(uint32_t x) { return xy; } - inline std::tuple mortonIndexInverse(uint64_t z) { + inline std::tuple mortonIndexInverse(std::uint64_t z) { __m128i xy = mortonIndexInverseSimd(z); - uint64_t r = _mm_cvtsi128_si64(_mm_shuffle_epi32(xy, 8)); - return std::make_tuple(static_cast(r & 0xffffffff), - static_cast(r >> 32)); + std::uint64_t r = _mm_cvtsi128_si64(_mm_shuffle_epi32(xy, 8)); + return std::make_tuple(static_cast(r & 0xffffffff), + static_cast(r >> 32)); } #endif /// `mortonToHilbert` converts the 2m-bit Morton index z to the /// corresponding Hilbert index. -inline uint64_t mortonToHilbert(uint64_t z, int m) { - alignas(64) static uint8_t const HILBERT_LUT_3[256] = { +inline std::uint64_t mortonToHilbert(std::uint64_t z, int m) { + alignas(64) static std::uint8_t const HILBERT_LUT_3[256] = { 0x40, 0xc3, 0x01, 0x02, 0x04, 0x45, 0x87, 0x46, 0x8e, 0x8d, 0x4f, 0xcc, 0x08, 0x49, 0x8b, 0x4a, 0xfa, 0x3b, 0xf9, 0xb8, 0x7c, 0xff, 0x3d, 0x3e, @@ -275,18 +275,18 @@ inline uint64_t mortonToHilbert(uint64_t z, int m) { 0x8a, 0x89, 0x4b, 0xc8, 0x86, 0x85, 0x47, 0xc4, 0x0c, 0x4d, 0x8f, 0x4e, 0xc2, 0x03, 0xc1, 0x80 }; - uint64_t h = 0; - uint64_t i = 0; + std::uint64_t h = 0; + std::uint64_t i = 0; for (m = 2 * m; m >= 6;) { m -= 6; - uint8_t j = HILBERT_LUT_3[i | ((z >> m) & 0x3f)]; + std::uint8_t j = HILBERT_LUT_3[i | ((z >> m) & 0x3f)]; h = (h << 6) | (j & 0x3f); i = j & 0xc0; } if (m != 0) { // m = 2 or 4 int r = 6 - m; - uint8_t j = HILBERT_LUT_3[i | ((z << r) & 0x3f)]; + std::uint8_t j = HILBERT_LUT_3[i | ((z << r) & 0x3f)]; h = (h << m) | ((j & 0x3f) >> r); } return h; @@ -294,8 +294,8 @@ inline uint64_t mortonToHilbert(uint64_t z, int m) { /// `hilbertToMorton` converts the 2m-bit Hilbert index h to the /// corresponding Morton index. -inline uint64_t hilbertToMorton(uint64_t h, int m) { - alignas(64) static uint8_t const HILBERT_INVERSE_LUT_3[256] = { +inline std::uint64_t hilbertToMorton(std::uint64_t h, int m) { + alignas(64) static std::uint8_t const HILBERT_INVERSE_LUT_3[256] = { 0x40, 0x02, 0x03, 0xc1, 0x04, 0x45, 0x47, 0x86, 0x0c, 0x4d, 0x4f, 0x8e, 0xcb, 0x89, 0x88, 0x4a, 0x20, 0x61, 0x63, 0xa2, 0x68, 0x2a, 0x2b, 0xe9, @@ -329,18 +329,18 @@ inline uint64_t hilbertToMorton(uint64_t h, int m) { 0x10, 0x51, 0x53, 0x92, 0x58, 0x1a, 0x1b, 0xd9, 0x5c, 0x1e, 0x1f, 0xdd, 0x97, 0xd6, 0xd4, 0x15 }; - uint64_t z = 0; - uint64_t i = 0; + std::uint64_t z = 0; + std::uint64_t i = 0; for (m = 2 * m; m >= 6;) { m -= 6; - uint8_t j = HILBERT_INVERSE_LUT_3[i | ((h >> m) & 0x3f)]; + std::uint8_t j = HILBERT_INVERSE_LUT_3[i | ((h >> m) & 0x3f)]; z = (z << 6) | (j & 0x3f); i = j & 0xc0; } if (m != 0) { // m = 2 or 4 int r = 6 - m; - uint8_t j = HILBERT_INVERSE_LUT_3[i | ((h << r) & 0x3f)]; + std::uint8_t j = HILBERT_INVERSE_LUT_3[i | ((h << r) & 0x3f)]; z = (z << m) | ((j & 0x3f) >> r); } return z; @@ -353,24 +353,24 @@ inline uint64_t hilbertToMorton(uint64_t h, int m) { /// times as long as computing its Morton index on an Intel Core i7-3820QM /// CPU. With Xcode 7.3 and -O3, latency is ~19ns per call at a CPU /// frequency of 3.5 GHz. -inline uint64_t hilbertIndex(uint32_t x, uint32_t y, int m) { +inline std::uint64_t hilbertIndex(std::uint32_t x, std::uint32_t y, int m) { return mortonToHilbert(mortonIndex(x, y), m); } #if !defined(NO_SIMD) && defined(__x86_64__) - inline uint64_t hilbertIndex(__m128i xy, int m) { + inline std::uint64_t hilbertIndex(__m128i xy, int m) { return mortonToHilbert(mortonIndex(xy), m); } #endif /// `hilbertIndexInverse` returns the point (x, y) with Hilbert index h, /// where x and y are m bit integers. -inline std::tuple hilbertIndexInverse(uint64_t h, int m) { +inline std::tuple hilbertIndexInverse(std::uint64_t h, int m) { return mortonIndexInverse(hilbertToMorton(h, m)); } #if !defined(NO_SIMD) && defined(__x86_64__) - inline __m128i hilbertIndexInverseSimd(uint64_t h, int m) { + inline __m128i hilbertIndexInverseSimd(std::uint64_t h, int m) { return mortonIndexInverseSimd(hilbertToMorton(h, m)); } #endif diff --git a/include/lsst/sphgeom/python/utils.h b/include/lsst/sphgeom/python/utils.h index a2b9fe2..0b77080 100644 --- a/include/lsst/sphgeom/python/utils.h +++ b/include/lsst/sphgeom/python/utils.h @@ -58,7 +58,7 @@ inline ptrdiff_t convertIndex(ptrdiff_t len, pybind11::int_ i) { /// Encode a Region as a pybind11 bytes object inline pybind11::bytes encode(Region const &self) { - std::vector bytes = self.encode(); + std::vector bytes = self.encode(); return pybind11::bytes(reinterpret_cast(bytes.data()), bytes.size()); } @@ -66,7 +66,7 @@ inline pybind11::bytes encode(Region const &self) { /// Decode a Region from a pybind11 bytes object. template std::unique_ptr decode(pybind11::bytes bytes) { - uint8_t const *buffer = reinterpret_cast( + std::uint8_t const *buffer = reinterpret_cast( PYBIND11_BYTES_AS_STRING(bytes.ptr())); size_t n = static_cast(PYBIND11_BYTES_SIZE(bytes.ptr())); return R::decode(buffer, n); diff --git a/src/BigInteger.cc b/src/BigInteger.cc index 3a1494d..99e345c 100644 --- a/src/BigInteger.cc +++ b/src/BigInteger.cc @@ -43,29 +43,29 @@ namespace { // `_add` computes the sum of the digits in m1 and m2 and stores the result in // m, which may equal either m1 or m2. It returns the number of digits in the // sum. -unsigned _add(uint32_t * const m, - uint32_t const * const m1, - uint32_t const * const m2, +unsigned _add(std::uint32_t * const m, + std::uint32_t const * const m1, + std::uint32_t const * const m2, unsigned const size1, unsigned const size2) { - uint64_t sum = 0; + std::uint64_t sum = 0; unsigned i = 0; unsigned const size = std::min(size1, size2); for (; i < size; ++i) { - sum = static_cast(m1[i]) + (sum >> 32) + - static_cast(m2[i]); - m[i] = static_cast(sum); + sum = static_cast(m1[i]) + (sum >> 32) + + static_cast(m2[i]); + m[i] = static_cast(sum); } for (; i < size1; ++i) { - sum = static_cast(m1[i]) + (sum >> 32); - m[i] = static_cast(sum); + sum = static_cast(m1[i]) + (sum >> 32); + m[i] = static_cast(sum); } for (; i < size2; ++i) { - sum = static_cast(m2[i]) + (sum >> 32); - m[i] = static_cast(sum); + sum = static_cast(m2[i]) + (sum >> 32); + m[i] = static_cast(sum); } - uint32_t carry = static_cast(sum >> 32); + std::uint32_t carry = static_cast(sum >> 32); if (carry != 0) { m[i] = carry; ++i; @@ -76,13 +76,13 @@ unsigned _add(uint32_t * const m, // `_sub` computes the difference of the digits in m1 and m2 and stores the // result in m, which may equal either m1 or m2. It assumes that the difference // is non-negative, and returns the the number of digits in the difference. -unsigned _sub(uint32_t * const m, - uint32_t const * const m1, - uint32_t const * const m2, +unsigned _sub(std::uint32_t * const m, + std::uint32_t const * const m1, + std::uint32_t const * const m2, unsigned const size1, unsigned const size2) { - int64_t diff = 0; + std::int64_t diff = 0; unsigned i = 0; // Note that right shifting a negative integer is implementation defined // (not undefined) behavior. Here we assume arithmetic right shifts for @@ -91,14 +91,14 @@ unsigned _sub(uint32_t * const m, // TODO(smm): check for this at build time, and provide an alternate // implementation when this assumption does not hold. for (; i < size2; ++i) { - diff = static_cast(m1[i]) + (diff >> 32) - - static_cast(m2[i]); - m[i] = static_cast(diff); + diff = static_cast(m1[i]) + (diff >> 32) - + static_cast(m2[i]); + m[i] = static_cast(diff); } // Borrow from the remaining digits in m1 while necessary. for (; diff < 0; ++i) { - diff = static_cast(m1[i]) - 1; - m[i] = static_cast(diff); + diff = static_cast(m1[i]) - 1; + m[i] = static_cast(diff); } // If we subtracted anything from the most significant digit in m1, strip // any leading zeroes that may have been introduced. @@ -116,9 +116,9 @@ unsigned _sub(uint32_t * const m, // `_mul` computes the product of m1 and m2 and stores the result in m, // which may equal either m1 or m2. It assumes that m1 has at least as many // digits as m2, and returns the the number of digits in the product. -unsigned _mul(uint32_t * const m, - uint32_t const * const m1, - uint32_t const * const m2, +unsigned _mul(std::uint32_t * const m, + std::uint32_t const * const m1, + std::uint32_t const * const m2, unsigned const size1, unsigned const size2) { @@ -134,21 +134,21 @@ unsigned _mul(uint32_t * const m, m[i] = 0; } for (unsigned i = size1; i > 0; --i) { - uint64_t digit = m1[i - 1]; - uint64_t carry = static_cast(m2[0]) * digit; + std::uint64_t digit = m1[i - 1]; + std::uint64_t carry = static_cast(m2[0]) * digit; unsigned j = 1; - m[i - 1] = static_cast(carry); + m[i - 1] = static_cast(carry); carry >>= 32; for (; j < size2; ++j) { - carry = static_cast(m2[j]) * digit + - static_cast(m[i + j - 1]) + + carry = static_cast(m2[j]) * digit + + static_cast(m[i + j - 1]) + carry; - m[i + j - 1] = static_cast(carry); + m[i + j - 1] = static_cast(carry); carry >>= 32; } for (; carry != 0; ++j) { - carry += static_cast(m[i + j - 1]); - m[i + j - 1] = static_cast(carry); + carry += static_cast(m[i + j - 1]); + m[i + j - 1] = static_cast(carry); carry >>= 32; } } @@ -239,7 +239,7 @@ BigInteger & BigInteger::multiplyPow2(unsigned n) { } _size = size; } else { - uint32_t low, high = 0; + std::uint32_t low, high = 0; for (unsigned i = _size; i != 0; --i, high = low) { low = _digits[i - 1]; _digits[i + z] = (high << s) | (low >> (32 - s)); diff --git a/src/Box.cc b/src/Box.cc index 6537073..49aea7e 100644 --- a/src/Box.cc +++ b/src/Box.cc @@ -451,9 +451,9 @@ Relationship Box::relate(Ellipse const & e) const { return invert(e.relate(*this)); } -std::vector Box::encode() const { - std::vector buffer; - uint8_t tc = TYPE_CODE; +std::vector Box::encode() const { + std::vector buffer; + std::uint8_t tc = TYPE_CODE; buffer.reserve(ENCODED_SIZE); buffer.push_back(tc); encodeDouble(_lon.getA().asRadians(), buffer); @@ -463,7 +463,7 @@ std::vector Box::encode() const { return buffer; } -std::unique_ptr Box::decode(uint8_t const * buffer, size_t n) { +std::unique_ptr Box::decode(std::uint8_t const * buffer, size_t n) { if (buffer == nullptr || n != ENCODED_SIZE || *buffer != TYPE_CODE) { throw std::runtime_error("Byte-string is not an encoded Box"); } diff --git a/src/Chunker.cc b/src/Chunker.cc index 816449c..56a7b28 100644 --- a/src/Chunker.cc +++ b/src/Chunker.cc @@ -37,7 +37,7 @@ namespace sphgeom { namespace { -int32_t computeNumSegments(AngleInterval const & latitudes, Angle width) { +std::int32_t computeNumSegments(AngleInterval const & latitudes, Angle width) { // TODO(smm): Document this. if (width.asRadians() > PI) { return 1; @@ -52,7 +52,7 @@ int32_t computeNumSegments(AngleInterval const & latitudes, Angle width) { double x = cosWidth - sinLat * sinLat; double u = cosLat * cosLat; double y = std::sqrt(std::fabs(u * u - x * x)); - return static_cast( + return static_cast( std::floor(2.0 * PI / std::fabs(std::atan2(y, x)))); } @@ -61,8 +61,8 @@ constexpr double BOX_EPSILON = 5.0e-12; // ~1 micro-arcsecond } // unnamed namespace -Chunker::Chunker(int32_t numStripes, - int32_t numSubStripesPerStripe) : +Chunker::Chunker(std::int32_t numStripes, + std::int32_t numSubStripesPerStripe) : _numStripes(numStripes), _numSubStripesPerStripe(numSubStripesPerStripe), _numSubStripes(numStripes * numSubStripesPerStripe), @@ -79,22 +79,22 @@ Chunker::Chunker(int32_t numStripes, Angle const stripeHeight = Angle(PI) / _numStripes; _stripes.reserve(_numStripes); _subStripes.reserve(_numSubStripes); - for (int32_t s = 0; s < _numStripes; ++s) { + for (std::int32_t s = 0; s < _numStripes; ++s) { // Compute stripe latitude bounds. AngleInterval sLat(s * stripeHeight - Angle(0.5 * PI), (s + 1) * stripeHeight - Angle(0.5 * PI)); Stripe stripe; - int32_t const nc = computeNumSegments(sLat, stripeHeight); + std::int32_t const nc = computeNumSegments(sLat, stripeHeight); stripe.chunkWidth = Angle(2.0 * PI) / nc; stripe.numChunksPerStripe = nc; - int32_t ss = s * _numSubStripesPerStripe; - int32_t const ssEnd = ss + _numSubStripesPerStripe; + std::int32_t ss = s * _numSubStripesPerStripe; + std::int32_t const ssEnd = ss + _numSubStripesPerStripe; for (; ss < ssEnd; ++ss) { // Compute sub-stripe latitude bounds. AngleInterval ssLat(ss * _subStripeHeight - Angle(0.5 * PI), (ss + 1) * _subStripeHeight - Angle(0.5 * PI)); SubStripe subStripe; - int32_t const nsc = computeNumSegments(ssLat, _subStripeHeight) / nc; + std::int32_t const nsc = computeNumSegments(ssLat, _subStripeHeight) / nc; stripe.numSubChunksPerChunk += nsc; subStripe.numSubChunksPerChunk = nsc; if (nsc > _maxSubChunksPerSubStripeChunk) { @@ -107,42 +107,42 @@ Chunker::Chunker(int32_t numStripes, } } -std::vector Chunker::getChunksIntersecting(Region const & r) const { - std::vector chunkIds; +std::vector Chunker::getChunksIntersecting(Region const & r) const { + std::vector chunkIds; // Find the stripes that intersect the bounding box of r. Box b = r.getBoundingBox().dilatedBy(Angle(BOX_EPSILON)); double ya = std::floor((b.getLat().getA() + Angle(0.5 * PI)) / _subStripeHeight); double yb = std::floor((b.getLat().getB() + Angle(0.5 * PI)) / _subStripeHeight); - int32_t minSS = std::min(static_cast(ya), _numSubStripes - 1); - int32_t maxSS = std::min(static_cast(yb), _numSubStripes - 1); - int32_t minS = minSS / _numSubStripesPerStripe; - int32_t maxS = maxSS / _numSubStripesPerStripe; - for (int32_t s = minS; s <= maxS; ++s) { + std::int32_t minSS = std::min(static_cast(ya), _numSubStripes - 1); + std::int32_t maxSS = std::min(static_cast(yb), _numSubStripes - 1); + std::int32_t minS = minSS / _numSubStripesPerStripe; + std::int32_t maxS = maxSS / _numSubStripesPerStripe; + for (std::int32_t s = minS; s <= maxS; ++s) { // Find the chunks of s that intersect the bounding box of r. Angle chunkWidth = _stripes[s].chunkWidth; - int32_t nc = _stripes[s].numChunksPerStripe; + std::int32_t nc = _stripes[s].numChunksPerStripe; double xa = std::floor(b.getLon().getA() / chunkWidth); double xb = std::floor(b.getLon().getB() / chunkWidth); - int32_t ca = std::min(static_cast(xa), nc - 1); - int32_t cb = std::min(static_cast(xb), nc - 1); + std::int32_t ca = std::min(static_cast(xa), nc - 1); + std::int32_t cb = std::min(static_cast(xb), nc - 1); if (ca == cb && b.getLon().wraps()) { ca = 0; cb = nc - 1; } // Examine each chunk overlapping the bounding box of r. if (ca <= cb) { - for (int32_t c = ca; c <= cb; ++c) { + for (std::int32_t c = ca; c <= cb; ++c) { if ((r.relate(getChunkBoundingBox(s, c)) & DISJOINT) == 0) { chunkIds.push_back(_getChunkId(s, c)); } } } else { - for (int32_t c = 0; c <= cb; ++c) { + for (std::int32_t c = 0; c <= cb; ++c) { if ((r.relate(getChunkBoundingBox(s, c)) & DISJOINT) == 0) { chunkIds.push_back(_getChunkId(s, c)); } } - for (int32_t c = ca; c < nc; ++c) { + for (std::int32_t c = ca; c < nc; ++c) { if ((r.relate(getChunkBoundingBox(s, c)) & DISJOINT) == 0) { chunkIds.push_back(_getChunkId(s, c)); } @@ -160,32 +160,32 @@ std::vector Chunker::getSubChunksIntersecting( Box b = r.getBoundingBox().dilatedBy(Angle(BOX_EPSILON)); double ya = std::floor((b.getLat().getA() + Angle(0.5 * PI)) / _subStripeHeight); double yb = std::floor((b.getLat().getB() + Angle(0.5 * PI)) / _subStripeHeight); - int32_t minSS = std::min(static_cast(ya), _numSubStripes - 1); - int32_t maxSS = std::min(static_cast(yb), _numSubStripes - 1); - int32_t minS = minSS / _numSubStripesPerStripe; - int32_t maxS = maxSS / _numSubStripesPerStripe; - for (int32_t s = minS; s <= maxS; ++s) { + std::int32_t minSS = std::min(static_cast(ya), _numSubStripes - 1); + std::int32_t maxSS = std::min(static_cast(yb), _numSubStripes - 1); + std::int32_t minS = minSS / _numSubStripesPerStripe; + std::int32_t maxS = maxSS / _numSubStripesPerStripe; + for (std::int32_t s = minS; s <= maxS; ++s) { // Find the chunks of s that intersect the bounding box of r. Angle chunkWidth = _stripes[s].chunkWidth; - int32_t nc = _stripes[s].numChunksPerStripe; + std::int32_t nc = _stripes[s].numChunksPerStripe; double xa = std::floor(b.getLon().getA() / chunkWidth); double xb = std::floor(b.getLon().getB() / chunkWidth); - int32_t ca = std::min(static_cast(xa), nc - 1); - int32_t cb = std::min(static_cast(xb), nc - 1); + std::int32_t ca = std::min(static_cast(xa), nc - 1); + std::int32_t cb = std::min(static_cast(xb), nc - 1); if (ca == cb && b.getLon().wraps()) { ca = 0; cb = nc - 1; } // Examine sub-chunks for each chunk overlapping the bounding box of r. if (ca <= cb) { - for (int32_t c = ca; c <= cb; ++c) { + for (std::int32_t c = ca; c <= cb; ++c) { _getSubChunks(chunks, r, b.getLon(), s, c, minSS, maxSS); } } else { - for (int32_t c = 0; c <= cb; ++c) { + for (std::int32_t c = 0; c <= cb; ++c) { _getSubChunks(chunks, r, b.getLon(), s, c, minSS, maxSS); } - for (int32_t c = ca; c < nc; ++c) { + for (std::int32_t c = ca; c < nc; ++c) { _getSubChunks(chunks, r, b.getLon(), s, c, minSS, maxSS); } } @@ -196,10 +196,10 @@ std::vector Chunker::getSubChunksIntersecting( void Chunker::_getSubChunks(std::vector & chunks, Region const & r, NormalizedAngleInterval const & lon, - int32_t stripe, - int32_t chunk, - int32_t minSS, - int32_t maxSS) const + std::int32_t stripe, + std::int32_t chunk, + std::int32_t minSS, + std::int32_t maxSS) const { SubChunks subChunks; subChunks.chunkId = _getChunkId(stripe, chunk); @@ -211,26 +211,26 @@ void Chunker::_getSubChunks(std::vector & chunks, // Find the sub-stripes to iterate over. minSS = std::max(minSS, stripe * _numSubStripesPerStripe); maxSS = std::min(maxSS, (stripe + 1) * _numSubStripesPerStripe - 1); - int32_t const nc = _stripes[stripe].numChunksPerStripe; - for (int32_t ss = minSS; ss <= maxSS; ++ss) { + std::int32_t const nc = _stripes[stripe].numChunksPerStripe; + for (std::int32_t ss = minSS; ss <= maxSS; ++ss) { // Find the sub-chunks of ss to iterate over. Angle subChunkWidth = _subStripes[ss].subChunkWidth; - int32_t const nsc = _subStripes[ss].numSubChunksPerChunk; + std::int32_t const nsc = _subStripes[ss].numSubChunksPerChunk; double xa = std::floor(lon.getA() / subChunkWidth); double xb = std::floor(lon.getB() / subChunkWidth); - int32_t sca = std::min(static_cast(xa), nc * nsc - 1); - int32_t scb = std::min(static_cast(xb), nc * nsc - 1); + std::int32_t sca = std::min(static_cast(xa), nc * nsc - 1); + std::int32_t scb = std::min(static_cast(xb), nc * nsc - 1); if (sca == scb && lon.wraps()) { sca = 0; scb = nc * nsc - 1; } - int32_t minSC = chunk * nsc; - int32_t maxSC = (chunk + 1) * nsc - 1; + std::int32_t minSC = chunk * nsc; + std::int32_t maxSC = (chunk + 1) * nsc - 1; // Test each sub-chunk against r, and record those that intersect. if (sca <= scb) { minSC = std::max(sca, minSC); maxSC = std::min(scb, maxSC); - for (int32_t sc = minSC; sc <= maxSC; ++sc) { + for (std::int32_t sc = minSC; sc <= maxSC; ++sc) { if ((r.relate(getSubChunkBoundingBox(ss, sc)) & DISJOINT) == 0) { subChunks.subChunkIds.push_back( _getSubChunkId(stripe, ss, chunk, sc)); @@ -239,13 +239,13 @@ void Chunker::_getSubChunks(std::vector & chunks, } else { sca = std::max(sca, minSC); scb = std::min(scb, maxSC); - for (int32_t sc = sca; sc <= maxSC; ++sc) { + for (std::int32_t sc = sca; sc <= maxSC; ++sc) { if ((r.relate(getSubChunkBoundingBox(ss, sc)) & DISJOINT) == 0) { subChunks.subChunkIds.push_back( _getSubChunkId(stripe, ss, chunk, sc)); } } - for (int32_t sc = minSC; sc <= scb; ++sc) { + for (std::int32_t sc = minSC; sc <= scb; ++sc) { if ((r.relate(getSubChunkBoundingBox(ss, sc)) & DISJOINT) == 0) { subChunks.subChunkIds.push_back( _getSubChunkId(stripe, ss, chunk, sc)); @@ -262,51 +262,51 @@ void Chunker::_getSubChunks(std::vector & chunks, } } -std::vector Chunker::getAllChunks() const { - std::vector chunkIds; - for (int32_t s = 0; s < _numStripes; ++s) { - int32_t nc = _stripes[s].numChunksPerStripe; - for (int32_t c = 0; c < nc; ++c) { +std::vector Chunker::getAllChunks() const { + std::vector chunkIds; + for (std::int32_t s = 0; s < _numStripes; ++s) { + std::int32_t nc = _stripes[s].numChunksPerStripe; + for (std::int32_t c = 0; c < nc; ++c) { chunkIds.push_back(_getChunkId(s, c)); } } return chunkIds; } -std::vector Chunker::getAllSubChunks(int32_t chunkId) const { - std::vector subChunkIds; - int32_t s = getStripe(chunkId); +std::vector Chunker::getAllSubChunks(std::int32_t chunkId) const { + std::vector subChunkIds; + std::int32_t s = getStripe(chunkId); subChunkIds.reserve(_stripes.at(s).numSubChunksPerChunk); - int32_t const ssBeg = s * _numSubStripesPerStripe; - int32_t const ssEnd = ssBeg + _numSubStripesPerStripe; - for (int32_t ss = ssBeg; ss < ssEnd; ++ss) { - int32_t const scEnd = _subStripes[ss].numSubChunksPerChunk; - int32_t const subChunkIdBase = _maxSubChunksPerSubStripeChunk * (ss - ssBeg); - for (int32_t sc = 0; sc < scEnd; ++sc) { + std::int32_t const ssBeg = s * _numSubStripesPerStripe; + std::int32_t const ssEnd = ssBeg + _numSubStripesPerStripe; + for (std::int32_t ss = ssBeg; ss < ssEnd; ++ss) { + std::int32_t const scEnd = _subStripes[ss].numSubChunksPerChunk; + std::int32_t const subChunkIdBase = _maxSubChunksPerSubStripeChunk * (ss - ssBeg); + for (std::int32_t sc = 0; sc < scEnd; ++sc) { subChunkIds.push_back(subChunkIdBase + sc); } } return subChunkIds; } -bool Chunker::valid(int32_t chunkId) const { - int32_t const s = getStripe(chunkId); +bool Chunker::valid(std::int32_t chunkId) const { + std::int32_t const s = getStripe(chunkId); return s >= 0 and s < _numStripes and getChunk(chunkId, s) < _stripes.at(s).numChunksPerStripe; } -Box Chunker::getChunkBoundingBox(int32_t stripe, int32_t chunk) const { +Box Chunker::getChunkBoundingBox(std::int32_t stripe, std::int32_t chunk) const { Angle chunkWidth = _stripes[stripe].chunkWidth; NormalizedAngleInterval lon(chunkWidth * chunk, chunkWidth * (chunk + 1)); - int32_t ss = stripe * _numSubStripesPerStripe; - int32_t ssEnd = ss + _numSubStripesPerStripe; + std::int32_t ss = stripe * _numSubStripesPerStripe; + std::int32_t ssEnd = ss + _numSubStripesPerStripe; AngleInterval lat(ss * _subStripeHeight - Angle(0.5 * PI), ssEnd * _subStripeHeight - Angle(0.5 * PI)); return Box(lon, lat).dilatedBy(Angle(BOX_EPSILON)); } -Box Chunker::getSubChunkBoundingBox(int32_t subStripe, int32_t subChunk) const { +Box Chunker::getSubChunkBoundingBox(std::int32_t subStripe, std::int32_t subChunk) const { Angle subChunkWidth = _subStripes[subStripe].subChunkWidth; NormalizedAngleInterval lon(subChunkWidth * subChunk, subChunkWidth * (subChunk + 1)); diff --git a/src/Circle.cc b/src/Circle.cc index 288fc8d..13f3fdf 100644 --- a/src/Circle.cc +++ b/src/Circle.cc @@ -336,9 +336,9 @@ Relationship Circle::relate(Ellipse const & e) const { return invert(e.relate(*this)); } -std::vector Circle::encode() const { - std::vector buffer; - uint8_t tc = TYPE_CODE; +std::vector Circle::encode() const { + std::vector buffer; + std::uint8_t tc = TYPE_CODE; buffer.reserve(ENCODED_SIZE); buffer.push_back(tc); encodeDouble(_center.x(), buffer); @@ -349,7 +349,7 @@ std::vector Circle::encode() const { return buffer; } -std::unique_ptr Circle::decode(uint8_t const * buffer, size_t n) { +std::unique_ptr Circle::decode(std::uint8_t const * buffer, size_t n) { if (buffer == nullptr || n != ENCODED_SIZE || *buffer != TYPE_CODE) { throw std::runtime_error("Byte-string is not an encoded Circle"); } diff --git a/src/CompoundRegion.cc b/src/CompoundRegion.cc index 4b4b9f3..cae1d51 100644 --- a/src/CompoundRegion.cc +++ b/src/CompoundRegion.cc @@ -124,7 +124,7 @@ std::array, 2> CompoundRegion::_decode( return result; } -std::unique_ptr CompoundRegion::decode(uint8_t const *buffer, size_t n) { +std::unique_ptr CompoundRegion::decode(std::uint8_t const *buffer, size_t n) { if (n == 0) { throw std::runtime_error("Encoded CompoundRegion is truncated."); } diff --git a/src/ConvexPolygon.cc b/src/ConvexPolygon.cc index 79770d4..598ee8a 100644 --- a/src/ConvexPolygon.cc +++ b/src/ConvexPolygon.cc @@ -352,9 +352,9 @@ Relationship ConvexPolygon::relate(Ellipse const & e) const { return detail::relate(_vertices.begin(), _vertices.end(), e); } -std::vector ConvexPolygon::encode() const { - std::vector buffer; - uint8_t tc = TYPE_CODE; +std::vector ConvexPolygon::encode() const { + std::vector buffer; + std::uint8_t tc = TYPE_CODE; buffer.reserve(1 + 24 * _vertices.size()); buffer.push_back(tc); for (UnitVector3d const & v: _vertices) { @@ -365,7 +365,7 @@ std::vector ConvexPolygon::encode() const { return buffer; } -std::unique_ptr ConvexPolygon::decode(uint8_t const * buffer, +std::unique_ptr ConvexPolygon::decode(std::uint8_t const * buffer, size_t n) { if (buffer == nullptr || *buffer != TYPE_CODE || diff --git a/src/Ellipse.cc b/src/Ellipse.cc index 604ea81..31cfef8 100644 --- a/src/Ellipse.cc +++ b/src/Ellipse.cc @@ -343,9 +343,9 @@ Relationship Ellipse::relate(Ellipse const & e) const { return getBoundingCircle().relate(e.getBoundingCircle()) & DISJOINT; } -std::vector Ellipse::encode() const { - std::vector buffer; - uint8_t tc = TYPE_CODE; +std::vector Ellipse::encode() const { + std::vector buffer; + std::uint8_t tc = TYPE_CODE; buffer.reserve(ENCODED_SIZE); buffer.push_back(tc); for (int r = 0; r < 3; ++r) { @@ -361,7 +361,7 @@ std::vector Ellipse::encode() const { return buffer; } -std::unique_ptr Ellipse::decode(uint8_t const * buffer, size_t n) { +std::unique_ptr Ellipse::decode(std::uint8_t const * buffer, size_t n) { if (buffer == nullptr || n != ENCODED_SIZE || buffer[0] != TYPE_CODE) { throw std::runtime_error("Byte-string is not an encoded Ellipse"); } diff --git a/src/HtmPixelization.cc b/src/HtmPixelization.cc index 1e98440..5d97abe 100644 --- a/src/HtmPixelization.cc +++ b/src/HtmPixelization.cc @@ -78,7 +78,7 @@ class HtmPixelFinder: public detail::PixelFinder< void operator()() { UnitVector3d trixel[3]; // Loop over HTM root triangles. - for (uint64_t r = 0; r < 8; ++r) { + for (std::uint64_t r = 0; r < 8; ++r) { for (int v = 0; v < 3; ++v) { trixel[v] = rootVertex(r, v); } @@ -86,7 +86,7 @@ class HtmPixelFinder: public detail::PixelFinder< } } - void subdivide(UnitVector3d const * trixel, uint64_t index, int level) { + void subdivide(UnitVector3d const * trixel, std::uint64_t index, int level) { UnitVector3d mid[3] = { UnitVector3d(trixel[1] + trixel[2]), UnitVector3d(trixel[2] + trixel[0]), @@ -114,7 +114,7 @@ class HtmPixelFinder: public detail::PixelFinder< } // unnamed namespace -int HtmPixelization::level(uint64_t i) { +int HtmPixelization::level(std::uint64_t i) { // An HTM index consists of 4 bits encoding the root triangle // number (8 - 15), followed by 2l bits, where each of the l bit pairs // encodes a child triangle number (0-3), and l is the desired level. @@ -127,13 +127,13 @@ int HtmPixelization::level(uint64_t i) { return (j - 3) >> 1; } -ConvexPolygon HtmPixelization::triangle(uint64_t i) { +ConvexPolygon HtmPixelization::triangle(std::uint64_t i) { int l = level(i); if (l < 0 || l > MAX_LEVEL) { throw std::invalid_argument("Invalid HTM index"); } l *= 2; - uint64_t r = (i >> l) & 7; + std::uint64_t r = (i >> l) & 7; UnitVector3d v0 = rootVertex(r, 0); UnitVector3d v1 = rootVertex(r, 1); UnitVector3d v2 = rootVertex(r, 2); @@ -152,7 +152,7 @@ ConvexPolygon HtmPixelization::triangle(uint64_t i) { return ConvexPolygon(v0, v1, v2); } -std::string HtmPixelization::asString(uint64_t i) { +std::string HtmPixelization::asString(std::uint64_t i) { char s[MAX_LEVEL + 2]; int l = level(i); if (l < 0 || l > MAX_LEVEL) { @@ -174,9 +174,9 @@ HtmPixelization::HtmPixelization(int level) : _level(level) { } } -uint64_t HtmPixelization::index(UnitVector3d const & v) const { +std::uint64_t HtmPixelization::index(UnitVector3d const & v) const { // Find the root triangle containing v. - uint64_t r; + std::uint64_t r; if (v.z() < 0.0) { // v is in the southern hemisphere (root triangle 0, 1, 2, or 3). if (v.y() > 0.0) { @@ -199,7 +199,7 @@ uint64_t HtmPixelization::index(UnitVector3d const & v) const { UnitVector3d v0 = rootVertex(r, 0); UnitVector3d v1 = rootVertex(r, 1); UnitVector3d v2 = rootVertex(r, 2); - uint64_t i = r + 8; + std::uint64_t i = r + 8; for (int l = 0; l < _level; ++l) { UnitVector3d m01 = UnitVector3d(v0 + v1); UnitVector3d m20 = UnitVector3d(v2 + v0); diff --git a/src/Mq3cPixelization.cc b/src/Mq3cPixelization.cc index 051238b..269c990 100644 --- a/src/Mq3cPixelization.cc +++ b/src/Mq3cPixelization.cc @@ -50,9 +50,9 @@ namespace { // See commentary in Q3cPixelizationImpl.h for an explanation of // these lookup tables. -constexpr uint8_t UNUSED = 255; +constexpr std::uint8_t UNUSED = 255; -alignas(64) uint8_t const FACE_NUM[64] = { +alignas(64) std::uint8_t const FACE_NUM[64] = { 4, 4, 4, 4, UNUSED, 3, UNUSED, UNUSED, UNUSED, UNUSED, 0, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, 2, UNUSED, 3, UNUSED, 2, @@ -63,7 +63,7 @@ alignas(64) uint8_t const FACE_NUM[64] = { UNUSED, UNUSED, 0, UNUSED, 1, 1, 1, 1 }; -uint8_t const FACE_COMP[6][4] = { +std::uint8_t const FACE_COMP[6][4] = { {0, 1, 2, UNUSED}, {1, 2, 0, UNUSED}, {2, 0, 1, UNUSED}, {0, 1, 2, UNUSED}, {1, 2, 0, UNUSED}, {2, 0, 1, UNUSED} }; @@ -83,15 +83,15 @@ constexpr double DILATION = 1.0e-15; // `wrapIndex` returns the modified-Q3C index for grid coordinates (face, s, t) // at the given level. Both s and t may underflow or overflow by 1, i.e. wrap // to an adjacent face. -uint64_t wrapIndex(int level, +std::uint64_t wrapIndex(int level, int face, - uint32_t s, - uint32_t t) + std::uint32_t s, + std::uint32_t t) { - uint32_t const stMax = (static_cast(1) << level) - 1; + std::uint32_t const stMax = (static_cast(1) << level) - 1; // Wrap until no more underflow or overflow is detected. while (true) { - if (s == static_cast(-1)) { + if (s == static_cast(-1)) { face = (face + 4) % 6; s = stMax - t; t = stMax; @@ -101,7 +101,7 @@ uint64_t wrapIndex(int level, s = t; t = 0; continue; - } else if (t == static_cast(-1)) { + } else if (t == static_cast(-1)) { face = (face + 5) % 6; t = s; s = stMax; @@ -114,13 +114,13 @@ uint64_t wrapIndex(int level, } break; } - return (static_cast(face + 10) << (2 * level)) | + return (static_cast(face + 10) << (2 * level)) | hilbertIndex(s, t, level); } -int findNeighborhood(int level, uint64_t i, uint64_t * dst) { +int findNeighborhood(int level, std::uint64_t i, std::uint64_t * dst) { int const face = static_cast(i >> (2 * level)) - 10; - uint32_t s, t; + std::uint32_t s, t; std::tie(s, t) = hilbertIndexInverse(i, level); dst[0] = wrapIndex(level, face, s - 1, t - 1); dst[1] = wrapIndex(level, face, s , t - 1); @@ -136,14 +136,14 @@ int findNeighborhood(int level, uint64_t i, uint64_t * dst) { } #if defined(NO_SIMD) || !defined(__x86_64__) - void makeQuad(uint64_t i, int level, UnitVector3d * verts) { + void makeQuad(std::uint64_t i, int level, UnitVector3d * verts) { int const face = static_cast(i >> (2 * level)) - 10; double const faceScale = FACE_SCALE[level]; double u0, v0; - uint32_t s, t; + std::uint32_t s, t; std::tie(s, t) = hilbertIndexInverse(i, level); std::tie(u0, v0) = gridToFace( - level, static_cast(s), static_cast(t)); + level, static_cast(s), static_cast(t)); double u1 = (u0 + faceScale) + DILATION; double v1 = (v0 + faceScale) + DILATION; u0 -= DILATION; @@ -163,7 +163,7 @@ int findNeighborhood(int level, uint64_t i, uint64_t * dst) { } } #else - void makeQuad(uint64_t i, int level, UnitVector3d * verts) { + void makeQuad(std::uint64_t i, int level, UnitVector3d * verts) { int const face = static_cast(i >> (2 * level)) - 10; __m128d faceScale = _mm_set1_pd(FACE_SCALE[level]); __m128d dilation = _mm_set1_pd(DILATION); @@ -221,16 +221,16 @@ class Mq3cPixelFinder: public detail::PixelFinder< void operator()() { UnitVector3d pixel[4]; // Loop over cube faces - for (uint64_t f = 10; f < 16; ++f) { + for (std::uint64_t f = 10; f < 16; ++f) { makeQuad(f, 0, pixel); visit(pixel, f, 0); } } - void subdivide(UnitVector3d const *, uint64_t i, int level) { + void subdivide(UnitVector3d const *, std::uint64_t i, int level) { UnitVector3d pixel[4]; ++level; - for (uint64_t c = i * 4; c != i * 4 + 4; ++c) { + for (std::uint64_t c = i * 4; c != i * 4 + 4; ++c) { makeQuad(c, level, pixel); visit(pixel, c, level); } @@ -240,7 +240,7 @@ class Mq3cPixelFinder: public detail::PixelFinder< } // unnamed namespace -int Mq3cPixelization::level(uint64_t i) { +int Mq3cPixelization::level(std::uint64_t i) { // A modified Q3C index consists of 4 bits encoding the root cube face // (10 - 15), followed by 2l bits, where each of the l bit pairs encodes // a child index (0-3), and l is the desired level. @@ -254,7 +254,7 @@ int Mq3cPixelization::level(uint64_t i) { return (j - 3) >> 1; } -ConvexPolygon Mq3cPixelization::quad(uint64_t i) { +ConvexPolygon Mq3cPixelization::quad(std::uint64_t i) { int l = level(i); if (l < 0 || l > MAX_LEVEL) { throw std::invalid_argument("Invalid modified-Q3C index"); @@ -264,17 +264,17 @@ ConvexPolygon Mq3cPixelization::quad(uint64_t i) { return ConvexPolygon(verts[0], verts[1], verts[2], verts[3]); } -std::vector Mq3cPixelization::neighborhood(uint64_t i) { +std::vector Mq3cPixelization::neighborhood(std::uint64_t i) { int l = level(i); if (l < 0 || l > MAX_LEVEL) { throw std::invalid_argument("Invalid modified-Q3C index"); } - uint64_t indexes[9]; + std::uint64_t indexes[9]; int n = findNeighborhood(l, i, indexes); - return std::vector(indexes, indexes + n); + return std::vector(indexes, indexes + n); } -std::string Mq3cPixelization::asString(uint64_t i) { +std::string Mq3cPixelization::asString(std::uint64_t i) { static char const FACE_NORM[6][2] = { {'-', 'Z'}, {'+', 'X'}, {'+', 'Y'}, {'+', 'Z'}, {'-', 'X'}, {'-', 'Y'}, @@ -303,8 +303,8 @@ Mq3cPixelization::Mq3cPixelization(int level) : _level{level} { } } -std::unique_ptr Mq3cPixelization::pixel(uint64_t i) const { - uint64_t f = i >> (2 * _level); +std::unique_ptr Mq3cPixelization::pixel(std::uint64_t i) const { + std::uint64_t f = i >> (2 * _level); if (f < 10 || f > 15) { throw std::invalid_argument("Invalid modified-Q3C index"); } @@ -315,20 +315,20 @@ std::unique_ptr Mq3cPixelization::pixel(uint64_t i) const { } #if defined(NO_SIMD) || !defined(__x86_64__) - uint64_t Mq3cPixelization::index(UnitVector3d const & p) const { + std::uint64_t Mq3cPixelization::index(UnitVector3d const & p) const { int face = faceNumber(p, FACE_NUM); double w = std::fabs(p(FACE_COMP[face][2])); double u = (p(FACE_COMP[face][0]) / w) * FACE_CONST[face][0]; double v = (p(FACE_COMP[face][1]) / w) * FACE_CONST[face][1]; std::tie(u, v) = atanApprox(u, v); - std::tuple g = faceToGrid(_level, u, v); - uint64_t h = hilbertIndex(static_cast(std::get<0>(g)), - static_cast(std::get<1>(g)), + std::tuple g = faceToGrid(_level, u, v); + std::uint64_t h = hilbertIndex(static_cast(std::get<0>(g)), + static_cast(std::get<1>(g)), _level); - return (static_cast(face + 10) << (2 * _level)) | h; + return (static_cast(face + 10) << (2 * _level)) | h; } #else - uint64_t Mq3cPixelization::index(UnitVector3d const & p) const { + std::uint64_t Mq3cPixelization::index(UnitVector3d const & p) const { int face = faceNumber(p, FACE_NUM); __m128d ww = _mm_set1_pd(p(FACE_COMP[face][2])); __m128d uv = _mm_set_pd(p(FACE_COMP[face][1]), p(FACE_COMP[face][0])); @@ -337,8 +337,8 @@ std::unique_ptr Mq3cPixelization::pixel(uint64_t i) const { _mm_set_pd(FACE_CONST[face][1], FACE_CONST[face][0]) ); __m128i st = faceToGrid(_level, atanApprox(uv)); - uint64_t h = hilbertIndex(st, _level); - return (static_cast(face + 10) << (2 * _level)) | h; + std::uint64_t h = hilbertIndex(st, _level); + return (static_cast(face + 10) << (2 * _level)) | h; } #endif diff --git a/src/Q3cPixelization.cc b/src/Q3cPixelization.cc index 675fbe0..686b824 100644 --- a/src/Q3cPixelization.cc +++ b/src/Q3cPixelization.cc @@ -50,9 +50,9 @@ namespace { // See commentary in Q3cPixelizationImpl.h for an explanation of // these lookup tables. -constexpr uint8_t UNUSED = 255; +constexpr std::uint8_t UNUSED = 255; -alignas(64) uint8_t const FACE_NUM[64] = { +alignas(64) std::uint8_t const FACE_NUM[64] = { 3, 3, 3, 3, UNUSED, 0, UNUSED, UNUSED, UNUSED, UNUSED, 5, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, 2, UNUSED, 0, UNUSED, 2, @@ -63,7 +63,7 @@ alignas(64) uint8_t const FACE_NUM[64] = { UNUSED, UNUSED, 5, UNUSED, 1, 1, 1, 1 }; -uint8_t const FACE_COMP[6][4] = { +std::uint8_t const FACE_COMP[6][4] = { {1, 0, 2, UNUSED}, {1, 2, 0, UNUSED}, {0, 2, 1, UNUSED}, {1, 2, 0, UNUSED}, {0, 2, 1, UNUSED}, {1, 0, 2, UNUSED} }; @@ -89,15 +89,15 @@ constexpr double DILATION = 1.0e-15; // `wrapIndex` returns the Q3C index for grid coordinates (face, s, t) at // the given level. Both s and t may underflow or overflow by 1, i.e. wrap // to an adjacent face. -uint64_t wrapIndex(int level, +std::uint64_t wrapIndex(int level, int face, - uint32_t s, - uint32_t t) + std::uint32_t s, + std::uint32_t t) { - uint32_t const stMax = (static_cast(1) << level) - 1; + std::uint32_t const stMax = (static_cast(1) << level) - 1; // Wrap until no more underflow or overflow is detected. while (true) { - if (s == static_cast(-1)) { + if (s == static_cast(-1)) { switch (face) { case 0: face = 4; s = stMax - t; t = stMax; break; case 1: face = 4; s = stMax; break; @@ -119,7 +119,7 @@ uint64_t wrapIndex(int level, default: break; } continue; - } else if (t == static_cast(-1)) { + } else if (t == static_cast(-1)) { switch (face) { case 0: face = 1; t = stMax; break; case 1: face = 5; t = stMax; break; @@ -144,13 +144,13 @@ uint64_t wrapIndex(int level, } break; } - return (static_cast(face) << (2 * level)) | mortonIndex(s, t); + return (static_cast(face) << (2 * level)) | mortonIndex(s, t); } -int findNeighborhood(int level, uint64_t i, uint64_t * dst) { - uint64_t const mask = (static_cast(1) << (2 * level)) - 1; +int findNeighborhood(int level, std::uint64_t i, std::uint64_t * dst) { + std::uint64_t const mask = (static_cast(1) << (2 * level)) - 1; int const face = static_cast(i >> (2 * level)); - uint32_t s, t; + std::uint32_t s, t; std::tie(s, t) = mortonIndexInverse(i & mask); dst[0] = wrapIndex(level, face, s - 1, t - 1); dst[1] = wrapIndex(level, face, s , t - 1); @@ -166,15 +166,15 @@ int findNeighborhood(int level, uint64_t i, uint64_t * dst) { } #if defined(NO_SIMD) || !defined(__x86_64__) - void makeQuad(uint64_t i, int level, UnitVector3d * verts) { - uint64_t const mask = (static_cast(1) << (2 * level)) - 1; + void makeQuad(std::uint64_t i, int level, UnitVector3d * verts) { + std::uint64_t const mask = (static_cast(1) << (2 * level)) - 1; int const face = static_cast(i >> (2 * level)); double const faceScale = FACE_SCALE[level]; double u0, v0; - uint32_t s, t; + std::uint32_t s, t; std::tie(s, t) = mortonIndexInverse(i & mask); std::tie(u0, v0) = gridToFace( - level, static_cast(s), static_cast(t)); + level, static_cast(s), static_cast(t)); double u1 = (u0 + faceScale) + DILATION; double v1 = (v0 + faceScale) + DILATION; u0 -= DILATION; @@ -185,8 +185,8 @@ int findNeighborhood(int level, uint64_t i, uint64_t * dst) { verts[3] = faceToSphere(face, u0, v1, FACE_COMP, FACE_CONST); } #else - void makeQuad(uint64_t i, int level, UnitVector3d * verts) { - uint64_t const mask = (static_cast(1) << (2 * level)) - 1; + void makeQuad(std::uint64_t i, int level, UnitVector3d * verts) { + std::uint64_t const mask = (static_cast(1) << (2 * level)) - 1; int const face = static_cast(i >> (2 * level)); __m128d faceScale = _mm_set1_pd(FACE_SCALE[level]); __m128d dilation = _mm_set1_pd(DILATION); @@ -241,16 +241,16 @@ class Q3cPixelFinder: public detail::PixelFinder< void operator()() { UnitVector3d pixel[4]; // Loop over cube faces - for (uint64_t f = 0; f < 6; ++f) { + for (std::uint64_t f = 0; f < 6; ++f) { makeQuad(f, 0, pixel); visit(pixel, f, 0); } } - void subdivide(UnitVector3d const *, uint64_t i, int level) { + void subdivide(UnitVector3d const *, std::uint64_t i, int level) { UnitVector3d pixel[4]; ++level; - for (uint64_t c = i * 4; c != i * 4 + 4; ++c) { + for (std::uint64_t c = i * 4; c != i * 4 + 4; ++c) { makeQuad(c, level, pixel); visit(pixel, c, level); } @@ -266,8 +266,8 @@ Q3cPixelization::Q3cPixelization(int level) : _level{level} { } } -ConvexPolygon Q3cPixelization::quad(uint64_t i) const { - if (i >= static_cast(6) << (2 * _level)) { +ConvexPolygon Q3cPixelization::quad(std::uint64_t i) const { + if (i >= static_cast(6) << (2 * _level)) { throw std::invalid_argument("Invalid Q3C index"); } UnitVector3d verts[4]; @@ -275,22 +275,22 @@ ConvexPolygon Q3cPixelization::quad(uint64_t i) const { return ConvexPolygon(verts[0], verts[1], verts[2], verts[3]); } -std::vector Q3cPixelization::neighborhood(uint64_t i) const { - if (i >= static_cast(6) << (2 * _level)) { +std::vector Q3cPixelization::neighborhood(std::uint64_t i) const { + if (i >= static_cast(6) << (2 * _level)) { throw std::invalid_argument("Invalid Q3C index"); } - uint64_t indexes[9]; + std::uint64_t indexes[9]; int n = findNeighborhood(_level, i, indexes); - return std::vector(indexes, indexes + n); + return std::vector(indexes, indexes + n); } -std::string Q3cPixelization::toString(uint64_t i) const { +std::string Q3cPixelization::toString(std::uint64_t i) const { static char const FACE_NORM[6][2] = { {'+', 'Z'}, {'+', 'X'}, {'+', 'Y'}, {'-', 'X'}, {'-', 'Y'}, {'-', 'Z'}, }; char s[MAX_LEVEL + 2]; - if (i >= static_cast(6) << (2 * _level)) { + if (i >= static_cast(6) << (2 * _level)) { throw std::invalid_argument("Invalid Q3C index"); } // Print in base-4, from least to most significant digit. @@ -305,8 +305,8 @@ std::string Q3cPixelization::toString(uint64_t i) const { return std::string(p, sizeof(s) - static_cast(p - s)); } -std::unique_ptr Q3cPixelization::pixel(uint64_t i) const { - if (i >= static_cast(6) << (2 * _level)) { +std::unique_ptr Q3cPixelization::pixel(std::uint64_t i) const { + if (i >= static_cast(6) << (2 * _level)) { throw std::invalid_argument("Invalid Q3C index"); } UnitVector3d verts[4]; @@ -316,18 +316,18 @@ std::unique_ptr Q3cPixelization::pixel(uint64_t i) const { } #if defined(NO_SIMD) || !defined(__x86_64__) - uint64_t Q3cPixelization::index(UnitVector3d const & p) const { + std::uint64_t Q3cPixelization::index(UnitVector3d const & p) const { int face = faceNumber(p, FACE_NUM); double w = std::fabs(p(FACE_COMP[face][2])); double u = (p(FACE_COMP[face][0]) / w) * FACE_CONST[face][0]; double v = (p(FACE_COMP[face][1]) / w) * FACE_CONST[face][1]; - std::tuple g = faceToGrid(_level, u, v); - uint64_t z = mortonIndex(static_cast(std::get<0>(g)), - static_cast(std::get<1>(g))); - return (static_cast(face) << (2 * _level)) | z; + std::tuple g = faceToGrid(_level, u, v); + std::uint64_t z = mortonIndex(static_cast(std::get<0>(g)), + static_cast(std::get<1>(g))); + return (static_cast(face) << (2 * _level)) | z; } #else - uint64_t Q3cPixelization::index(UnitVector3d const & p) const { + std::uint64_t Q3cPixelization::index(UnitVector3d const & p) const { int face = faceNumber(p, FACE_NUM); __m128d ww = _mm_set1_pd(p(FACE_COMP[face][2])); __m128d uv = _mm_set_pd(p(FACE_COMP[face][1]), p(FACE_COMP[face][0])); @@ -336,7 +336,7 @@ std::unique_ptr Q3cPixelization::pixel(uint64_t i) const { _mm_set_pd(FACE_CONST[face][1], FACE_CONST[face][0]) ); __m128i st = faceToGrid(_level, uv); - return (static_cast(face) << (2 * _level)) | mortonIndex(st); + return (static_cast(face) << (2 * _level)) | mortonIndex(st); } #endif diff --git a/src/Q3cPixelizationImpl.h b/src/Q3cPixelizationImpl.h index 2ee1e8e..8732e95 100644 --- a/src/Q3cPixelizationImpl.h +++ b/src/Q3cPixelizationImpl.h @@ -230,7 +230,7 @@ double const FACE_SCALE[31] = { #if defined(NO_SIMD) || !defined(__x86_64__) - int faceNumber(UnitVector3d const & v, uint8_t const (&faceNumbers)[64]) { + int faceNumber(UnitVector3d const & v, std::uint8_t const (&faceNumbers)[64]) { int index = ((v.x() > v.y()) << 5) + ((v.x() > -v.y()) << 4) + ((v.x() > v.z()) << 3) + @@ -243,7 +243,7 @@ double const FACE_SCALE[31] = { UnitVector3d faceToSphere(int face, double u, double v, - uint8_t const (&faceComponents)[6][4], + std::uint8_t const (&faceComponents)[6][4], double const (&faceConstants)[6][4]) { double p[3]; @@ -255,18 +255,18 @@ double const FACE_SCALE[31] = { return UnitVector3d::fromNormalized(p[0], p[1], p[2]); } - std::tuple faceToGrid(int level, double u, double v) { + std::tuple faceToGrid(int level, double u, double v) { double const gridScale = GRID_SCALE[level]; double const stMax = ST_MAX[level]; double s = u * gridScale + gridScale; double t = v * gridScale + gridScale; s = std::max(std::min(s, stMax), 0.0); t = std::max(std::min(t, stMax), 0.0); - return std::make_tuple(static_cast(s), - static_cast(t)); + return std::make_tuple(static_cast(s), + static_cast(t)); } - std::tuple gridToFace(int level, int32_t s, int32_t t) { + std::tuple gridToFace(int level, std::int32_t s, std::int32_t t) { double const faceScale = FACE_SCALE[level]; return std::make_tuple(static_cast(s) * faceScale - 1.0, static_cast(t) * faceScale - 1.0); @@ -288,7 +288,7 @@ double const FACE_SCALE[31] = { #else - int faceNumber(UnitVector3d const & v, uint8_t const (&faceNumbers)[64]) { + int faceNumber(UnitVector3d const & v, std::uint8_t const (&faceNumbers)[64]) { __m128d const m00 = _mm_set_pd(0.0, -0.0); __m128d xx = _mm_set1_pd(v.x()); __m128d yy = _mm_set1_pd(v.y()); @@ -303,7 +303,7 @@ double const FACE_SCALE[31] = { UnitVector3d faceToSphere(int face, __m128d uv, - uint8_t const (&faceComponents)[6][4], + std::uint8_t const (&faceComponents)[6][4], double const (&faceConstants)[6][4]) { double p[3]; diff --git a/src/RangeSet.cc b/src/RangeSet.cc index 20fc051..30b8f02 100644 --- a/src/RangeSet.cc +++ b/src/RangeSet.cc @@ -46,19 +46,19 @@ namespace { inline ptrdiff_t roundUpToEven(ptrdiff_t i) { return i + (i & 1); } -// `RangeIter` is a stride-2 iterator over uint64_t values +// `RangeIter` is a stride-2 iterator over std::uint64_t values // in an underlying array. struct RangeIter { // For std::iterator_traits using difference_type = ptrdiff_t; - using value_type = uint64_t; - using pointer = uint64_t *; - using reference = uint64_t &; + using value_type = std::uint64_t; + using pointer = std::uint64_t *; + using reference = std::uint64_t &; using iterator_category = std::random_access_iterator_tag; RangeIter() = default; - explicit RangeIter(uint64_t * p) : ptr{p} {} + explicit RangeIter(std::uint64_t * p) : ptr{p} {} friend void swap(RangeIter & a, RangeIter & b) { std::swap(a.ptr, b.ptr); } @@ -88,27 +88,27 @@ struct RangeIter { bool operator>=(RangeIter const & i) const { return ptr >= i.ptr; } // Dereferencing - uint64_t & operator*() const { return *ptr; } - uint64_t * operator->() const { return ptr; } - uint64_t & operator[](ptrdiff_t n) const { return ptr[2 * n]; } + std::uint64_t & operator*() const { return *ptr; } + std::uint64_t * operator->() const { return ptr; } + std::uint64_t & operator[](ptrdiff_t n) const { return ptr[2 * n]; } - uint64_t * ptr = nullptr; + std::uint64_t * ptr = nullptr; }; } // unnamed namespace -RangeSet::RangeSet(std::initializer_list list) : +RangeSet::RangeSet(std::initializer_list list) : RangeSet(list.begin(), list.end()) {} -RangeSet::RangeSet(std::initializer_list> list) { +RangeSet::RangeSet(std::initializer_list> list) { for (auto t: list) { insert(std::get<0>(t), std::get<1>(t)); } } -void RangeSet::insert(uint64_t first, uint64_t last) { +void RangeSet::insert(std::uint64_t first, std::uint64_t last) { if (first == last) { fill(); } else { @@ -125,7 +125,7 @@ void RangeSet::insert(uint64_t first, uint64_t last) { } } -void RangeSet::erase(uint64_t first, uint64_t last) { +void RangeSet::erase(std::uint64_t first, std::uint64_t last) { // To erase [first, last), insert it into the complement of this set, // then complement the result. The complements are performed in the // constructor and destructor of a local object, so that the second @@ -196,10 +196,10 @@ RangeSet RangeSet::symmetricDifference(RangeSet const & s) const { // the main loop. Then, 1 is subtracted from all other values prior // to comparison, yielding the proper ordering (since subtracting // 1 from a trailing zero bookend results in 2^64 - 1). - uint64_t const * a = _begin(); - uint64_t const * aend = _end(); - uint64_t const * b = s._begin(); - uint64_t const * bend = s._end(); + std::uint64_t const * a = _begin(); + std::uint64_t const * aend = _end(); + std::uint64_t const * b = s._begin(); + std::uint64_t const * bend = s._end(); int astate = (*a == 0); int bstate = (*b == 0); a += astate; @@ -214,13 +214,13 @@ RangeSet RangeSet::symmetricDifference(RangeSet const & s) const { result._offset = (state == 0); // Merge lists until one or both are exhausted. while (a != aend && b != bend) { - uint64_t av = *a - 1; - uint64_t bv = *b - 1; + std::uint64_t av = *a - 1; + std::uint64_t bv = *b - 1; // The pointer(s) yielding the minimal value will be // incremented. bool ainc = (av <= bv); bool binc = (bv <= av); - uint64_t minval = ainc ? av : bv; + std::uint64_t minval = ainc ? av : bv; astate ^= ainc; bstate ^= binc; // Output the minimum value if the output state changes. @@ -245,7 +245,7 @@ RangeSet RangeSet::symmetricDifference(RangeSet const & s) const { return result; } -bool RangeSet::intersects(uint64_t first, uint64_t last) const { +bool RangeSet::intersects(std::uint64_t first, std::uint64_t last) const { if (empty()) { return false; } @@ -253,10 +253,10 @@ bool RangeSet::intersects(uint64_t first, uint64_t last) const { return true; } if (first <= last - 1) { - uint64_t r[2] = {first, last}; + std::uint64_t r[2] = {first, last}; return _intersectsOne(r, _begin(), _end()); } - uint64_t r[4] = {0, last, first, 0}; + std::uint64_t r[4] = {0, last, first, 0}; return _intersectsOne(r, _begin(), _end()) || _intersectsOne(r + 2, _begin(), _end()); } @@ -268,7 +268,7 @@ bool RangeSet::intersects(RangeSet const & s) const { return _intersects(_begin(), _end(), s._begin(), s._end()); } -bool RangeSet::contains(uint64_t first, uint64_t last) const { +bool RangeSet::contains(std::uint64_t first, std::uint64_t last) const { if (full()) { return true; } @@ -276,10 +276,10 @@ bool RangeSet::contains(uint64_t first, uint64_t last) const { return false; } if (first <= last - 1) { - uint64_t r[2] = {first, last}; + std::uint64_t r[2] = {first, last}; return !_intersectsOne(r, _beginc(), _endc()); } - uint64_t r[4] = {0, last, first, 0}; + std::uint64_t r[4] = {0, last, first, 0}; return !_intersectsOne(r, _beginc(), _endc()) && !_intersectsOne(r + 2, _beginc(), _endc()); } @@ -291,28 +291,28 @@ bool RangeSet::contains(RangeSet const & s) const { return !_intersects(_beginc(), _endc(), s._begin(), s._end()); } -bool RangeSet::isWithin(uint64_t first, uint64_t last) const { +bool RangeSet::isWithin(std::uint64_t first, std::uint64_t last) const { if (empty() || first == last) { return true; } if (last <= first - 1) { - uint64_t r[2] = {last, first}; + std::uint64_t r[2] = {last, first}; return !_intersectsOne(r, _begin(), _end()); } - uint64_t r[4] = {0, first, last, 0}; + std::uint64_t r[4] = {0, first, last, 0}; return !_intersectsOne(r, _begin(), _end()) && !_intersectsOne(r + 2, _begin(), _end()); } -uint64_t RangeSet::cardinality() const { - uint64_t sz = 0; +std::uint64_t RangeSet::cardinality() const { + std::uint64_t sz = 0; for (auto r = _begin(), e = _end(); r != e; r += 2) { sz += r[1] - r[0]; } return sz; } -RangeSet & RangeSet::simplify(uint32_t n) { +RangeSet & RangeSet::simplify(std::uint32_t n) { if (empty() || n == 0) { return *this; } else if (n >= 64) { @@ -322,13 +322,13 @@ RangeSet & RangeSet::simplify(uint32_t n) { // Compute m, the integer with n LSBs set to 1. Then, (x & ~m) is x // rounded down to the nearest multiple of 2^n, and (x + m) & ~m is // x rounded up to the nearest multiple of 2^n. - uint64_t const m = (static_cast(1) << n) - 1; - uint64_t * r = const_cast(_begin()); - uint64_t * rend = const_cast(_end()); - uint64_t * out = r; + std::uint64_t const m = (static_cast(1) << n) - 1; + std::uint64_t * r = const_cast(_begin()); + std::uint64_t * rend = const_cast(_end()); + std::uint64_t * out = r; // Expand the first range. - uint64_t first = r[0] & ~m; - uint64_t last = (r[1] + m) & ~m; + std::uint64_t first = r[0] & ~m; + std::uint64_t last = (r[1] + m) & ~m; if (r[0] != 0 && first == 0) { // The expanded first range now contains the leading bookend. _offset = false; @@ -338,8 +338,8 @@ RangeSet & RangeSet::simplify(uint32_t n) { out[1] = last; // Expand the remaining ranges. for (r += 2; last != 0 && r != rend; r += 2) { - uint64_t u = r[0] & ~m; - uint64_t v = (r[1] + m) & ~m; + std::uint64_t u = r[0] & ~m; + std::uint64_t v = (r[1] + m) & ~m; if (u > last) { out += 2; out[0] = u; @@ -358,18 +358,18 @@ RangeSet & RangeSet::simplify(uint32_t n) { return *this; } -RangeSet & RangeSet::scale(uint64_t i) { +RangeSet & RangeSet::scale(std::uint64_t i) { if (empty() || i == 1) { return *this; } else if (i == 0) { clear(); return *this; } - uint64_t overflowThreshold = static_cast(-1) / i; + std::uint64_t overflowThreshold = static_cast(-1) / i; auto r = _ranges.begin(); auto rend = _ranges.end(); for (; r < rend; ++r) { - uint64_t value = *r; + std::uint64_t value = *r; if (value > overflowThreshold) { *r = 0; ++r; @@ -398,17 +398,17 @@ bool RangeSet::isValid() const { return true; } -void RangeSet::_insert(uint64_t first, uint64_t last) { +void RangeSet::_insert(std::uint64_t first, std::uint64_t last) { // First, check if this set is empty, or if [first, last) extends // or comes after the last range in this set. // // It is assumed that first <= last - 1; that is, first and last // do not correspond to a full range, or one that wraps. - uint64_t * r = const_cast(_begin()); - uint64_t * rend = const_cast(_end()); + std::uint64_t * r = const_cast(_begin()); + std::uint64_t * rend = const_cast(_end()); if (r == rend) { // This set is empty. - uint64_t array[4] = {0, first, last, 0}; + std::uint64_t array[4] = {0, first, last, 0}; _ranges.assign(array + (first == 0), array + (4 - (last == 0))); _offset = (first != 0); } else if (first >= rend[-2]) { @@ -431,15 +431,15 @@ void RangeSet::_insert(uint64_t first, uint64_t last) { } else { // Find a, the first range with end point a[1] >= first, and b, // the first range with beginning point b[0] > last. - uint64_t * a; - uint64_t * b; + std::uint64_t * a; + std::uint64_t * b; if (first == 0) { a = r; } else { // Subtract one from values before comparisons so that the // trailing zero bookend is ordered properly. a = std::lower_bound(RangeIter(r + 1), RangeIter(rend + 1), first, - [](uint64_t u, uint64_t v) { + [](std::uint64_t u, std::uint64_t v) { return u - 1 < v - 1; }).ptr - 1; } @@ -483,10 +483,10 @@ void RangeSet::_insert(uint64_t first, uint64_t last) { /// `_intersectOne` stores the intersection of the single range pointed /// to by `a` and the ranges pointed to by `b` in `v`. -void RangeSet::_intersectOne(std::vector & v, - uint64_t const * a, - uint64_t const * b, - uint64_t const * bend) +void RangeSet::_intersectOne(std::vector & v, + std::uint64_t const * a, + std::uint64_t const * b, + std::uint64_t const * bend) { // The range B = [b[0], bend[-1]) contains all the ranges // [b[0], b[1]), ... , [bend[-2], bend[-1]). If [a[0], a[1]) @@ -500,7 +500,7 @@ void RangeSet::_intersectOne(std::vector & v, } if (b + 2 == bend) { // Output the intersection of the ranges pointed to by a and b. - uint64_t u = std::max(a[0], b[0]); + std::uint64_t u = std::max(a[0], b[0]); if (u != 0) { v.push_back(u); } @@ -512,7 +512,7 @@ void RangeSet::_intersectOne(std::vector & v, } else { // Divide and conquer - split the list of ranges pointed // to by b in half and recurse. - uint64_t const * bmid = b + roundUpToEven((bend - b) >> 1); + std::uint64_t const * bmid = b + roundUpToEven((bend - b) >> 1); _intersectOne(v, a, b, bmid); _intersectOne(v, a, bmid, bend); } @@ -520,11 +520,11 @@ void RangeSet::_intersectOne(std::vector & v, /// `_intersect` stores the intersection of the ranges pointed to by `a` /// and the ranges pointed to by `b` in `v`. -void RangeSet::_intersect(std::vector & v, - uint64_t const * a, - uint64_t const * aend, - uint64_t const * b, - uint64_t const * bend) +void RangeSet::_intersect(std::vector & v, + std::uint64_t const * a, + std::uint64_t const * aend, + std::uint64_t const * b, + std::uint64_t const * bend) { // The range A = [a[0], aend[-1]) contains all the ranges // [a[0], a[1]), ... , [aend[-2], aend[-1]), and similarly, @@ -548,8 +548,8 @@ void RangeSet::_intersect(std::vector & v, // // Note that the order of the recursive calls matters - // output must be generated in sorted order. - uint64_t const * amid = a + roundUpToEven((aend - a) >> 1); - uint64_t const * bmid = b + roundUpToEven((bend - b) >> 1); + std::uint64_t const * amid = a + roundUpToEven((aend - a) >> 1); + std::uint64_t const * bmid = b + roundUpToEven((bend - b) >> 1); _intersect(v, a, amid, b, bmid); _intersect(v, a, amid, bmid, bend); _intersect(v, amid, aend, b, bmid); @@ -557,10 +557,10 @@ void RangeSet::_intersect(std::vector & v, } } -void RangeSet::_intersect(uint64_t const * a, - uint64_t const * aend, - uint64_t const * b, - uint64_t const * bend) +void RangeSet::_intersect(std::uint64_t const * a, + std::uint64_t const * aend, + std::uint64_t const * b, + std::uint64_t const * bend) { if (a == aend || b == bend) { clear(); @@ -580,9 +580,9 @@ void RangeSet::_intersect(uint64_t const * a, /// `_intersectsOne` checks if the single range pointed to by `a` intersects /// any of the ranges pointed to by `b`. -bool RangeSet::_intersectsOne(uint64_t const * a, - uint64_t const * b, - uint64_t const * bend) +bool RangeSet::_intersectsOne(std::uint64_t const * a, + std::uint64_t const * b, + std::uint64_t const * bend) { // See the comments in _intersectOne for an explanation. if (a[0] > bend[-1] - 1 || a[1] - 1 < b[0]) { @@ -591,16 +591,16 @@ bool RangeSet::_intersectsOne(uint64_t const * a, if (b + 2 == bend || a[0] <= b[0] || a[1] - 1 >= bend[-1] - 1) { return true; } - uint64_t const * bmid = b + roundUpToEven((bend - b) >> 1); + std::uint64_t const * bmid = b + roundUpToEven((bend - b) >> 1); return _intersectsOne(a, b, bmid) || _intersectsOne(a, bmid, bend); } /// `_intersects` checks if any of the ranges pointed to by `a` intersect /// any of the ranges pointed to by `b`. -bool RangeSet::_intersects(uint64_t const * a, - uint64_t const * aend, - uint64_t const * b, - uint64_t const * bend) +bool RangeSet::_intersects(std::uint64_t const * a, + std::uint64_t const * aend, + std::uint64_t const * b, + std::uint64_t const * bend) { // See the comments in _intersect for an explanation. if (a + 2 == aend) { @@ -612,8 +612,8 @@ bool RangeSet::_intersects(uint64_t const * a, if (a[0] > bend[-1] - 1 || aend[-1] - 1 < b[0]) { return false; } - uint64_t const * amid = a + roundUpToEven((aend - a) >> 1); - uint64_t const * bmid = b + roundUpToEven((bend - b) >> 1); + std::uint64_t const * amid = a + roundUpToEven((aend - a) >> 1); + std::uint64_t const * bmid = b + roundUpToEven((bend - b) >> 1); return _intersects(a, amid, b, bmid) || _intersects(a, amid, bmid, bend) || _intersects(amid, aend, b, bmid) || diff --git a/src/Region.cc b/src/Region.cc index a72f3ce..37d6cfb 100644 --- a/src/Region.cc +++ b/src/Region.cc @@ -52,11 +52,11 @@ bool Region::contains(double lon, double lat) const { return contains(UnitVector3d(LonLat::fromRadians(lon, lat))); } -std::unique_ptr Region::decode(uint8_t const * buffer, size_t n) { +std::unique_ptr Region::decode(std::uint8_t const * buffer, size_t n) { if (buffer == nullptr || n == 0) { throw std::runtime_error("Byte-string is not an encoded Region"); } - uint8_t type = *buffer; + std::uint8_t type = *buffer; if (type == Box::TYPE_CODE) { return Box::decode(buffer, n); } else if (type == Circle::TYPE_CODE) { diff --git a/src/Vector3d.cc b/src/Vector3d.cc index e716fca..f3dc349 100644 --- a/src/Vector3d.cc +++ b/src/Vector3d.cc @@ -37,6 +37,7 @@ #endif #include #include +#include #include "lsst/sphgeom/Angle.h" #include "lsst/sphgeom/UnitVector3d.h" @@ -46,7 +47,7 @@ namespace lsst { namespace sphgeom { double Vector3d::normalize() { - static constexpr uint8_t UNUSED = 255; + static constexpr std::uint8_t UNUSED = 255; // Given a 3 component vector (x, y, z), this LUT provides the indexes // of the components in order of smallest absolute value to largest. // The index into the LUT must be computed as: @@ -54,7 +55,7 @@ double Vector3d::normalize() { // ((|x| > |z|) << 2) + // ((|x| > |y|) << 1) + // (|y| > |z|) - static uint8_t const COMPONENT[8][4] = { + static std::uint8_t const COMPONENT[8][4] = { {0, 1, 2, UNUSED}, {0, 2, 1, UNUSED}, {1, 0, 2, UNUSED}, diff --git a/src/orientation.cc b/src/orientation.cc index 84c1fed..71bc48a 100644 --- a/src/orientation.cc +++ b/src/orientation.cc @@ -57,8 +57,8 @@ void computeProduct(BigFloat & p, double d0, double d1, double d2) { // This constant (2^53) is used to scale the fractions returned by // std::frexp and turn them into integer mantissas. static double const SCALE = 9007199254740992.0; - uint32_t buf[2]; - BigInteger i(buf, sizeof(buf) / sizeof(uint32_t)); + std::uint32_t buf[2]; + BigInteger i(buf, sizeof(buf) / sizeof(std::uint32_t)); // Unpack the 3 input doubles into integer mantissas and exponents. int e0 = 0; int e1 = 0; @@ -67,10 +67,10 @@ void computeProduct(BigFloat & p, double d0, double d1, double d2) { double m1 = std::frexp(d1, &e1) * SCALE; double m2 = std::frexp(d2, &e2) * SCALE; // Compute the product of the 3 input doubles using exact arithmetic. - p.mantissa->setTo(static_cast(m0)); - i.setTo(static_cast(m1)); + p.mantissa->setTo(static_cast(m0)); + i.setTo(static_cast(m1)); p.mantissa->multiply(i); - i.setTo(static_cast(m2)); + i.setTo(static_cast(m2)); p.mantissa->multiply(i); // Finally, adjust the exponent of the result to compensate for the 3 // multiplications by 2^53 performed above. @@ -85,7 +85,7 @@ int orientationExact(Vector3d const & a, Vector3d const & c) { // Product mantissa storage buffers. - uint32_t mantissaBuffers[6][6]; + std::uint32_t mantissaBuffers[6][6]; // Product mantissas. BigInteger mantissas[6] = { BigInteger(mantissaBuffers[0], 6), @@ -104,9 +104,9 @@ int orientationExact(Vector3d const & a, BigFloat(&mantissas[5]) }; // An accumulator and its storage. - uint32_t accumulatorBuffer[512]; + std::uint32_t accumulatorBuffer[512]; BigInteger accumulator(accumulatorBuffer, - sizeof(accumulatorBuffer) / sizeof(uint32_t)); + sizeof(accumulatorBuffer) / sizeof(std::uint32_t)); // Compute the products in the determinant. Performing all multiplication // up front means that each product mantissa occupies at most 3*53 bits. computeProduct(products[0], a.x(), b.y(), c.z());