1 /*
2  *  Copyright (C) 2016, Mike Walters <mike@flomp.net>
3  *
4  *  This file is part of inspectrum.
5  *
6  *  This program is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "util.h"
21 
formatSIValue(float value)22 std::string formatSIValue(float value)
23 {
24     std::map<int, std::string> prefixes = {
25         {  9,   "G" },
26         {  6,   "M" },
27         {  3,   "k" },
28         {  0,   ""  },
29         { -3,   "m" },
30         { -6,   "µ" },
31         { -9,   "n" },
32     };
33 
34     int power = 0;
35     while (value < 1.0f && power > -9) {
36         value *= 1e3;
37         power -= 3;
38     }
39     while (value >= 1e3 && power < 9) {
40         value *= 1e-3;
41         power += 3;
42     }
43     std::stringstream ss;
44     ss << value << prefixes[power];
45     return ss.str();
46 }
47 
getFileNameFilter()48 template<> const char* getFileNameFilter<std::complex<float>>() { return "complex<float> file (*.fc32)"; };
getFileNameFilter()49 template<> const char* getFileNameFilter<float>() { return "float file (*.f32)"; };
50