Files
pip/libs/main/units/piunits_prefix.h
peri4 5db97ca959 version 5.4.0
remove CORS default header from PIHTTPServer
fix several docs
fix PIMathVector::dot return type
add units directory with PIUnits facility
2025-09-26 21:33:45 +03:00

96 lines
2.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*! \file piunits_prefix.h
* \ingroup Core
* \~\brief
* \~english Unit prefixes
* \~russian Префиксы единиц измерения
*/
/*
PIP - Platform Independent Primitives
Unit prefix
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIUNITS_PREFIX_H
#define PIUNITS_PREFIX_H
#include "pistring.h"
namespace PIUnits {
class PIP_EXPORT Prefix {
friend class Value;
public:
enum {
None,
Deca = 0x100, // da 10^1 10
Hecto, // h 10^2 100
Kilo, // k 10^3 1000
Mega, // M 10^6 1000000
Giga, // G 10^9 1000000000
Tera, // T 10^12 1000000000000
Peta, // P 10^15 1000000000000000
Exa, // E 10^18 1000000000000000000
Zetta, // Z 10^21 1000000000000000000000
Yotta, // Y 10^24 1000000000000000000000000
Ronna, // R 10^27 1000000000000000000000000000
Quetta, // Q 10^30 1000000000000000000000000000000
Deci = 0x200, // d 10^1 0.1
Centi, // c 10^2 0.01
Milli, // m 10^3 0.001
Micro, // μ 10^6 0.000001
Nano, // n 10^9 0.000000001
Pico, // p 10^12 0.000000000001
Femto, // f 10^15 0.000000000000001
Atto, // a 10^18 0.000000000000000001
Zepto, // z 10^21 0.000000000000000000001
Yocto, // y 10^24 0.000000000000000000000001
Ronto, // r 10^27 0.000000000000000000000000001
};
static PIString name(int prefix);
static PIString prefix(int prefix);
static double multiplier(int prefix);
private:
Prefix();
NO_COPY_CLASS(Prefix);
static Prefix & instance();
static PIString valueToString(double v, void * type_class, int type, char format = 'g', int prec = 5);
struct P {
PIString name;
PIString prefix;
int pow;
double divider;
bool non3;
};
const P getPrefix(int p) const;
const P getPrefixForValue(double v, bool use_non3, bool use_greater, bool use_smaller) const;
PIMap<int, P> prefixes;
PIMap<int, P *> prefixes_by_pow;
P def_prefix;
};
} // namespace PIUnits
#endif