Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHieu Hoang <hieu@hoang.co.uk>2013-05-29 21:16:15 +0400
committerHieu Hoang <hieu@hoang.co.uk>2013-05-29 21:16:15 +0400
commit6249432407af8730c10bccc7894c0725fcaf5e47 (patch)
tree3ac1f094b9fdc199b04bc5ef209ce00e3596e37d /util/double-conversion
parent59bd7deb4b6b9c4f7b3b7dbb055783528fbc31ca (diff)
beautify
Diffstat (limited to 'util/double-conversion')
-rw-r--r--util/double-conversion/bignum-dtoa.h3
-rw-r--r--util/double-conversion/bignum.h18
-rw-r--r--util/double-conversion/cached-powers.h18
-rw-r--r--util/double-conversion/diy-fp.h26
-rw-r--r--util/double-conversion/double-conversion.h49
-rw-r--r--util/double-conversion/fast-dtoa.h3
-rw-r--r--util/double-conversion/fixed-dtoa.h3
-rw-r--r--util/double-conversion/ieee.h59
-rw-r--r--util/double-conversion/strtod.h3
-rw-r--r--util/double-conversion/utils.h70
10 files changed, 161 insertions, 91 deletions
diff --git a/util/double-conversion/bignum-dtoa.h b/util/double-conversion/bignum-dtoa.h
index 34b961992..652a4db9a 100644
--- a/util/double-conversion/bignum-dtoa.h
+++ b/util/double-conversion/bignum-dtoa.h
@@ -30,7 +30,8 @@
#include "utils.h"
-namespace double_conversion {
+namespace double_conversion
+{
enum BignumDtoaMode {
// Return the shortest correct representation.
diff --git a/util/double-conversion/bignum.h b/util/double-conversion/bignum.h
index 5ec3544f5..5deadbfbe 100644
--- a/util/double-conversion/bignum.h
+++ b/util/double-conversion/bignum.h
@@ -30,10 +30,12 @@
#include "utils.h"
-namespace double_conversion {
+namespace double_conversion
+{
-class Bignum {
- public:
+class Bignum
+{
+public:
// 3584 = 128 * 28. We can represent 2^3584 > 10^1000 accurately.
// This bignum can encode much bigger numbers, since it contains an
// exponent.
@@ -60,7 +62,9 @@ class Bignum {
void MultiplyByUInt32(uint32_t factor);
void MultiplyByUInt64(uint64_t factor);
void MultiplyByPowerOfTen(int exponent);
- void Times10() { return MultiplyByUInt32(10); }
+ void Times10() {
+ return MultiplyByUInt32(10);
+ }
// Pseudocode:
// int result = this / other;
// this = this % other;
@@ -97,7 +101,7 @@ class Bignum {
static bool PlusLess(const Bignum& a, const Bignum& b, const Bignum& c) {
return PlusCompare(a, b, c) < 0;
}
- private:
+private:
typedef uint32_t Chunk;
typedef uint64_t DoubleChunk;
@@ -125,7 +129,9 @@ class Bignum {
// shift_amount must be < kBigitSize.
void BigitsShiftLeft(int shift_amount);
// BigitLength includes the "hidden" digits encoded in the exponent.
- int BigitLength() const { return used_digits_ + exponent_; }
+ int BigitLength() const {
+ return used_digits_ + exponent_;
+ }
Chunk BigitAt(int index) const;
void SubtractTimes(const Bignum& other, int factor);
diff --git a/util/double-conversion/cached-powers.h b/util/double-conversion/cached-powers.h
index 61a50614c..3daf52d51 100644
--- a/util/double-conversion/cached-powers.h
+++ b/util/double-conversion/cached-powers.h
@@ -30,10 +30,12 @@
#include "diy-fp.h"
-namespace double_conversion {
+namespace double_conversion
+{
-class PowersOfTenCache {
- public:
+class PowersOfTenCache
+{
+public:
// Not all powers of ten are cached. The decimal exponent of two neighboring
// cached numbers will differ by kDecimalExponentDistance.
@@ -45,9 +47,9 @@ class PowersOfTenCache {
// Returns a cached power-of-ten with a binary exponent in the range
// [min_exponent; max_exponent] (boundaries included).
static void GetCachedPowerForBinaryExponentRange(int min_exponent,
- int max_exponent,
- DiyFp* power,
- int* decimal_exponent);
+ int max_exponent,
+ DiyFp* power,
+ int* decimal_exponent);
// Returns a cached power of ten x ~= 10^k such that
// k <= decimal_exponent < k + kCachedPowersDecimalDistance.
@@ -55,8 +57,8 @@ class PowersOfTenCache {
// kMinDecimalExponent <= requested_exponent, and
// requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance.
static void GetCachedPowerForDecimalExponent(int requested_exponent,
- DiyFp* power,
- int* found_exponent);
+ DiyFp* power,
+ int* found_exponent);
};
} // namespace double_conversion
diff --git a/util/double-conversion/diy-fp.h b/util/double-conversion/diy-fp.h
index 9dcf8fbdb..39a6bd7dd 100644
--- a/util/double-conversion/diy-fp.h
+++ b/util/double-conversion/diy-fp.h
@@ -30,15 +30,17 @@
#include "utils.h"
-namespace double_conversion {
+namespace double_conversion
+{
// This "Do It Yourself Floating Point" class implements a floating-point number
// with a uint64 significand and an int exponent. Normalized DiyFp numbers will
// have the most significant bit of the significand set.
// Multiplication and Subtraction do not normalize their results.
// DiyFp are not designed to contain special doubles (NaN and Infinity).
-class DiyFp {
- public:
+class DiyFp
+{
+public:
static const int kSignificandSize = 64;
DiyFp() : f_(0), e_(0) {}
@@ -100,13 +102,21 @@ class DiyFp {
return result;
}
- uint64_t f() const { return f_; }
- int e() const { return e_; }
+ uint64_t f() const {
+ return f_;
+ }
+ int e() const {
+ return e_;
+ }
- void set_f(uint64_t new_value) { f_ = new_value; }
- void set_e(int new_value) { e_ = new_value; }
+ void set_f(uint64_t new_value) {
+ f_ = new_value;
+ }
+ void set_e(int new_value) {
+ e_ = new_value;
+ }
- private:
+private:
static const uint64_t kUint64MSB = UINT64_2PART_C(0x80000000, 00000000);
uint64_t f_;
diff --git a/util/double-conversion/double-conversion.h b/util/double-conversion/double-conversion.h
index 1c3387d4f..b3e51bae8 100644
--- a/util/double-conversion/double-conversion.h
+++ b/util/double-conversion/double-conversion.h
@@ -30,10 +30,12 @@
#include "utils.h"
-namespace double_conversion {
+namespace double_conversion
+{
-class DoubleToStringConverter {
- public:
+class DoubleToStringConverter
+{
+public:
// When calling ToFixed with a double > 10^kMaxFixedDigitsBeforePoint
// or a requested_digits parameter > kMaxFixedDigitsAfterPoint then the
// function returns false.
@@ -112,20 +114,20 @@ class DoubleToStringConverter {
int decimal_in_shortest_high,
int max_leading_padding_zeroes_in_precision_mode,
int max_trailing_padding_zeroes_in_precision_mode)
- : flags_(flags),
- infinity_symbol_(infinity_symbol),
- nan_symbol_(nan_symbol),
- exponent_character_(exponent_character),
- decimal_in_shortest_low_(decimal_in_shortest_low),
- decimal_in_shortest_high_(decimal_in_shortest_high),
- max_leading_padding_zeroes_in_precision_mode_(
- max_leading_padding_zeroes_in_precision_mode),
- max_trailing_padding_zeroes_in_precision_mode_(
- max_trailing_padding_zeroes_in_precision_mode) {
+ : flags_(flags),
+ infinity_symbol_(infinity_symbol),
+ nan_symbol_(nan_symbol),
+ exponent_character_(exponent_character),
+ decimal_in_shortest_low_(decimal_in_shortest_low),
+ decimal_in_shortest_high_(decimal_in_shortest_high),
+ max_leading_padding_zeroes_in_precision_mode_(
+ max_leading_padding_zeroes_in_precision_mode),
+ max_trailing_padding_zeroes_in_precision_mode_(
+ max_trailing_padding_zeroes_in_precision_mode) {
// When 'trailing zero after the point' is set, then 'trailing point'
// must be set too.
ASSERT(((flags & EMIT_TRAILING_DECIMAL_POINT) != 0) ||
- !((flags & EMIT_TRAILING_ZERO_AFTER_POINT) != 0));
+ !((flags & EMIT_TRAILING_ZERO_AFTER_POINT) != 0));
}
// Returns a converter following the EcmaScript specification.
@@ -341,7 +343,7 @@ class DoubleToStringConverter {
int* length,
int* point);
- private:
+private:
// Implementation for ToShortest and ToShortestSingle.
bool ToShortestIeeeNumber(double value,
StringBuilder* result_builder,
@@ -378,8 +380,9 @@ class DoubleToStringConverter {
};
-class StringToDoubleConverter {
- public:
+class StringToDoubleConverter
+{
+public:
// Enumeration for allowing octals and ignoring junk when converting
// strings to numbers.
enum Flags {
@@ -488,11 +491,11 @@ class StringToDoubleConverter {
double junk_string_value,
const char* infinity_symbol,
const char* nan_symbol)
- : flags_(flags),
- empty_string_value_(empty_string_value),
- junk_string_value_(junk_string_value),
- infinity_symbol_(infinity_symbol),
- nan_symbol_(nan_symbol) {
+ : flags_(flags),
+ empty_string_value_(empty_string_value),
+ junk_string_value_(junk_string_value),
+ infinity_symbol_(infinity_symbol),
+ nan_symbol_(nan_symbol) {
}
// Performs the conversion.
@@ -516,7 +519,7 @@ class StringToDoubleConverter {
processed_characters_count, false));
}
- private:
+private:
const int flags_;
const double empty_string_value_;
const double junk_string_value_;
diff --git a/util/double-conversion/fast-dtoa.h b/util/double-conversion/fast-dtoa.h
index 5f1e8eee5..184f9cade 100644
--- a/util/double-conversion/fast-dtoa.h
+++ b/util/double-conversion/fast-dtoa.h
@@ -30,7 +30,8 @@
#include "utils.h"
-namespace double_conversion {
+namespace double_conversion
+{
enum FastDtoaMode {
// Computes the shortest representation of the given input. The returned
diff --git a/util/double-conversion/fixed-dtoa.h b/util/double-conversion/fixed-dtoa.h
index 3bdd08e21..9383cb936 100644
--- a/util/double-conversion/fixed-dtoa.h
+++ b/util/double-conversion/fixed-dtoa.h
@@ -30,7 +30,8 @@
#include "utils.h"
-namespace double_conversion {
+namespace double_conversion
+{
// Produces digits necessary to print a given number with
// 'fractional_count' digits after the decimal point.
diff --git a/util/double-conversion/ieee.h b/util/double-conversion/ieee.h
index 839dc47d4..0922129d5 100644
--- a/util/double-conversion/ieee.h
+++ b/util/double-conversion/ieee.h
@@ -30,17 +30,31 @@
#include "diy-fp.h"
-namespace double_conversion {
+namespace double_conversion
+{
// We assume that doubles and uint64_t have the same endianness.
-static uint64_t double_to_uint64(double d) { return BitCast<uint64_t>(d); }
-static double uint64_to_double(uint64_t d64) { return BitCast<double>(d64); }
-static uint32_t float_to_uint32(float f) { return BitCast<uint32_t>(f); }
-static float uint32_to_float(uint32_t d32) { return BitCast<float>(d32); }
+static uint64_t double_to_uint64(double d)
+{
+ return BitCast<uint64_t>(d);
+}
+static double uint64_to_double(uint64_t d64)
+{
+ return BitCast<double>(d64);
+}
+static uint32_t float_to_uint32(float f)
+{
+ return BitCast<uint32_t>(f);
+}
+static float uint32_to_float(uint32_t d32)
+{
+ return BitCast<float>(d32);
+}
// Helper functions for doubles.
-class Double {
- public:
+class Double
+{
+public:
static const uint64_t kSignMask = UINT64_2PART_C(0x80000000, 00000000);
static const uint64_t kExponentMask = UINT64_2PART_C(0x7FF00000, 00000000);
static const uint64_t kSignificandMask = UINT64_2PART_C(0x000FFFFF, FFFFFFFF);
@@ -113,7 +127,7 @@ class Double {
uint64_t d64 = AsUint64();
int biased_e =
- static_cast<int>((d64 & kExponentMask) >> kPhysicalSignificandSize);
+ static_cast<int>((d64 & kExponentMask) >> kPhysicalSignificandSize);
return biased_e - kExponentBias;
}
@@ -143,13 +157,13 @@ class Double {
bool IsNan() const {
uint64_t d64 = AsUint64();
return ((d64 & kExponentMask) == kExponentMask) &&
- ((d64 & kSignificandMask) != 0);
+ ((d64 & kSignificandMask) != 0);
}
bool IsInfinite() const {
uint64_t d64 = AsUint64();
return ((d64 & kExponentMask) == kExponentMask) &&
- ((d64 & kSignificandMask) == 0);
+ ((d64 & kSignificandMask) == 0);
}
int Sign() const {
@@ -197,7 +211,9 @@ class Double {
return physical_significand_is_zero && (Exponent() != kDenormalExponent);
}
- double value() const { return uint64_to_double(d64_); }
+ double value() const {
+ return uint64_to_double(d64_);
+ }
// Returns the significand size for a given order of magnitude.
// If v = f*2^e with 2^p-1 <= f <= 2^p then p+e is v's order of magnitude.
@@ -221,7 +237,7 @@ class Double {
return Double(kNaN).value();
}
- private:
+private:
static const int kExponentBias = 0x3FF + kPhysicalSignificandSize;
static const int kDenormalExponent = -kExponentBias + 1;
static const int kMaxExponent = 0x7FF - kExponentBias;
@@ -254,12 +270,13 @@ class Double {
biased_exponent = static_cast<uint64_t>(exponent + kExponentBias);
}
return (significand & kSignificandMask) |
- (biased_exponent << kPhysicalSignificandSize);
+ (biased_exponent << kPhysicalSignificandSize);
}
};
-class Single {
- public:
+class Single
+{
+public:
static const uint32_t kSignMask = 0x80000000;
static const uint32_t kExponentMask = 0x7F800000;
static const uint32_t kSignificandMask = 0x007FFFFF;
@@ -289,7 +306,7 @@ class Single {
uint32_t d32 = AsUint32();
int biased_e =
- static_cast<int>((d32 & kExponentMask) >> kPhysicalSignificandSize);
+ static_cast<int>((d32 & kExponentMask) >> kPhysicalSignificandSize);
return biased_e - kExponentBias;
}
@@ -319,13 +336,13 @@ class Single {
bool IsNan() const {
uint32_t d32 = AsUint32();
return ((d32 & kExponentMask) == kExponentMask) &&
- ((d32 & kSignificandMask) != 0);
+ ((d32 & kSignificandMask) != 0);
}
bool IsInfinite() const {
uint32_t d32 = AsUint32();
return ((d32 & kExponentMask) == kExponentMask) &&
- ((d32 & kSignificandMask) == 0);
+ ((d32 & kSignificandMask) == 0);
}
int Sign() const {
@@ -373,7 +390,9 @@ class Single {
return physical_significand_is_zero && (Exponent() != kDenormalExponent);
}
- float value() const { return uint32_to_float(d32_); }
+ float value() const {
+ return uint32_to_float(d32_);
+ }
static float Infinity() {
return Single(kInfinity).value();
@@ -383,7 +402,7 @@ class Single {
return Single(kNaN).value();
}
- private:
+private:
static const int kExponentBias = 0x7F + kPhysicalSignificandSize;
static const int kDenormalExponent = -kExponentBias + 1;
static const int kMaxExponent = 0xFF - kExponentBias;
diff --git a/util/double-conversion/strtod.h b/util/double-conversion/strtod.h
index ed0293b8f..1d81078d2 100644
--- a/util/double-conversion/strtod.h
+++ b/util/double-conversion/strtod.h
@@ -30,7 +30,8 @@
#include "utils.h"
-namespace double_conversion {
+namespace double_conversion
+{
// The buffer must only contain digits in the range [0-9]. It must not
// contain a dot or a sign. It must not start with '0', and must not be empty.
diff --git a/util/double-conversion/utils.h b/util/double-conversion/utils.h
index 2bd716050..91f1e6c48 100644
--- a/util/double-conversion/utils.h
+++ b/util/double-conversion/utils.h
@@ -126,25 +126,29 @@ typedef unsigned __int64 uint64_t;
DISALLOW_COPY_AND_ASSIGN(TypeName)
#endif
-namespace double_conversion {
+namespace double_conversion
+{
static const int kCharSize = sizeof(char);
// Returns the maximum of the two parameters.
template <typename T>
-static T Max(T a, T b) {
+static T Max(T a, T b)
+{
return a < b ? b : a;
}
// Returns the minimum of the two parameters.
template <typename T>
-static T Min(T a, T b) {
+static T Min(T a, T b)
+{
return a < b ? a : b;
}
-inline int StrLength(const char* string) {
+inline int StrLength(const char* string)
+{
size_t length = strlen(string);
ASSERT(length == static_cast<size_t>(static_cast<int>(length)));
return static_cast<int>(length);
@@ -152,8 +156,9 @@ inline int StrLength(const char* string) {
// This is a simplified version of V8's Vector class.
template <typename T>
-class Vector {
- public:
+class Vector
+{
+public:
Vector() : start_(NULL), length_(0) {}
Vector(T* data, int length) : start_(data), length_(length) {
ASSERT(length == 0 || (length > 0 && data != NULL));
@@ -169,13 +174,19 @@ class Vector {
}
// Returns the length of the vector.
- int length() const { return length_; }
+ int length() const {
+ return length_;
+ }
// Returns whether or not the vector is empty.
- bool is_empty() const { return length_ == 0; }
+ bool is_empty() const {
+ return length_ == 0;
+ }
// Returns the pointer to the start of the data in the vector.
- T* start() const { return start_; }
+ T* start() const {
+ return start_;
+ }
// Access individual vector elements - checks bounds in debug mode.
T& operator[](int index) const {
@@ -183,11 +194,15 @@ class Vector {
return start_[index];
}
- T& first() { return start_[0]; }
+ T& first() {
+ return start_[0];
+ }
- T& last() { return start_[length_ - 1]; }
+ T& last() {
+ return start_[length_ - 1];
+ }
- private:
+private:
T* start_;
int length_;
};
@@ -196,14 +211,19 @@ class Vector {
// Helper class for building result strings in a character buffer. The
// purpose of the class is to use safe operations that checks the
// buffer bounds on all operations in debug mode.
-class StringBuilder {
- public:
+class StringBuilder
+{
+public:
StringBuilder(char* buffer, int size)
- : buffer_(buffer, size), position_(0) { }
+ : buffer_(buffer, size), position_(0) { }
- ~StringBuilder() { if (!is_finalized()) Finalize(); }
+ ~StringBuilder() {
+ if (!is_finalized()) Finalize();
+ }
- int size() const { return buffer_.length(); }
+ int size() const {
+ return buffer_.length();
+ }
// Get the current position in the builder.
int position() const {
@@ -212,7 +232,9 @@ class StringBuilder {
}
// Reset the position.
- void Reset() { position_ = 0; }
+ void Reset() {
+ position_ = 0;
+ }
// Add a single character to the builder. It is not allowed to add
// 0-characters; use the Finalize() method to terminate the string
@@ -262,11 +284,13 @@ class StringBuilder {
return buffer_.start();
}
- private:
+private:
Vector<char> buffer_;
int position_;
- bool is_finalized() const { return position_ < 0; }
+ bool is_finalized() const {
+ return position_ < 0;
+ }
DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder);
};
@@ -296,7 +320,8 @@ class StringBuilder {
// enough that it can no longer see that you have cast one pointer type to
// another thus avoiding the warning.
template <class Dest, class Source>
-inline Dest BitCast(const Source& source) {
+inline Dest BitCast(const Source& source)
+{
// Compile time assertion: sizeof(Dest) == sizeof(Source)
// A compile error here means your Dest and Source have different sizes.
typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1];
@@ -307,7 +332,8 @@ inline Dest BitCast(const Source& source) {
}
template <class Dest, class Source>
-inline Dest BitCast(Source* source) {
+inline Dest BitCast(Source* source)
+{
return BitCast<Dest>(reinterpret_cast<uintptr_t>(source));
}