aboutsummaryrefslogtreecommitdiffstats
path: root/util/string
diff options
context:
space:
mode:
authorEvgeny Grechnikov <diamondaz@yandex.ru>2022-02-10 16:46:20 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:20 +0300
commitc73494e681a4e497ae191ada07a55a6bf55885ff (patch)
tree1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/string
parent6e38f52f898d7c077ddd319800b4014967a5ca76 (diff)
downloadydb-c73494e681a4e497ae191ada07a55a6bf55885ff.tar.gz
Restoring authorship annotation for Evgeny Grechnikov <diamondaz@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'util/string')
-rw-r--r--util/string/cast.h20
-rw-r--r--util/string/cast_ut.cpp8
2 files changed, 14 insertions, 14 deletions
diff --git a/util/string/cast.h b/util/string/cast.h
index f5ef2aa184..90e925c194 100644
--- a/util/string/cast.h
+++ b/util/string/cast.h
@@ -29,7 +29,7 @@ inline size_t ToString(const T& t, char* buf, size_t len) {
/**
* Floating point to string conversion mode, values are enforced by `dtoa_impl.cpp`.
*/
-enum EFloatToStringMode {
+enum EFloatToStringMode {
/** 0.1f -> "0.1", 0.12345678f -> "0.12345678", ignores ndigits. */
PREC_AUTO = 0,
@@ -44,18 +44,18 @@ enum EFloatToStringMode {
/** same as PREC_POINT_DIGITS, but stripping trailing zeroes:
* 0.1f for ndgigits=6 -> "0.1" */
PREC_POINT_DIGITS_STRIP_ZEROES = 4
-};
-
-size_t FloatToString(float t, char* buf, size_t len, EFloatToStringMode mode = PREC_AUTO, int ndigits = 0);
-size_t FloatToString(double t, char* buf, size_t len, EFloatToStringMode mode = PREC_AUTO, int ndigits = 0);
-
+};
+
+size_t FloatToString(float t, char* buf, size_t len, EFloatToStringMode mode = PREC_AUTO, int ndigits = 0);
+size_t FloatToString(double t, char* buf, size_t len, EFloatToStringMode mode = PREC_AUTO, int ndigits = 0);
+
template <typename T>
inline TString FloatToString(const T& t, EFloatToStringMode mode = PREC_AUTO, int ndigits = 0) {
- char buf[512]; // Max<double>() with mode = PREC_POINT_DIGITS has 309 digits before the decimal point
- size_t count = FloatToString(t, buf, sizeof(buf), mode, ndigits);
+ char buf[512]; // Max<double>() with mode = PREC_POINT_DIGITS has 309 digits before the decimal point
+ size_t count = FloatToString(t, buf, sizeof(buf), mode, ndigits);
return TString(buf, count);
-}
-
+}
+
namespace NPrivate {
template <class T, bool isSimple>
struct TToString {
diff --git a/util/string/cast_ut.cpp b/util/string/cast_ut.cpp
index 44905181b9..033450c38c 100644
--- a/util/string/cast_ut.cpp
+++ b/util/string/cast_ut.cpp
@@ -253,11 +253,11 @@ Y_UNIT_TEST_SUITE(TCastTest) {
}
Y_UNIT_TEST(TestFloats) {
- // "%g" mode
+ // "%g" mode
UNIT_ASSERT_VALUES_EQUAL(FloatToString(0.1f, PREC_NDIGITS, 6), "0.1"); // drop trailing zeroes
UNIT_ASSERT_VALUES_EQUAL(FloatToString(0.12345678f, PREC_NDIGITS, 6), "0.123457");
UNIT_ASSERT_VALUES_EQUAL(FloatToString(1e-20f, PREC_NDIGITS, 6), "1e-20");
- // "%f" mode
+ // "%f" mode
UNIT_ASSERT_VALUES_EQUAL(FloatToString(0.1f, PREC_POINT_DIGITS, 6), "0.100000");
UNIT_ASSERT_VALUES_EQUAL(FloatToString(0.12345678f, PREC_POINT_DIGITS, 6), "0.123457");
UNIT_ASSERT_VALUES_EQUAL(FloatToString(1e-20f, PREC_POINT_DIGITS, 6), "0.000000");
@@ -268,13 +268,13 @@ Y_UNIT_TEST_SUITE(TCastTest) {
UNIT_ASSERT_VALUES_EQUAL(FloatToString(1e-20f, PREC_POINT_DIGITS_STRIP_ZEROES, 6), "0");
UNIT_ASSERT_VALUES_EQUAL(FloatToString(12.34f, PREC_POINT_DIGITS_STRIP_ZEROES, 0), "12"); // rounding to integers drops '.'
UNIT_ASSERT_VALUES_EQUAL(FloatToString(10000.0f, PREC_POINT_DIGITS_STRIP_ZEROES, 0), "10000");
- // automatic selection of ndigits
+ // automatic selection of ndigits
UNIT_ASSERT_VALUES_EQUAL(FloatToString(0.1f), "0.1"); // drop trailing zeroes
UNIT_ASSERT_VALUES_EQUAL(FloatToString(0.12345678f), "0.12345678"); // 8 valid digits
UNIT_ASSERT_VALUES_EQUAL(FloatToString(1000.00006f), "1000.00006"); // 9 valid digits
UNIT_ASSERT_VALUES_EQUAL(FloatToString(1e-45f), "1e-45"); // denormalized: 1 valid digit
UNIT_ASSERT_VALUES_EQUAL(FloatToString(-0.0f), "-0"); // sign must be preserved
- // version for double
+ // version for double
UNIT_ASSERT_VALUES_EQUAL(FloatToString(1.0 / 10000), "0.0001"); // trailing zeroes
UNIT_ASSERT_VALUES_EQUAL(FloatToString(1.2345678901234567), "1.2345678901234567"); // no truncation
UNIT_ASSERT_VALUES_EQUAL(FloatToString(5e-324), "5e-324"); // denormalized