103 static void ms_CheckValue(
double value, WORD& _status)
107 if ( ::_isnan(value) != 0 )
112 else if ( ::_finite(value) == 0 )
127 static WORD ms_CalcStatus(WORD left, WORD right)
160 void m_CheckValue(
void)
162 ms_CheckValue(m_doValue, m_wStatus);
170 : m_doValue(value), m_wStatus(static_cast<WORD>(status)), m_wParam(static_cast<WORD>(param))
189 : m_doValue(other.m_doValue), m_wStatus(other.m_wStatus), m_wParam(other.m_wParam)
234 m_doValue = other.m_doValue;
235 m_wStatus = other.m_wStatus;
236 m_wParam = other.m_wParam;
296 #define FUNCMAC2(EQ, DST, VL) \
297 CRealNumber& operator EQ (DST){ \
298 m_doValue EQ VL.m_doValue; \
299 m_wStatus = ms_CalcStatus(m_wStatus, VL.m_wStatus); \
300 m_wParam |= VL.m_wParam; \
305 #define FUNCMAC1(DST, VL) \
306 FUNCMAC2( +=, DST, VL ); \
307 FUNCMAC2( -=, DST, VL ); \
308 FUNCMAC2( *=, DST, VL ); \
309 CRealNumber& operator/=(DST) { \
310 if ( VL.m_doValue != 0.0 ) { \
311 m_doValue /= VL.m_doValue; \
312 m_wStatus = ms_CalcStatus(m_wStatus, VL.m_wStatus); \
313 m_wParam |= VL.m_wParam; \
316 if ( VL.m_wStatus == ES_Empty ) { \
317 m_wStatus = ms_CalcStatus(m_wStatus, ES_Empty); \
319 m_wStatus = ms_CalcStatus(m_wStatus, ES_ZeroDivied);\
337 #define FUNCMAC2(EQ, DST, VL) \
338 CRealNumber operator EQ (DST) const { \
339 CRealNumber r = *this; \
344 #define FUNCMAC1(DST, VL) \
345 FUNCMAC2( +, DST, VL ) \
346 FUNCMAC2( -, DST, VL ) \
347 FUNCMAC2( *, DST, VL ) \
348 FUNCMAC2( /, DST, VL )
357 #define FUNCMAC2(EQ,DST,VL) \
358 friend CRealNumber operator EQ (DST, const CRealNumber& value){ \
359 CRealNumber r = VL; \
364 #define FUNCMAC1(DST, VL) \
365 FUNCMAC2( +, DST, VL ); \
366 FUNCMAC2( -, DST, VL ); \
367 FUNCMAC2( *, DST, VL ); \
368 FUNCMAC2( /, DST, VL );
370 FUNCMAC1(
double doValue, doValue )
371 FUNCMAC1(
int iValue, iValue )
380 #define FUNCMAC1(CMD) \
381 friend CRealNumber CMD(const CRealNumber& value) { \
382 if ( value.m_wStatus == ES_Valid ) { \
383 CRealNumber r(::CMD(value.m_doValue), \
384 value.m_wStatus, value.m_wParam); \
388 return CRealNumber(0, value.m_wStatus, value.m_wParam); \
390 friend double CMD(double value) { return ::CMD(value); }
415 #define FUNCMAC1(CMD, DSP, VL) \
416 friend CRealNumber CMD(const CRealNumber& value, DSP) { \
418 if ( value.m_wStatus == ES_Valid && VL.m_wStatus == ES_Valid ){\
419 d = ::CMD(value.m_doValue, VL.m_doValue); \
421 CRealNumber r(d, ms_CalcStatus(value.m_wStatus, VL.m_wStatus),\
422 value.m_wParam|VL.m_wParam); \
427 #define FUNCMAC2(CMD) \
428 FUNCMAC1( CMD, const CRealNumber& value2, value2 ); \
429 FUNCMAC1( CMD, double doValue, CRealNumber(doValue) ); \
430 FUNCMAC1( CMD, int iValue, CRealNumber(iValue) ); \
431 friend double CMD(double v1, double v2) { return ::CMD(v1, v2); }
443 CRealNumber r(::frexp(value.m_doValue, _Y), value.m_wStatus, value.m_wParam);
448 friend double frexp(
double value,
int* _Y)
450 return ::frexp(value, _Y);
455 CRealNumber r(::_jn(_X, value.m_doValue), value.m_wStatus,value.m_wParam);
460 friend double _jn(
int _X,
double value)
462 return ::_jn(_X, value);
467 CRealNumber r(::ldexp(value.m_doValue, iValue), value.m_wStatus, value.m_wParam);
472 friend double ldexp(
double value,
int iValue)
474 return ::ldexp(value, iValue);
479 CRealNumber r(::modf(value.m_doValue, _Y), value.m_wStatus, value.m_wParam);
484 friend double modf(
double value,
double* _Y)
486 return ::modf(value, _Y);
491 CRealNumber r(::_yn(_X, value.m_doValue), value.m_wStatus, value.m_wParam);
496 friend double _yn(
int _X,
double value)
498 return ::_yn(_X, value);
505 #define FUNCMAC2(EQ,TY,VL) \
506 friend bool operator EQ(TY VL##1, TY VL##2) { \
507 if ( VL##1.m_wStatus != ES_Valid ){ return false; } \
508 if ( VL##2.m_wStatus != ES_Valid ){ return false; } \
509 return VL##1.m_doValue EQ VL##2.m_doValue; \
511 friend bool operator EQ(TY VL, double d) { \
512 return operator EQ(VL, CRealNumber(d)); \
514 friend bool operator EQ(TY VL, int d) { \
515 return operator EQ(VL, CRealNumber(d)); \
517 #define FUNCMAC1(TY, VL) \
518 friend bool operator==(TY VL##1, TY VL##2) { \
519 if ( VL##1.m_wStatus != VL##2.m_wStatus ){ return false; } \
520 if ( VL##1.m_wStatus != ES_Valid && VL##1.m_wStatus == VL##2.m_wStatus ){ return true; }\
521 return VL##1.m_doValue == VL##2.m_doValue; \
523 friend bool operator==(TY VL, double d) { \
524 return operator==(VL, CRealNumber(d)); \
526 friend bool operator==(TY VL, int d) { \
527 return operator==(VL, CRealNumber(d)); \
529 friend bool operator!=(TY VL##1, TY VL##2) { \
530 return ! operator==(VL##1, VL##2); \
532 friend bool operator!=(TY VL, double d) { \
533 return operator!=(VL, CRealNumber(d)); \
535 friend bool operator!=(TY VL, int d) { \
536 return operator!=(VL, CRealNumber(d)); \
538 FUNCMAC2( <, TY, VL ); \
539 FUNCMAC2( <=, TY, VL ); \
540 FUNCMAC2( >, TY, VL ); \
541 FUNCMAC2( >=, TY, VL );
563 ASSERT1(
false,
"CRealNumber::ToDouble()",
"状態が VALID(0)以外です (r=%u) 。", m_wStatus);
575 operator double()
const
627 return static_cast<EStatus>(m_wStatus);
638 m_wStatus =
static_cast<WORD
>(status);
692 if ( m_wStatus != r.m_wStatus ){
return false; }
693 if ( m_wStatus !=
ES_Valid && m_wStatus == r.m_wStatus ){
return true; }
695 return ::floor(m_doValue / doDepth + 0.5) == ::floor(r.m_doValue / doDepth + 0.5);
709 if ( lpszFormat == NULL || lpszFormat[0] == 0 )
711 lpszFormat = _T(
"%f");
713 s.
Format(lpszFormat, m_doValue);
721 s = _T(
"-ZeroDivied-");
724 s = _T(
"-OverFlow-");
CRealNumber(double value)
代入コンストラクタ
bool IsEmpty(void) const
[確認] EMPTY確認
int ToInt(void) const
[取得] int型取得.
void SetStatus(EStatus status)
[設定] 状態設定
bool IsEqual(const CRealNumber &r) const
[確認] 比較
double ToDouble(void) const
[取得] double型取得.
CRealNumber(const CRealNumber &other)
コピーコンストラクタ
CRealNumber & operator=(const CStr &str)
[代入] 代入
bool IsAlmostEqual(const CRealNumber &r, double doDepth=0.01) const
[確認] あいまい比較.
bool IsValid(void) const
[確認] 有効確認
CRealNumber(int value)
代入コンストラクタ
CRealNumber & operator=(double value)
[代入] 代入
@ ES_ZeroDivied
Zero Divied状態
WORD GetParam(void) const
[取得] パラメータ取得
EStatus GetStatus(void) const
[確認] 状態確認
CRealNumber & operator=(int value)
[代入] 代入
void SetParam(WORD wParam)
[設定] パラメータ設定
void Empty(void)
[設定] Empty.
CStr ToString(LPCTSTR lpszFormat=NULL) const
[取得] 文字列作成
CRealNumber(const CStr &str)
代入コンストラクタ.
CRealNumber & operator=(const CRealNumber &other)
[代入] コピーオペレータ
WORD & RefParam(void)
[取得] パラメータ参照
bool IsEmpty(void) const
[確認] 空チェック
double ToDouble(INDEX iOffset=0) const
[取得] 数値(double)へ変換
void Format(const TYP *lpszFormat,...)
[代入] 書式付き文字列代入.
int ToInt(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
CRealNumber tan(const CValueDegree &d)
[計算] tan (値 = tan(角度))
CRealNumber sin(const CValueDegree &d)
[計算] sin (値 = sin(角度))
CValueDistance sqrt(const CValueArea &a)
[計算] 平方根 (距離 = √面積)
CRealNumber cos(const CValueDegree &d)
[計算] cos (値 = cos(角度))
CRealNumber cosh(const CValueDegree &d)
[計算] cosh (値 = cosh(角度))
CRealNumber sinh(const CValueDegree &d)
[計算] sinh (値 = sinh(角度))
CRealNumber tanh(const CValueDegree &d)
[計算] tanh (値 = tanh(角度))