[tor-commits] [tor/master] Rename cast_double_to_int64 to clamp_double_to_int64

nickm at torproject.org nickm at torproject.org
Thu Nov 12 16:42:29 UTC 2015


commit 1f7ba115a46743ea09402a30a7b11e4b6d2ee52e
Author: Nick Mathewson <nickm at torproject.org>
Date:   Thu Jul 9 16:54:17 2015 -0400

    Rename cast_double_to_int64 to clamp_double_to_int64
---
 src/common/util.c    |    4 ++--
 src/common/util.h    |    2 +-
 src/test/test_util.c |   40 ++++++++++++++++++++--------------------
 3 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/src/common/util.c b/src/common/util.c
index 63bd1cc..f642c6a 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -565,7 +565,7 @@ sample_laplace_distribution(double mu, double b, double p)
   result = mu - b * (p > 0.5 ? 1.0 : -1.0)
                   * tor_mathlog(1.0 - 2.0 * fabs(p - 0.5));
 
-  return cast_double_to_int64(result);
+  return clamp_double_to_int64(result);
 }
 
 /** Add random noise between INT64_MIN and INT64_MAX coming from a Laplace
@@ -5509,7 +5509,7 @@ tor_weak_random_range(tor_weak_rng_t *rng, int32_t top)
 /** Cast a given double value to a int64_t. Return 0 if number is NaN.
  * Returns either INT64_MIN or INT64_MAX if number is outside of the int64_t
  * range. */
-int64_t cast_double_to_int64(double number)
+int64_t clamp_double_to_int64(double number)
 {
   int exp;
 
diff --git a/src/common/util.h b/src/common/util.h
index e303da2..8e18e05 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -185,7 +185,7 @@ int64_t sample_laplace_distribution(double mu, double b, double p);
 int64_t add_laplace_noise(int64_t signal, double random, double delta_f,
                           double epsilon);
 int n_bits_set_u8(uint8_t v);
-int64_t cast_double_to_int64(double number);
+int64_t clamp_double_to_int64(double number);
 
 /* Compute the CEIL of <b>a</b> divided by <b>b</b>, for nonnegative <b>a</b>
  * and positive <b>b</b>.  Works on integer types only. Not defined if a+b can
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 8ae5bb3..f96a362 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -4238,36 +4238,36 @@ test_util_laplace(void *arg)
 }
 
 static void
-test_util_cast_double_to_int64(void *arg)
+test_util_clamp_double_to_int64(void *arg)
 {
   (void)arg;
 
-  tt_i64_op(INT64_MIN, ==, cast_double_to_int64(-INFINITY));
+  tt_i64_op(INT64_MIN, ==, clamp_double_to_int64(-INFINITY));
   tt_i64_op(INT64_MIN, ==,
-            cast_double_to_int64(-1.0 * pow(2.0, 64.0) - 1.0));
+            clamp_double_to_int64(-1.0 * pow(2.0, 64.0) - 1.0));
   tt_i64_op(INT64_MIN, ==,
-            cast_double_to_int64(-1.0 * pow(2.0, 63.0) - 1.0));
+            clamp_double_to_int64(-1.0 * pow(2.0, 63.0) - 1.0));
   tt_i64_op(((uint64_t) -1) << 53, ==,
-            cast_double_to_int64(-1.0 * pow(2.0, 53.0)));
+            clamp_double_to_int64(-1.0 * pow(2.0, 53.0)));
   tt_i64_op((((uint64_t) -1) << 53) + 1, ==,
-            cast_double_to_int64(-1.0 * pow(2.0, 53.0) + 1.0));
-  tt_i64_op(-1, ==, cast_double_to_int64(-1.0));
-  tt_i64_op(0, ==, cast_double_to_int64(-0.9));
-  tt_i64_op(0, ==, cast_double_to_int64(-0.1));
-  tt_i64_op(0, ==, cast_double_to_int64(0.0));
-  tt_i64_op(0, ==, cast_double_to_int64(NAN));
-  tt_i64_op(0, ==, cast_double_to_int64(0.1));
-  tt_i64_op(0, ==, cast_double_to_int64(0.9));
-  tt_i64_op(1, ==, cast_double_to_int64(1.0));
+            clamp_double_to_int64(-1.0 * pow(2.0, 53.0) + 1.0));
+  tt_i64_op(-1, ==, clamp_double_to_int64(-1.0));
+  tt_i64_op(0, ==, clamp_double_to_int64(-0.9));
+  tt_i64_op(0, ==, clamp_double_to_int64(-0.1));
+  tt_i64_op(0, ==, clamp_double_to_int64(0.0));
+  tt_i64_op(0, ==, clamp_double_to_int64(NAN));
+  tt_i64_op(0, ==, clamp_double_to_int64(0.1));
+  tt_i64_op(0, ==, clamp_double_to_int64(0.9));
+  tt_i64_op(1, ==, clamp_double_to_int64(1.0));
   tt_i64_op((((int64_t) 1) << 53) - 1, ==,
-            cast_double_to_int64(pow(2.0, 53.0) - 1.0));
+            clamp_double_to_int64(pow(2.0, 53.0) - 1.0));
   tt_i64_op(((int64_t) 1) << 53, ==,
-            cast_double_to_int64(pow(2.0, 53.0)));
+            clamp_double_to_int64(pow(2.0, 53.0)));
   tt_i64_op(INT64_MAX, ==,
-            cast_double_to_int64(pow(2.0, 63.0)));
+            clamp_double_to_int64(pow(2.0, 63.0)));
   tt_i64_op(INT64_MAX, ==,
-            cast_double_to_int64(pow(2.0, 64.0)));
-  tt_i64_op(INT64_MAX, ==, cast_double_to_int64(INFINITY));
+            clamp_double_to_int64(pow(2.0, 64.0)));
+  tt_i64_op(INT64_MAX, ==, clamp_double_to_int64(INFINITY));
 
  done:
   ;
@@ -4490,7 +4490,7 @@ struct testcase_t util_tests[] = {
   UTIL_LEGACY(di_ops),
   UTIL_TEST(round_to_next_multiple_of, 0),
   UTIL_TEST(laplace, 0),
-  UTIL_TEST(cast_double_to_int64, 0),
+  UTIL_TEST(clamp_double_to_int64, 0),
   UTIL_TEST(find_str_at_start_of_line, 0),
   UTIL_TEST(string_is_C_identifier, 0),
   UTIL_TEST(asprintf, 0),





More information about the tor-commits mailing list