- /* sdf2dbld.cpp by K.Tsuru */
- // function ID 3001
- /********************************************************************
- SDouble class
- Provides a conversion SDouble --> long double.
- If you let err = 0, an out of range of double does not terminate the
- program and return DBL_MAX or 0.0. The error (OVERFLOW_ERR or UNDERFLOW_ERR)
- can be detected by SNError().
- Default value is declared as err = 1.
- *********************************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- static const char* func = "doubleLD";
- long double ldpow10(const int n){
- if(!n) return 1.0;
- long double r(1), z(10.0);
- int m = n>0 ? n : -n;
-
- while(1){
- if( m & 1 ) r *= z;
- m /= 2;
- if( !m ) break;
- z *= z;
- }
- if(n > 0) return r;
- return 1.0/r;
- }
-
- ldouble doubleLD(const SDouble& sd, int err){
- if(sd.Type() != sd.REAL) SNManager::SetError(sd.RADIX_ERR, func, 3001);
- if(sd.SNSign() == 0) return 0.0;
-
- // detect error
- long de = sd.DExp();
- SNManager::SNErrorFlag error = sd.NO_ERR;
- ldouble d = 0.0;
-
- if(de > LDBL_MAX_10_EXP-1){
- error = sd.OVERFLOW_ERR;
- d = LDBL_MAX;
- }else if( de < LDBL_MIN_10_EXP+1 ){
- error = sd.UNDERFLOW_ERR;
- d = 0.0;
- }
-
- if(error != sd.NO_ERR){
- if(err) sd.SetError(error, func, 3001);
- else sd.SetErrorFlag(error);
- return d;
- }
-
- stringstream ss;
- sd.SetFormat(0, LDBL_DIG+2, 0, sd.ROUND);
- ss.precision(LDBL_DIG+2);
- ss << scientific << sd;
- ss >> d;
- return d;
- }
-
sdf2dbld.cpp : last modifiled at 2017/08/23 10:42:40(1,484 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).