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

Method format_freq

DSView/pv/view/spectrumtrace.cpp:214–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

212}
213
214QString SpectrumTrace::format_freq(double freq, unsigned precision)
215{
216 if (freq <= 0) {
217 return "0Hz";
218 } else {
219 const int order = floor(log10f(freq));
220 assert(order >= FirstSIPrefixPower);
221 assert(order <= LastSIPrefixPower);
222 const int prefix = floor((order - FirstSIPrefixPower)/ 3.0f);
223 const double divider = pow(10.0, max(prefix * 3.0 + FirstSIPrefixPower, 0.0));
224
225 /*
226 QString s;
227 QTextStream ts(&s);
228 ts.setRealNumberPrecision(precision);
229 ts << fixed << freq / divider << FreqPrefixes[prefix] << "Hz";
230 return s;
231 */
232
233 char buffer[50] = {0};
234 char format[15] = {0};
235 QString units = FreqPrefixes[prefix] + "Hz";
236 sprintf(format, "%%.%df", (int)precision);
237 sprintf(buffer, format, freq / divider);
238 strcat(buffer, units.toUtf8().data());
239 return QString(buffer);
240 }
241}
242
243bool SpectrumTrace::measure(const QPoint &p)
244{

Callers

nothing calls this directly

Calls 1

dataMethod · 0.45

Tested by

no test coverage detected