|
@@ -6,6 +6,7 @@
|
|
|
* See file License for license information.
|
|
|
*/
|
|
|
|
|
|
+// STL includes
|
|
|
#include <cmath>
|
|
|
#include <math.h>
|
|
|
#include <stdlib.h>
|
|
@@ -401,10 +402,21 @@ inline long stringToInt(std::string s) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Convert an integer into a string.
|
|
|
+ * @brief Convert an integer into a string
|
|
|
*/
|
|
|
std::string intToString(const int i);
|
|
|
|
|
|
+/**
|
|
|
+ * @brief Convert an integer into a string of fixed length, add leading zeros if needed.
|
|
|
+ * @author Alxander Freytag
|
|
|
+ * @date 13-01-2014 (dd-mm-yyyy)
|
|
|
+ *
|
|
|
+ * @param i - number to convert
|
|
|
+ * @param length - resulting length of string including leading zeros
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+std::string intToString(const int i, const uint & length);
|
|
|
+
|
|
|
/**
|
|
|
* Convert a double into a string.
|
|
|
*/
|
|
@@ -425,6 +437,31 @@ inline int roundInt(float d) {
|
|
|
return int(roundf(d));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief Compute number of digits (including sign) of a given number w.r.t. a specified base (ONLY USEFUL FOR INT-LIKE VARIABLES)
|
|
|
+ * @author Alexander Freytag
|
|
|
+ * @date 13-01-2014 (dd-mm-yyyy)
|
|
|
+ *
|
|
|
+ * @param number
|
|
|
+ * @param base ( default is 10).
|
|
|
+ * @return int
|
|
|
+ **/
|
|
|
+template <class T>
|
|
|
+int getNumDigits(T number, T base = 10 )
|
|
|
+{
|
|
|
+ int digits ( 0 );
|
|
|
+
|
|
|
+ // note: only possible, because we call it using call-by-value!
|
|
|
+ while ( number )
|
|
|
+ {
|
|
|
+ number /= base;
|
|
|
+ digits++;
|
|
|
+ }
|
|
|
+
|
|
|
+ return digits;
|
|
|
+}
|
|
|
+
|
|
|
} // namespace
|
|
|
|
|
|
#endif // _NUMERICTOOLS_FBASICS_H
|