/
Alexandr_Pidkasisty
/
froma2
Обзор
Документация
Войти
/
Alexandr_Pidkasisty
/
froma2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
libsource/LongReal_module.h
226 строк
16 KB
Alexandr Pidkasisty
Скорректировал комментарии у новых операторов приведения типов
07 авг 2026, 21:35
Верифицирован
07 авг 2026, 21:35
e4d3013
Код
Авторство
О чём код?
/** ���� ���� �������� ������ ���������� ������������ ����������� ��� �������������� �������������, ����������� ������� � ������������ ������������ ������������ ����������� "Free Operation Manager 2" (���������� FROMA2). **/ /****************************************************************************************************/ /****************************************************************************************************/ /*** ***/ /*** Copyright � 2025 ����������� ��������� �������� ***/ /*** ***/ /*** ������ �������� ��������� �����, ���������� ����� ������� ������������ ����������� � ***/ /*** ������������� ������������ (����� � ����������� �����������), ������������ ������������ ***/ /*** ����������� ����������� ��� �����������, ������� �������������� ����� �� �������������, ***/ /*** �����������, ���������, �������, ����������, ���������������, ����������������� �/��� ***/ /*** ������� ����� ������������ �����������, � ����� �����, ������� ��������������� ������ ***/ /*** ����������� �����������, ��� ���������� ��������� �������: ***/ /*** ***/ /*** ��������� ���� ����������� �� ��������� ����� � ������ ������� ������ ���� �������� �� ***/ /*** ��� ����� ��� �������� ����� ������� ������������ �����������. ***/ /*** ***/ /*** ������ ����������� ����������� ��������������� ���� ���ܻ, ��� �����-���� ��������, ���� ***/ /*** ���������� ��� ���������������, ������� �������� �������� �����������, ������������ �� ***/ /*** ��� ����������� ���������� � ���������� ���������, �� �� ������������� ���. �� � ����� ***/ /*** ������ ������ ��� ��������������� �� ����� ��������������� �� �����-���� �����, �� ����� ***/ /*** ��� �� ���� �����������, � ��� �����, ��� �������� ���������, ������� ��� ���� ��������, ***/ /*** ��������� ��-�� ������������� ������������ ����������� ��� ���� �������� � ����������� ***/ /*** ������������. ***/ /*** ***/ /****************************************************************************************************/ /****************************************************************************************************/ #ifndef FROMA2_LONGREAL_H #define FROMA2_LONGREAL_H #include <iostream> // ���� � ����� �� ����� #include <fstream> // ���� � ����� � ���� #include <string> // ������ �� �������� //#include <limits> // ���������� �������� ��������������� ����� #include <sstream> // ��������� ����� ��� ������ �� �������� #include <iomanip> // std::setprecision #include <cmath> // �������������� ������� � �������� �� NaN #include "serialization_module.hpp" // ���������� ������� ������������ � �������������� using namespace std; /** ��� ��������� ����� ��������� �������� �������� ������ �� ����� ����� **/ using Stype = bool; // ��� ����� ����� (1 ��� ������������� � 0 ��� �������������) using Dtype = short int; // ��� ����� �������� ����� (������ ����� ����� ���� ���). ����������� ��� �� ������! using Etype = int; // ��� ����� ���������� /** ��������� **/ //const Etype MinEtype = numeric_limits<Etype>::min()/2+1; // ���������� ������� ��� ������������ �������� ���������� //const Etype MaxEtype = numeric_limits<Etype>::max()/2-1; // ���������� ������� ��� ������������� �������� ���������� const Etype MinEtype = -32768; // ������� ������� ��� ������������ �������� ���������� const Etype MaxEtype = 32768; // ������� ������� ��� ������������� �������� ���������� const size_t manDigits = 64; // ������������ ���������� ���� ����� ������� enum Scale{NANO=-9, MICRO=-6, MILL=-3, KILO = 3, MEGA=6, GIGA=9}; // ��� ���������� ���������� ��������� � ������ Expchange /*************************************************************************************************************************/ /** **/ /** class LongReal **/ /** **/ /*************************************************************************************************************************/ template<typename T> constexpr bool are_types_for_get_v = std::is_floating_point<T>::value || std::is_same<T, std::string>::value; class LongReal { /** ����� ��� �������� � ���������� �������������� �������� � �������� ������������� �������. **/ private: size_t NumCount; // ���������� ���� � ����� ����� ���������� ��������� ������� digits Stype sign; // ���� ����� (1 ��� ������������� � 0 ��� �������������) Dtype* digits; // ��������� �� ������������ ������ ���� ������� NumCount ��� �������� �������� ����� Etype exponent; // ���������� ����� /** ������ ����� �������������� � ���� sign * 0.d1d2...dn * 10^exponent **/ inline void setzero(); // ���� ����� ���� inline void setposinf(); // ���� ������������� ������������� inline void setneginf(); // ���� ������������� ������������� inline void setNaN(); // ���� �������� NaN void normalize(); // ������������ ����� inline Dtype* cut(const Dtype _digits[], size_t Num); // ���������� ���������� ����� ��������� ������� inline void Resize(const size_t _n); // ��������� ����������� ������� �� ����������� ������� void init(const string& s); // ������������� ����� �� ������ stringstream getstream() const; // ����� ��������� ����� � ����� stringstream inline bool ovrflw(const Etype& E1, const Etype& E2) const; // �������� ������������ LongReal incrE(const Etype& _E) const; // ������ ���������� ��� ��������� ����� void incrD(const size_t& _N); // ����������� ����� ������� digits �� �������� _N �� ���� ������ ����� inline LongReal _round(const size_t) const; // ���������� ����� ���� LongReal � ����������� �� _n ��������; // �������� � �������� �� _n+1 �� NumCount �� �������� public: /** ������������, ����������, ����� ������ **/ LongReal(); // ����������� ��-��������� LongReal(const string& value); // ����������� � �������������� ����� �� ������ LongReal(const double& value); // ����������� � �������������� ����� �� ����� ���� double LongReal(const LongReal& obj); // ����������� ����������� LongReal(LongReal&& obj); // ����������� ����������� LongReal(Stype _sign, size_t _NumCount, Dtype* &_digits, Etype _exp); // ����������� ������� �������� ����� ~LongReal(); // ���������� void swap(LongReal& obj) noexcept; // ������� ������ ���������� ����� ��������� /** ���������� ���������� ������������ **/ LongReal& operator=(const LongReal &obj); // ���������� ��������� ������������ ������������ ������� LongReal LongReal& operator=(const double &value); // ���������� ��������� ������������ ������������ ������� double LongReal& operator=(const string &value); // ���������� ��������� ������������ ������������ ������� string LongReal& operator=(LongReal &&obj); // ���������� ��������� ������������ ������������ /** ������ Get **/ size_t Size() const; // ����� ���������� ������ ������� � ������ template<typename T, class=std::enable_if_t<are_types_for_get_v<T>>> T Get() const; // ���������� ����� � ����� string, long double, double ��� float string Get(size_t _n) const; // ���������� ����� � ����� string � �������� ����������� ������ ����� ����� string EGet(size_t n) const; // ���������� ����� � ����� string � ���� .ddddEn (�������� �� ��������) /** ��������� �������������� �����. ��� ������������ ���������� ����������� ������������ ����� �������� ���� LongReal. ��������� explicit ��� �������������� ������� (��������������) �������������� ����� **/ explicit operator long double() const; // �������� ������������ ���������� ���� long double explicit operator double() const; // �������� ������������ ���������� ���� double explicit operator float() const; // �������� ������������ ���������� ���� float /** ������ ��������������� ����� � ����-, ����-, �����-, �����- � �.�. ����� **/ LongReal& Expchange(const Etype _exch); // ����� �������� ���������� ����� /** ���������� ���������� � �������������� ���������� **/ bool isZero() const; // ����� ���������� true, ���� ����� ����� +/-���� bool isposInf() const; // ����� ���������� true, ���� ����� ����� Inf bool isnegInf() const; // ����� ���������� true, ���� ����� ����� -Inf bool isNaN() const; // �������� ����� �� NaN (����������������) bool operator==(const LongReal& x) const; // �������� ��������� ����� bool operator!=(const LongReal& x) const; // �������� ��������� �� ����� LongReal operator*(const LongReal& x) const; // �������� ��������� LongReal operator-() const; // ������� ����� bool operator>(const LongReal& x) const; // �������� ������ bool operator<(const LongReal& x) const; // �������� ������ bool operator>=(const LongReal& x) const; // �������� ������ ��� ����� bool operator<=(const LongReal& x) const; // �������� ������ ��� ����� LongReal operator+(const LongReal& x) const; // �������� �������� LongReal operator-(const LongReal& x) const; // �������� ��������� LongReal& operator-=(const LongReal& x); // �������� ���������� �� �������� x LongReal& operator+=(const LongReal& x); // �������� ���������� �� �������� x LongReal inverse() const; // ���������� ��������� ����� (1/x) LongReal operator/(const LongReal& x) const; // ���������� ��������� ������� friend LongReal fabs(const LongReal& x); // ������ ����� �� ������ /** ���������� ���������� ����� � ������ **/ friend ostream& operator<<(ostream& os, const LongReal& value); // ����� ����� � ����� ostream ��� double friend stringstream& operator>>(stringstream& ss, LongReal& value); // ���� ����� �� ������ stringstream friend istream& operator>>(istream& is, LongReal& value); // ���� ����� �� ������ istream /** ������ ������������ � �������������� **/ bool StF(ofstream &_outF) const; // ������ ���������� ������ � �������� ���������� bool RfF(ifstream &_inF); // ������ �� �������� ���������� � ��������� ������ bool SaveToFile(const string _filename) const; // ������ ���������� ������ � ���� bool ReadFromFile(const string _filename); // ������ �� ����� � ��������� ������ friend bool SEF(ofstream &_outF, LongReal& x); // ���������� ������� SEF friend bool SEF(ofstream &_outF, LongReal x[], size_t Cnt); // ���������� ������� SEF friend bool DSF(ifstream &_inF, LongReal& x); // ���������� ������� DSF friend bool DSF(ifstream &_inF, LongReal x[], size_t Cnt); // ���������� ������� DSF /** ������ ����������� �������� **/ void View(ostream& os) const; // ����� ����������� �������� ����� � �������������� ������� ������� void ViewM(ostream& os) const; // ����� ����������� �������� ����� � ������������ ������� ������� protected: }; // LongReal /*************************************************************************************************************************/ /** **/ /** class lrstream **/ /** **/ /*************************************************************************************************************************/ template<typename T> constexpr bool are_types_for_lrstream_v = std::is_floating_point<T>::value || std::is_same<std::remove_const_t<std::remove_pointer_t<T>>, char>::value || std::is_same<std::remove_const_t<T>, size_t>::value; /** ������� ������������ �����: float, double, long double, char, char*, const char, const char*, size_t, const size_t. ��� ����, ��������� ����� ���� ��� lvalue, ��� � rvalue. (https://cplusplus.com/reference/type_traits) **/ struct lrstream { /** ���, ����������� "�����������" ��� ������ � ����� ���� ostream ����� ���� LongReal, float, double ��� long double � ����� � ��� �� �������������. ����������� ������������ ���������� ������ ����� ������� � ������������ ����� ��������� �����. ����� ����������� � �������, ��� ������������ ��������� decimal, ��� ���� ����������� ����� ������������ ��� ���� ��������� �����. ������������ ������� ������� � ���, ��� �� ��������� ������������� ����������� ����� LongReal � double � ������������ ������ ����������� ��� ����� �����. **/ ostream *pos = &cout; // ����� ��� ��������� ������ ����� � �������� const size_t N; // ���������� ������ ����� ������� � ������������ ����� lrstream(const size_t w); // ����������� lrstream& operator<<(const LongReal& val); // �������� ������ � ����� lrstream ������������ ����� ���� LongReal lrstream& operator<<(const string& val); // �������� ������ � ����� lrstream ����� std::string template<typename T, class=std::enable_if_t<are_types_for_lrstream_v<T>>> lrstream& operator<<(T val); // �������� ������ � ����� lrstream ������������ ������� ���������� ����� ostream& operator<<(ostream&(*f)(ostream&));/** �������� ����� � ����� ������������ ��� ������ �� ������ lrstream � ����� ostream. � �������� ��������� ����� �������������� ������� lr_exit ��� ����������� ������������ std::endl, std::flush � ������ output-������������ �� ������������� ����� <ostream> (https://en.cppreference.com/w/cpp/io/manip.html) **/ }; // struct lrstream lrstream lr_precision(const size_t w); /** ����������� ��� ����� ���� LongReal, float, double � long double. ������������� ���������� ��������� ������ ����� �������. **/ lrstream operator <<(ostream& os, lrstream&& m); /** �������� ����� ������� ���� lrstream � ����� ostream. ��������� ��������� ����� ostream ������� lrstream � ��������� � ����� lrstream ����������� ������. **/ lrstream operator <<(lrstream& los, lrstream&& m); /** �������� ����� ������ ������� ���� lrstream � ����� lrstream. ��������� ��������� ������� ����� �� ������ ��������� ����� �������� ����� ������� � ����� ��������� ����� �������� **/ ostream& lr_exit(ostream&); /** ����������� ��� ������ �� ������ lrstream � ����������� � ����� ostream. ������ ������������ lr_exit ����� �������������� ������������ std::endl, std::flush � ������ output-������������ �� ������������� ����� <ostream> (https://en.cppreference.com/w/cpp/io/manip.html)**/ #endif // FROMA2_LONGREAL_H