[mlpack-svn] r11840 - mlpack/trunk/src/mlpack/core/math

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Mar 12 17:40:25 EDT 2012


Author: rcurtin
Date: 2012-03-12 17:40:25 -0400 (Mon, 12 Mar 2012)
New Revision: 11840

Added:
   mlpack/trunk/src/mlpack/core/math/round.hpp
Modified:
   mlpack/trunk/src/mlpack/core/math/CMakeLists.txt
Log:
Implementation of round() for C99-deficient compilers (MSVC...).


Modified: mlpack/trunk/src/mlpack/core/math/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/core/math/CMakeLists.txt	2012-03-12 21:07:58 UTC (rev 11839)
+++ mlpack/trunk/src/mlpack/core/math/CMakeLists.txt	2012-03-12 21:40:25 UTC (rev 11840)
@@ -9,6 +9,7 @@
   random.cpp
   range.hpp
   range_impl.hpp
+  round.hpp
 )
 
 # add directory name to sources

Added: mlpack/trunk/src/mlpack/core/math/round.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/math/round.hpp	                        (rev 0)
+++ mlpack/trunk/src/mlpack/core/math/round.hpp	2012-03-12 21:40:25 UTC (rev 11840)
@@ -0,0 +1,26 @@
+/**
+ * @file round.hpp
+ * @author Ryan Curtin
+ *
+ * Implementation of round() for use on Visual Studio, where C99 isn't
+ * implemented.
+ */
+#ifndef __MLPACK_CORE_MATH_ROUND_HPP
+#define __MLPACK_CORE_MATH_ROUND_HPP
+
+// _MSC_VER should only be defined for Visual Studio, which doesn't implement
+// C99.
+#ifdef _MSC_VER
+
+// This function ends up going into the global namespace, so it can be used in
+// place of C99's round().
+
+//! Round a number to the nearest integer.
+inline double round(double a)
+{
+  return floor(a + 0.5);
+}
+
+#endif
+
+#endif




More information about the mlpack-svn mailing list