17
20
,UnitsAreFixedFlag(false)
19
,TheFromMantissa( - std::numeric_limits<real>::infinity() )
20
,TheToMantissa( std::numeric_limits<real>::infinity() )
22
,TheFromMantissa( - real_inf )
23
,TheToMantissa( real_inf )
21
24
,ThePrecisionMantissa(0.0)
22
25
,TheDigits(sPhysValue::MaxDigits-1)
27
sPhysRange::sPhysRange (real from ,real to ,sUnits units ,real precision)
29
,UnitsAreFixedFlag(true)
31
,TheFromMantissa(from)
33
,ThePrecisionMantissa(fabs(precision))
39
//sPhysRange::sPhysRange (sPhysValue from ,sPhysValue to)
40
// :TheUnits(to.Units())
41
// ,UnitsAreFixedFlag(true)
43
// ,ThePrecisionMantissa(0.0)
44
// ,TheDigits(sPhysValue::MaxDigits-1)
47
// if( ! to.Units().Comparable(from.Units(),C) )
48
// throw xRealAlgebra();
49
// TheToMantissa=to.Value();
50
// TheFromMantissa=from.Value() / C;
56
sPhysRange::sPhysRange (rcsPhysRange range)
58
,TheUnits(range.TheUnits)
59
,UnitsAreFixedFlag(range.UnitsAreFixedFlag)
60
,TheOrder(range.TheOrder)
61
,TheFromMantissa(range.TheFromMantissa)
62
,TheToMantissa(range.TheToMantissa)
63
,ThePrecisionMantissa(range.ThePrecisionMantissa)
64
,TheDigits(range.TheDigits)
26
,NormalizationLevel(99)
88
51
a_stream.WRITE_FROM(TheFromMantissa);
89
52
a_stream.WRITE_FROM(TheToMantissa);
90
53
a_stream.WRITE_FROM(ThePrecisionMantissa);
54
a_stream.WRITE_FROM(TheDigits);
55
a_stream.WRITE_FROM(NormalizationLevel);
59
sPhysRange::sPhysRange (rcsUnits units)
61
,UnitsAreFixedFlag(true)
63
,TheFromMantissa( - real_inf )
64
,TheToMantissa( real_inf )
65
,ThePrecisionMantissa(0.0)
66
,TheDigits(sPhysValue::MaxDigits-1)
67
,NormalizationLevel(1)
69
Normalize(sPhysValue::DraftNormalization);
73
sPhysRange::sPhysRange (real from
78
,UnitsAreFixedFlag(true)
80
,TheFromMantissa(from)
82
,ThePrecisionMantissa(rabs(precision))
83
,TheDigits(sPhysValue::MaxDigits-1)
84
,NormalizationLevel(0)
86
Normalize(sPhysValue::DraftNormalization);
90
sPhysRange::sPhysRange (sString unitsstr)
92
,UnitsAreFixedFlag(true)
94
,TheFromMantissa( - real_inf )
95
,TheToMantissa( real_inf )
96
,ThePrecisionMantissa(0.0)
97
,TheDigits(sPhysValue::MaxDigits-1)
98
,NormalizationLevel(1)
100
Normalize(sPhysValue::DraftNormalization);
104
sPhysRange::sPhysRange (real from
109
,UnitsAreFixedFlag(true)
111
,TheFromMantissa(from)
113
,ThePrecisionMantissa(rabs(precision))
114
,TheDigits(sPhysValue::MaxDigits-1)
115
,NormalizationLevel(0)
117
Normalize(sPhysValue::DraftNormalization);
121
sPhysRange::sPhysRange (rcsPhysValue from ,rcsPhysValue to)
122
:TheUnits(from.Units())
123
,UnitsAreFixedFlag(true)
125
,ThePrecisionMantissa(0.0)
126
,TheDigits(sPhysValue::MaxDigits-1)
127
,NormalizationLevel(0)
130
if( ! from.Units().Comparable(to.Units(),Ratio) )
132
TheFromMantissa=from.ArbValue();
133
TheToMantissa=to.ArbValue() / Ratio;
134
ThePrecisionMantissa = rabs(to.ArbError() / Ratio);
135
if( ThePrecisionMantissa < rabs(from.ArbError()) )
136
ThePrecisionMantissa = rabs(from.ArbError());
137
Normalize(sPhysValue::DraftNormalization);
138
// RANet::Log.Put(sLog::Debug,"sPhysRange::sPhysRange"
139
// ,sString("sPhysRange::sPhysRange(")+from.Text()+","+to.Text()+")="+Txt()
140
// +(sString(" Ratio=")<<Ratio)
145
sPhysRange::sPhysRange (rcsPhysRange range)
147
,TheUnits(range.TheUnits)
148
,UnitsAreFixedFlag(range.UnitsAreFixedFlag)
149
,TheOrder(range.TheOrder)
150
,TheFromMantissa(range.TheFromMantissa)
151
,TheToMantissa(range.TheToMantissa)
152
,ThePrecisionMantissa(range.ThePrecisionMantissa)
153
,TheDigits(range.TheDigits)
154
,NormalizationLevel(range.NormalizationLevel)
94
159
rsPhysRange sPhysRange::operator = (rcsPhysRange range)
97
162
if( ! UnitsAreFixedFlag ){
98
TheUnits=range.TheUnits;
99
TheOrder=range.TheOrder;
100
TheFromMantissa=range.TheFromMantissa;
101
TheToMantissa=range.TheToMantissa;
102
ThePrecisionMantissa=range.ThePrecisionMantissa;
103
TheDigits=range.TheDigits;
104
}else if( TheUnits.Comparable(range.TheUnits,C) ){
105
TheOrder=range.TheOrder;
106
TheFromMantissa=range.TheFromMantissa / C;
107
TheToMantissa=range.TheToMantissa / C;
108
ThePrecisionMantissa=range.ThePrecisionMantissa / C;
163
TheUnits = range.TheUnits;
164
TheOrder = range.TheOrder;
165
TheFromMantissa = range.TheFromMantissa;
166
TheToMantissa = range.TheToMantissa;
167
ThePrecisionMantissa = range.ThePrecisionMantissa;
168
TheDigits = range.TheDigits;
169
NormalizationLevel = range.NormalizationLevel;
170
}else if( TheUnits.Comparable(range.TheUnits,Ratio) ){
171
TheOrder = range.TheOrder;
172
TheFromMantissa = range.TheFromMantissa / Ratio;
173
TheToMantissa = range.TheToMantissa / Ratio;
174
ThePrecisionMantissa = rabs(range.ThePrecisionMantissa / Ratio);
175
NormalizationLevel = 0;
176
Normalize(sPhysValue::DraftNormalization);
111
throw xRealAlgebra();
130
197
if( ! TheUnits.Comparable(range.TheUnits,C) )
131
throw xRealAlgebra();
132
199
C *= power10(TheOrder-range.TheOrder);
133
200
if( TheFromMantissa < range.TheFromMantissa / C ){
134
201
TheFromMantissa=range.TheFromMantissa / C;
135
202
ThePrecisionMantissa=std::max(ThePrecisionMantissa
136
203
,range.ThePrecisionMantissa / C);
138
}else if( range.TheToMantissa / C < TheToMantissa ){
204
}else if( TheToMantissa > range.TheToMantissa / C ){
139
205
TheToMantissa=range.TheToMantissa / C;
140
206
ThePrecisionMantissa=std::max(ThePrecisionMantissa
207
,rabs(range.ThePrecisionMantissa / C));
209
NormalizationLevel = 0;
210
Normalize(sPhysValue::DraftNormalization);
215
rsPhysRange sPhysRange::operator |= (sPhysRange range)
218
if( ! TheUnits.Comparable(range.TheUnits,C) )
220
C *= power10(TheOrder-range.TheOrder);
221
if( TheFromMantissa > range.TheFromMantissa / C ){
222
TheFromMantissa=range.TheFromMantissa / C;
223
ThePrecisionMantissa=std::max(ThePrecisionMantissa
141
224
,range.ThePrecisionMantissa / C);
225
}else if( TheToMantissa < range.TheToMantissa / C ){
226
TheToMantissa=range.TheToMantissa / C;
227
ThePrecisionMantissa=std::max(ThePrecisionMantissa
228
,rabs(range.ThePrecisionMantissa / C));
230
NormalizationLevel = 0;
231
Normalize(sPhysValue::DraftNormalization);
236
void sPhysRange::Normalize (unsigned short int level)
238
if( level <= NormalizationLevel )
240
RANet::Log.OpenBlock(sLog::Debug,"sPhysRange::Normalize",Txt());
242
if( ( isnan(TheFromMantissa) || isinf(TheFromMantissa) )
243
&& ( isnan(TheToMantissa) || isinf(TheToMantissa) ) ){
244
if( level > 1 ) TheUnits.DissolveOrder(level);
247
if( isnan(TheFromMantissa) || isinf(TheFromMantissa) ){
248
MaxMantissa = fabs(TheToMantissa);
249
}else if( isnan(TheToMantissa) || isinf(TheToMantissa) ){
250
MaxMantissa = fabs(TheFromMantissa);
252
MaxMantissa = std::max( fabs(TheFromMantissa) , fabs(TheToMantissa) );
254
if( (MaxMantissa == 0) && (ThePrecisionMantissa == 0) ){
255
if( level > 1 ) TheUnits.DissolveOrder(level);
257
TheDigits = sPhysValue::MaxDigits;
260
bool TryToIncreaseExpectedRest = false;
261
int ExpectedRest = 0;
263
//приведение мантисс: V к [0.1,1) или если |V|<E, то E к [0.1,1)
264
//и вычисление максимального сдвига,
265
//допустимого после приведения единиц
267
if( rabs(MaxMantissa) < ThePrecisionMantissa ){
268
// TRACENOCR("|V|<E");
269
real LgE = log10(ThePrecisionMantissa);
270
if( LgE == - real_inf ){
271
TRACENOCR("АБЗДАЧА-LgE-1");
272
}else if( LgE == real_inf ){
273
TRACENOCR("АБЗДАЧА-LgE-2");
274
}else if( isnan(LgE) ){
275
TRACENOCR("АБЗДАЧА-LgE-3");
277
Shift = floor(LgE)+1;
280
real LgV = log10(rabs(MaxMantissa));
281
if( LgV == -real_inf ){
282
TRACENOCR("АБЗДАЧА-LgV-1");
283
}else if( LgV == real_inf ){
284
TRACENOCR("АБЗДАЧА-LgV-2");
285
}else if( isnan(LgV) ){
286
TRACENOCR("АБЗДАЧА-LgV-3");
288
Shift = floor(LgV)+1;
290
TryToIncreaseExpectedRest = true;
295
TheFromMantissa /= C;
297
ThePrecisionMantissa /= C;
300
if( TryToIncreaseExpectedRest ){
301
if( ThePrecisionMantissa < 0.1 ) ExpectedRest = 1;
302
if( ThePrecisionMantissa < 0.01 ) ExpectedRest = 2;
303
if( ThePrecisionMantissa < 0.001 ) ExpectedRest = 3;
306
TheOrder = TheUnits.DissolveOrder(level,TheOrder
307
,ExpectedRest-2,ExpectedRest);
310
Shift = TheOrder - floor(TheOrder/3)*3;
312
Shift = TheOrder - floor((TheOrder-1)/3)*3;
315
TheOrder = TheOrder - Shift;
317
TheFromMantissa *= C;
319
ThePrecisionMantissa *= C;
321
real D = log10(0.3/ThePrecisionMantissa);
322
TheDigits = ( D > sPhysValue::MaxDigits ? sPhysValue::MaxDigits
323
: ( D < 0 ? 0 : ceil(D) ) );
326
NormalizationLevel = level;
327
RANet::Log.Put(sLog::Debug,"sPhysRange::Normalize",sString("finally ")+Txt());
328
RANet::Log.CloseBlock(sLog::Debug,"sPhysRange::Normalize");
332
sString sPhysRange::Text (eTextFormat F)
334
// RANet::Log.Put(sLog::Debug,"sPhysRange::Text","");
335
if( NormalizationLevel < sPhysValue::BriefNormalization ){
336
Normalize(sPhysValue::BriefNormalization);
148
342
sString sPhysRange::Text (eTextFormat F) const
344
// RANet::Log.Put(sLog::Debug,"sPhysRange::Text","const");
345
if( NormalizationLevel < sPhysValue::BriefNormalization ){
346
sPhysRange NormalizedForm(*this);
347
NormalizedForm.Normalize(sPhysValue::BriefNormalization);
348
return NormalizedForm.Txt(F);
355
sString sPhysRange::Txt (eTextFormat F) const
151
T += sString::from_real(TheFromMantissa,TheDigits);
359
T += sString::FromReal(TheFromMantissa,TheDigits);
153
T += sString::from_real(TheToMantissa,TheDigits);
361
T += sString::FromReal(TheToMantissa,TheDigits);
365
T += Symbol::Multiplication;
168
T += TheUnits.Text(F);
375
UT = TheUnits.Text(F);
173
void sPhysRange::Normalize ()
175
real V = std::max(fabs(TheFromMantissa)
176
,fabs(TheToMantissa) );
183
ThePrecisionMantissa = fabs(ThePrecisionMantissa);
184
if( LgV == -std::numeric_limits<real>::infinity() ){
185
// TRACE( "Normalize -inf" );
186
D = log10(fabs(0.3*C/ThePrecisionMantissa));
187
// { sString T; TRACE( T<<D ); };
188
// TRACE( BeforeDot );
189
// TRACE( log_shift );
190
}else if( LgV == std::numeric_limits<real>::infinity() ){
191
// TRACE( "Normalize +inf" );
192
// { sString T; TRACE( T<<D ); };
193
// TRACE( BeforeDot );
194
// TRACE( log_shift );
196
// TRACE( "Normalize" );
197
FloorLgV = floor(LgV / 3);
198
log_shift = FloorLgV * 3;
199
BeforeDot = floor(LgV) - log_shift + 1;
200
C = power10(log_shift);
201
D = log10(fabs(0.3*C/ThePrecisionMantissa));
203
TheDigits = ( D > sPhysValue::MaxDigits-BeforeDot
204
? sPhysValue::MaxDigits-BeforeDot
205
: ( D < 0 ? 0 : ceil(D) ) );
206
// TRACE( TheDigits );
207
if( (V == 0.0) || isinf(V) || isnan(V) ){
210
TheFromMantissa /= C;
212
ThePrecisionMantissa /= C;
217
383
//------------------------------------------------------------------------------
218
384
}; //namespace RA