~vbursian/research-assistant/intervers

« back to all changes in this revision

Viewing changes to RANet/PhysValue.h

  • Committer: Viktor Bursian
  • Date: 2013-06-06 15:10:08 UTC
  • Revision ID: vbursian@gmail.com-20130606151008-6641eh62f0lgx8jt
Tags: version_0.3.0
version 0.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
//------------------------------------------------------------------------------
13
13
 
14
14
ANNOUNCE_CLASS(sPhysValue)
15
 
ANNOUNCE_CLASS(xRealAlgebra)
 
15
ANNOUNCE_CLASS(xRAlgebra)
16
16
 
17
17
//--------------------------------------------------------------- sPhysValue ---
18
18
 
19
19
 
20
 
class RANet_EXPORT  sPhysValue : public sStorable /*! @todo{VB_?_RAlgebra} virtual?*/
 
20
class RANet_EXPORT  sPhysValue : public virtual sStorable /*! @todo{PhysValues} virtual?*/
21
21
{
22
22
  STORABLE(sPhysValue)
23
 
  public:
24
 
    static const int          MaxDigits = 8;
 
23
 
 
24
  public://static
 
25
    static unsigned short int MaxDigits;
 
26
    static unsigned short int DraftNormalization; //always
 
27
    static unsigned short int BriefNormalization; //for Text()
 
28
    static unsigned short int SmartNormalization; //for editing
25
29
 
26
30
  public:
27
31
                              sPhysValue ();
28
 
                              sPhysValue (sUnits  U);
 
32
    explicit                  sPhysValue (rcsUnits  U);
29
33
                              sPhysValue (real V ,rcsUnits  U);
30
34
                              sPhysValue (real V ,real E ,rcsUnits  U);
31
35
    explicit                  sPhysValue (real V);
32
36
                              sPhysValue (real V ,real E);
33
 
                              sPhysValue (sString  UnitsStr);
 
37
    explicit                  sPhysValue (sString  UnitsStr);
 
38
                              sPhysValue (real V ,sString  UnitsStr);
 
39
                              sPhysValue (real V ,real E ,sString  UnitsStr);
34
40
                              sPhysValue (rcsPhysValue  R);
35
 
    rsPhysValue               operator = (sPhysValue);
36
 
 
37
 
/*! @todo{VB_!_RAlgebra} хреново это, надо вызывать operator=(sPhysValue(V))*/
38
 
//    rsPhysValue               operator = (real);
39
 
 
40
 
                              /*! @todo{VB_!_RAlgebra} изничтожить? оставить только для безразмерных?*/
41
 
//                              operator real () const
42
 
//                                { return TheValueMantissa*power10(TheOrder); };
43
41
 
44
42
  public:
 
43
//    bool                      IsUnitsless () const;
45
44
    bool                      UnitsAreFixed () const
46
45
                                { return UnitsAreFixedFlag; };
47
 
    real                      Value () const
 
46
    void                      FixTheUnits ()
 
47
                                { UnitsAreFixedFlag = true; };
 
48
    sUnits                    Units () const
 
49
                                { return TheUnits; };
 
50
    bool                      IsInf () const
 
51
                                { return isinf(TheValueMantissa); };
 
52
    bool                      IsNaN () const
 
53
                                { return isnan(TheValueMantissa); };
 
54
    bool                      IsPowerOfTen () const
 
55
                                { return ThePowerOfTenFlag; };
 
56
    sPhysValue                Error () const
 
57
                                { return sPhysValue(ArbError(),Units()); };
 
58
    void                      SetError (rcsPhysValue  error);
 
59
    real                      ArbValue () const
48
60
                                { return TheValueMantissa*power10(TheOrder); };
49
 
    real                      ValueMantissa () const
 
61
    sString                   Text (eTextFormat        F=Plain
 
62
                                   ,eTextDetalization  D=Casual);
 
63
                                //!< visual representation for user
 
64
                                //!< (may have side effect - normalization)
 
65
    sString                   Text (eTextFormat        F=Plain
 
66
                                   ,eTextDetalization  D=Casual) const;
 
67
                                //!< visual representation for user
 
68
    void                      Normalize ()
 
69
                                { Normalize(SmartNormalization); };
 
70
 
 
71
  public://operators
 
72
    rsPhysValue               operator = (rcsPhysValue);
 
73
//    bool                      operator == (rcsPhysValue) const;
 
74
    bool                      operator < (rcsPhysValue) const;
 
75
    sPhysValue                operator + () const;
 
76
    sPhysValue                operator - () const;
 
77
    sPhysValue                operator + (rcsPhysValue) const;
 
78
    sPhysValue                operator - (rcsPhysValue) const;
 
79
    sPhysValue                operator * (rcsPhysValue) const;
 
80
    sPhysValue                operator / (rcsPhysValue) const;
 
81
    sPhysValue                operator * (real  r) const
 
82
                                { return (*this) * sPhysValue(r); };
 
83
    sPhysValue                operator / (real  r) const
 
84
                                { return (*this) / sPhysValue(r); };
 
85
    rsPhysValue               operator += (rcsPhysValue);
 
86
    rsPhysValue               operator -= (rcsPhysValue);
 
87
    rsPhysValue               operator *= (real);
 
88
    rsPhysValue               operator /= (real);
 
89
    rsPhysValue               operator << (int  order_shift);
 
90
 
 
91
  public://but for internal needs in RANet and RAGUI
 
92
    real                      ArbError () const
 
93
                                { return TheErrorMantissa*power10(TheOrder); };
 
94
    real                      ArbValueMantissa () const
50
95
                                { return TheValueMantissa; };
51
 
    real                      ErrorMantissa () const
 
96
    real                      ArbErrorMantissa () const
52
97
                                { return TheErrorMantissa; };
53
98
    int                       Order () const
54
99
                                { return TheOrder; };
55
 
//    void                      SetError (real);
56
 
    sUnits                    Units () const
57
 
                                { return TheUnits; };
58
100
    unsigned short int        Digits () const
59
101
                                { return TheDigits; };
60
102
                                //!< число цифр после запятой при выводе,
61
103
                                //!  актуальное с учётом погрешности
62
104
 
63
 
    sString                   Text (eTextFormat        F=Plain
64
 
                                   ,eTextDetalization  D=Casual) const;
65
 
                                //!< visual representation for user
66
 
 
67
 
  public:
68
 
    void                      ShiftOrder (int  order_shift)
69
 
                                { TheOrder += order_shift; };
70
 
 
71
 
  public:
72
 
  /*! @todo{VB_!_RAlgebra} (rcsPhysValue) ??*/
73
 
//    bool                      operator == (sPhysValue) const;
74
 
    bool                      operator < (sPhysValue) const;
75
 
    sPhysValue                operator + () const;
76
 
    sPhysValue                operator - () const;
77
 
    sPhysValue                operator + (sPhysValue) const;
78
 
    sPhysValue                operator - (sPhysValue) const;
79
 
    sPhysValue                operator * (sPhysValue) const;
80
 
    sPhysValue                operator / (sPhysValue) const;
81
 
    rsPhysValue               operator += (sPhysValue);
82
 
    rsPhysValue               operator -= (sPhysValue);
83
 
    rsPhysValue               operator *= (real);
84
 
    rsPhysValue               operator /= (real);
85
 
 
86
 
 
87
105
  private:
88
 
    void                      Normalize ();
 
106
    void                      Normalize (unsigned short int  level);
 
107
    sString                   Txt (eTextFormat        F=Plain
 
108
                                  ,eTextDetalization  D=Casual) const;
89
109
 
90
110
  private: //fields
91
111
    sUnits                    TheUnits;
96
116
    bool                      PreciseFlag;
97
117
    bool                      ThePowerOfTenFlag;
98
118
    unsigned short int        TheDigits;
99
 
};
100
 
 
101
 
