Browse Source

lround() missing in MSVC

lround() is missing in MS Visual-C's <math.h>. Not available anywhere.
Here is an easy patch.
Gisle Vanem 12 years ago
parent
commit
5939c09d35
2 changed files with 8 additions and 0 deletions
  1. 4 0
      changes/msvc_lround
  2. 4 0
      src/common/util.c

+ 4 - 0
changes/msvc_lround

@@ -0,0 +1,4 @@
+  o Build fixes:
+    - Provide a substitute implementation of lround() for MSVC, which
+      apparently lacks it.  Patch from Gisle Vanem.
+      

+ 4 - 0
src/common/util.c

@@ -334,7 +334,11 @@ tor_mathlog(double d)
 long
 tor_lround(double d)
 {
+#ifdef _MSC_VER
+  return (long)(d > 0 ? d + 0.5 : ceil(d - 0.5));
+#else
   return lround(d);
+#endif
 }
 
 /** Returns floor(log2(u64)).  If u64 is 0, (incorrectly) returns 0. */