MCPcopy Create free account
hub / github.com/KAlO2/PerfectShow / GetPrintMatFormat

Function GetPrintMatFormat

jni/stasm/misc.cpp:226–251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

224}
225
226static void GetPrintMatFormat(
227 char* format, // out: will be something like %3.2f
228 const MAT& mat) // in
229{
230 // get max elem and if any elems are negative so we can format nicely
231 double max = -1;
232 bool neg = false;
233 bool frac = false;
234 for (int row = 0; row < mat.rows; row++)
235 for (int col = 0; col < mat.cols; col++)
236 {
237 const double elem = mat(row, col);
238 if (ABS(elem) > max)
239 max = ABS(elem);
240 if (elem < 0)
241 neg = true;
242 if (elem != floor(elem))
243 frac = true;
244 }
245
246 if (max >= 1e5)
247 frac = false; // no decimal digit if enough sig digits to left of decimal
248 const int ndigits = NumDigits(max);
249 sprintf(format, "%%%s%d.%s",
250 neg? " ": "", ndigits+neg+(frac? 2: 0)+1, frac? "2f": "0f");
251}
252
253void PrintMat( // utility to print a matrix
254 const MAT& mat, // in

Callers 1

PrintMatFunction · 0.85

Calls 2

ABSFunction · 0.85
NumDigitsFunction · 0.85

Tested by

no test coverage detected