//------------------------------------------------------------- xRealAlgebra ---
102
 
 
103
 
class RANet_EXPORT  xRealAlgebra : public xException
 
119
    unsigned short int        NormalizationLevel;
 
120
                                  //!< 0 - possibly not normalized;
 
121
                                  //!< 1 - units - untouched,
 
122
                                  //!<     mantissa&order - OK;
 
123
                                  //!< 2 - units - within permissions;
 
124
                                  //!< n - units are looking better,
 
125
                                  //!<     time consuming limited by c*exp(n)
 
126
 
 
127
  friend class sUnits;
 
128
};
 
129
 
 
130
 
 
131
inline  sPhysValue  operator * (real  r ,sPhysValue  v)
 
132
{
 
133
  return sPhysValue(r) * v;
 
134
};
 
135
 
 
136
 
 
137
inline  sPhysValue  operator / (real  r ,sPhysValue  v)
 
138
{
 
139
  return sPhysValue(r) / v;
 
140
};
 
141
 
 
142
 
 
143
inline  sPhysValue  Abs (rcsPhysValue  V)
 
144
{
 
145
  return ( V.ArbValueMantissa() < 0.0 ? -V : V );
 
146
};
 
147
 
 
148
//---------------------------------------------------------------- xRAlgebra ---
 
149
 
 
150
class RANet_EXPORT  xRAlgebra : public xException
104
151
{
105
152
  public:
106
 
                              xRealAlgebra () {};
 
153
                              xRAlgebra () {};
107
154
};
108
155
 
109
156
//------------------------------------------------------------------------------