MCPcopy Create free account
hub / github.com/DreamSourceLab/DSView / format_freq

Method format_freq

DSView/pv/view/ruler.cpp:116–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116QString Ruler::format_freq(double period, unsigned int precision)
117{
118 if (period <= 0) {
119 return View::Unknown_Str;
120 } else {
121 const int order = ceil(log10f(period));
122 assert(order >= FirstSIPrefixPower);
123 const int prefix = ceil((order - FirstSIPrefixPower) / 3.0f);
124 const double multiplier = pow(10.0, max(-prefix * 3.0 - FirstSIPrefixPower, 0.0));
125
126 /*
127 QString s;
128 QTextStream ts(&s);
129 ts.setRealNumberPrecision(precision);
130 ts << fixed << 1 / (period * multiplier) <<
131 FreqPrefixes[prefix] << "Hz";
132 return s;
133 */
134
135 char buffer[50] = {0};
136 char format[15] = {0};
137 QString units = FreqPrefixes[prefix] + "Hz";
138 sprintf(format, "%%.%df", (int)precision);
139 sprintf(buffer, format, 1 / (period * multiplier));
140 strcat(buffer, units.toUtf8().data());
141 return QString(buffer);
142 }
143}
144
145QString Ruler::format_time(double t, int prefix,
146 unsigned int precision)

Callers

nothing calls this directly

Calls 1

dataMethod · 0.45

Tested by

no test coverage detected