*** empty log message ***
git-svn-id: svn://10.65.10.50/trunk@22 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
65e62eda30
commit
a041c09044
305
include/real.cpp
305
include/real.cpp
@ -14,17 +14,17 @@ HIDDEN real __tmp_real;
|
||||
HIDDEN char __string[80];
|
||||
const real ZERO (0.0);
|
||||
|
||||
real ::real ()
|
||||
real::real ()
|
||||
{
|
||||
dzero (ptr ());
|
||||
}
|
||||
|
||||
real ::real (const real & b)
|
||||
real::real (const real& b)
|
||||
{
|
||||
dcpy (ptr (), b.ptr ());
|
||||
}
|
||||
|
||||
real ::real (double a)
|
||||
real::real (double a)
|
||||
{
|
||||
dftodr (ptr (), a, 9); // Round the number (1.0 is NOT 0.999999999)
|
||||
|
||||
@ -32,8 +32,7 @@ real ::real (double a)
|
||||
|
||||
}
|
||||
|
||||
char *real ::
|
||||
eng2ita (char *s)
|
||||
char *real::eng2ita (char *s)
|
||||
{
|
||||
if (s)
|
||||
{
|
||||
@ -44,8 +43,7 @@ eng2ita (char *s)
|
||||
return s;
|
||||
}
|
||||
|
||||
char *real ::
|
||||
ita2eng (const char *s)
|
||||
char *real::ita2eng (const char *s)
|
||||
{
|
||||
int j = 0;
|
||||
if (s)
|
||||
@ -68,15 +66,13 @@ ita2eng (const char *s)
|
||||
return __string;
|
||||
}
|
||||
|
||||
bool real ::
|
||||
is_real (const char *s)
|
||||
bool real::is_real (const char *s)
|
||||
{
|
||||
bool ok = FALSE;
|
||||
if (s)
|
||||
{
|
||||
while (*s == ' ')
|
||||
s++; // Remove leading spaces before atod
|
||||
|
||||
ok = atod (__tmp_real.ptr (), (char *) s) != GM_NULL;
|
||||
}
|
||||
return ok;
|
||||
@ -94,46 +90,46 @@ real ::real (const char *s)
|
||||
dzero (ptr ());
|
||||
}
|
||||
|
||||
real & real ::operator = (const real & b)
|
||||
real& real::operator = (const real& b)
|
||||
{
|
||||
dcpy (ptr (), b.ptr ());
|
||||
return *this;
|
||||
}
|
||||
|
||||
real & real ::operator = (double a)
|
||||
real& real::operator = (double a)
|
||||
{
|
||||
const real n (a);
|
||||
operator = (n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
real & real ::operator += (const real & b)
|
||||
real& real::operator += (const real& b)
|
||||
{
|
||||
dadd (ptr (), ptr (), b.ptr ());
|
||||
return *this;
|
||||
}
|
||||
|
||||
real & real ::operator += (double a)
|
||||
real& real ::operator += (double a)
|
||||
{
|
||||
__tmp_real = *this;
|
||||
adddfd (ptr (), __tmp_real.ptr (), a);
|
||||
return *this;
|
||||
}
|
||||
|
||||
real & real ::operator -= (const real & b)
|
||||
real& real::operator -= (const real& b)
|
||||
{
|
||||
__tmp_real = *this;
|
||||
dsub (ptr (), __tmp_real.ptr (), b.ptr ());
|
||||
return *this;
|
||||
}
|
||||
|
||||
real & real ::operator *= (const real & b)
|
||||
real& real::operator *= (const real& b)
|
||||
{
|
||||
dmul (ptr (), ptr (), b.ptr ());
|
||||
return *this;
|
||||
}
|
||||
|
||||
real & real ::operator /= (const real & b)
|
||||
real& real::operator /= (const real& b)
|
||||
{
|
||||
const DEC *dst = ddiv (ptr (), ptr (), b.ptr ());
|
||||
|
||||
@ -148,52 +144,47 @@ real & real ::operator /= (const real & b)
|
||||
return *this;
|
||||
}
|
||||
|
||||
TObject *real ::
|
||||
dup ()
|
||||
const
|
||||
{
|
||||
|
||||
|
||||
TObject *real::dup () const
|
||||
{
|
||||
return new real (*this);
|
||||
}
|
||||
}
|
||||
|
||||
bool real ::is_zero ()
|
||||
const
|
||||
{
|
||||
bool real::is_zero () const
|
||||
{
|
||||
return diszero (ptr ());
|
||||
}
|
||||
}
|
||||
|
||||
int real ::sign ()
|
||||
const
|
||||
{
|
||||
int real::sign () const
|
||||
{
|
||||
return dsign (ptr ());
|
||||
}
|
||||
}
|
||||
|
||||
real real ::operator - ()
|
||||
const
|
||||
{
|
||||
real real::operator- () const
|
||||
{
|
||||
real n;
|
||||
dchgs (n.ptr (), ptr ());
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
int real ::integer ()
|
||||
const
|
||||
{
|
||||
int real::integer () const
|
||||
{
|
||||
return dtoi (ptr ());
|
||||
}
|
||||
}
|
||||
|
||||
// Certified 91%
|
||||
char *real ::string (int len, int dec, char pad)
|
||||
const
|
||||
{
|
||||
char *real::string (int len, int dec, char pad) const
|
||||
{
|
||||
__tmp_real = *this;
|
||||
if (dec != UNDEFINED)
|
||||
__tmp_real.round (dec);
|
||||
else
|
||||
deltrz (__tmp_real.ptr (), __tmp_real.ptr ());
|
||||
|
||||
// if (len == 0)
|
||||
// if (len == 0)
|
||||
dtoa (__string, __tmp_real.ptr ());
|
||||
/*
|
||||
/*
|
||||
* else
|
||||
* {
|
||||
* char f[16];
|
||||
@ -215,7 +206,7 @@ dup ()
|
||||
*/
|
||||
int lun = strlen (__string);
|
||||
|
||||
/*
|
||||
/*
|
||||
* char* dot = strchr(__string, '.');
|
||||
*
|
||||
* int d = dot ? strlen(dot+1) : 0; // Decimals already there
|
||||
@ -242,24 +233,21 @@ dup ()
|
||||
}
|
||||
|
||||
return __string;
|
||||
}
|
||||
}
|
||||
|
||||
// Certified 99%
|
||||
char *real ::
|
||||
stringa (int len, int dec, char pad)
|
||||
const
|
||||
char* real::stringa (int len, int dec, char pad) const
|
||||
|
||||
{
|
||||
{
|
||||
string (len, dec, pad);
|
||||
if (dec > 0 || dec == UNDEFINED)
|
||||
eng2ita (__string);
|
||||
return __string;
|
||||
}
|
||||
}
|
||||
|
||||
// Certified 75%
|
||||
char *real ::literals ()
|
||||
const
|
||||
{
|
||||
char *real::literals () const
|
||||
{
|
||||
const char *primi20[] =
|
||||
{"", "uno", "due", "tre", "quattro",
|
||||
"cinque", "sei", "sette", "otto",
|
||||
@ -335,13 +323,11 @@ stringa (int len, int dec, char pad)
|
||||
if (negativo)
|
||||
risultato.insert ("meno", 0);
|
||||
return __string;
|
||||
}
|
||||
}
|
||||
|
||||
// Certified 75%
|
||||
char *real ::
|
||||
points (int dec)
|
||||
const
|
||||
{
|
||||
char *real::points (int dec) const
|
||||
{
|
||||
const char *str = stringa ();
|
||||
const int neg = (*str == '-') ? 1 : 0;
|
||||
TFixed_string n ((char *) str, 24);
|
||||
@ -369,10 +355,9 @@ points (int dec)
|
||||
n.insert (".", i);
|
||||
|
||||
return __string;
|
||||
}
|
||||
}
|
||||
|
||||
HIDDEN int
|
||||
get_picture_decimals (const TString & picture)
|
||||
HIDDEN int get_picture_decimals (const TString & picture)
|
||||
{
|
||||
int decimali = 0;
|
||||
const int virgola = picture.find (',');
|
||||
@ -386,10 +371,8 @@ get_picture_decimals (const TString & picture)
|
||||
return decimali;
|
||||
}
|
||||
|
||||
char *real ::
|
||||
string (const char *picture)
|
||||
const
|
||||
{
|
||||
char *real::string (const char *picture) const
|
||||
{
|
||||
if (*picture == '\0')
|
||||
return string ();
|
||||
if (*picture == '.')
|
||||
@ -440,29 +423,27 @@ string (const char *picture)
|
||||
break;
|
||||
}
|
||||
return strcpy (__string, f);
|
||||
}
|
||||
}
|
||||
|
||||
ostream & operator << (ostream & out, const real & a)
|
||||
ostream& operator<< (ostream& out, const real& a)
|
||||
|
||||
{
|
||||
return out << a.string ();
|
||||
}
|
||||
|
||||
istream & operator >> (istream & in, real & a)
|
||||
|
||||
istream& operator>> (istream& in, real& a)
|
||||
{
|
||||
in >> __string;
|
||||
atod (a.ptr (), __string);
|
||||
return in;
|
||||
}
|
||||
|
||||
int real ::
|
||||
precision ()
|
||||
int real::precision ()
|
||||
{
|
||||
return dprec (ptr ());
|
||||
}
|
||||
|
||||
real & real ::round (int prec)
|
||||
real& real::round (int prec)
|
||||
{
|
||||
if (prec < 0)
|
||||
{
|
||||
@ -476,7 +457,7 @@ real & real ::round (int prec)
|
||||
return *this;
|
||||
}
|
||||
|
||||
real & real ::ceil (int prec)
|
||||
real& real::ceil (int prec)
|
||||
{
|
||||
double p = 1.0;
|
||||
if (prec)
|
||||
@ -498,41 +479,41 @@ real & real ::ceil (int prec)
|
||||
return *this;
|
||||
}
|
||||
|
||||
real & real ::trunc (int prec)
|
||||
real& real::trunc (int prec)
|
||||
{
|
||||
dtrunc (ptr (), ptr (), prec);
|
||||
return *this;
|
||||
}
|
||||
|
||||
real operator + (const real & a, const real & b)
|
||||
real operator+ (const real& a, const real& b)
|
||||
|
||||
{
|
||||
dadd (__tmp_real.ptr (), a.ptr (), b.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
|
||||
real operator + (double a, const real & b)
|
||||
real operator+ (double a, const real& b)
|
||||
|
||||
{
|
||||
__tmp_real = a;
|
||||
return __tmp_real += b;
|
||||
}
|
||||
|
||||
real operator + (const real & a, double b)
|
||||
real operator+ (const real& a, double b)
|
||||
|
||||
{
|
||||
__tmp_real = a;
|
||||
return __tmp_real += b;
|
||||
}
|
||||
|
||||
real operator - (const real & a, const real & b)
|
||||
real operator - (const real& a, const real& b)
|
||||
|
||||
{
|
||||
dsub (__tmp_real.ptr (), a.ptr (), b.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
|
||||
real operator - (double a, const real & b)
|
||||
real operator - (double a, const real& b)
|
||||
|
||||
{
|
||||
__tmp_real = a;
|
||||
@ -540,42 +521,42 @@ real operator - (double a, const real & b)
|
||||
return __tmp_real;
|
||||
}
|
||||
|
||||
real operator - (const real & a, double b)
|
||||
real operator - (const real& a, double b)
|
||||
|
||||
{
|
||||
__tmp_real = b;
|
||||
return __tmp_real -= a;
|
||||
}
|
||||
|
||||
real operator *(const real & a, const real & b)
|
||||
real operator *(const real& a, const real& b)
|
||||
|
||||
{
|
||||
dmul (__tmp_real.ptr (), a.ptr (), b.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
|
||||
real operator *(double a, const real & b)
|
||||
real operator *(double a, const real& b)
|
||||
|
||||
{
|
||||
muldfd (__tmp_real.ptr (), b.ptr (), a);
|
||||
return __tmp_real;
|
||||
}
|
||||
|
||||
real operator *(const real & a, double b)
|
||||
real operator *(const real& a, double b)
|
||||
|
||||
{
|
||||
muldfd (__tmp_real.ptr (), a.ptr (), b);
|
||||
return __tmp_real;
|
||||
}
|
||||
|
||||
real operator / (const real & a, const real & b)
|
||||
real operator / (const real& a, const real& b)
|
||||
|
||||
{
|
||||
ddiv (__tmp_real.ptr (), a.ptr (), b.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
|
||||
real operator / (double a, const real & b)
|
||||
real operator / (double a, const real& b)
|
||||
|
||||
{
|
||||
__tmp_real = a;
|
||||
@ -583,7 +564,7 @@ real operator / (double a, const real & b)
|
||||
return __tmp_real;
|
||||
}
|
||||
|
||||
real operator / (const real & a, double b)
|
||||
real operator / (const real& a, double b)
|
||||
|
||||
{
|
||||
__tmp_real = b;
|
||||
@ -591,191 +572,193 @@ real operator / (const real & a, double b)
|
||||
return __tmp_real;
|
||||
}
|
||||
|
||||
bool operator > (const real & a, const real & b)
|
||||
bool operator > (const real& a, const real& b)
|
||||
{
|
||||
return disgt (a.ptr (), b.ptr ());
|
||||
}
|
||||
|
||||
bool operator > (double a, const real & b)
|
||||
bool operator > (double a, const real& b)
|
||||
{
|
||||
// dftod(__tmp_real.ptr(), a);
|
||||
// dftod(__tmp_real.ptr(), a);
|
||||
// return disgt(__tmp_real.ptr(), b.ptr());
|
||||
const double n = dtodf (b.ptr ());
|
||||
return a > n;
|
||||
}
|
||||
|
||||
bool operator < (const real & a, const real & b)
|
||||
bool operator < (const real& a, const real& b)
|
||||
|
||||
{
|
||||
return dislt (a.ptr (), b.ptr ());
|
||||
}
|
||||
|
||||
bool operator < (double a, const real & b)
|
||||
bool operator < (double a, const real& b)
|
||||
|
||||
{
|
||||
// dftod(__tmp_real.ptr(), a);
|
||||
// dftod(__tmp_real.ptr(), a);
|
||||
// return dislt(__tmp_real.ptr(), b.ptr());
|
||||
const double n = dtodf (b.ptr ());
|
||||
return a < n;
|
||||
}
|
||||
|
||||
bool operator >= (const real & a, const real & b)
|
||||
bool operator >= (const real& a, const real& b)
|
||||
|
||||
{
|
||||
return disge (a.ptr (), b.ptr ());
|
||||
}
|
||||
|
||||
bool operator >= (double a, const real & b)
|
||||
bool operator >= (double a, const real& b)
|
||||
|
||||
{
|
||||
// dftod(__tmp_real.ptr(), a);
|
||||
// dftod(__tmp_real.ptr(), a);
|
||||
// return disge(__tmp_real.ptr(), b.ptr());
|
||||
const double n = dtodf (b.ptr ());
|
||||
return a >= n;
|
||||
}
|
||||
|
||||
bool operator <= (const real & a, const real & b)
|
||||
bool operator <= (const real& a, const real& b)
|
||||
|
||||
{
|
||||
return disle (a.ptr (), b.ptr ());
|
||||
}
|
||||
|
||||
bool operator <= (double a, const real & b)
|
||||
bool operator <= (double a, const real& b)
|
||||
|
||||
{
|
||||
// dftod(__tmp_real.ptr(), a);
|
||||
// dftod(__tmp_real.ptr(), a);
|
||||
// return disle(__tmp_real.ptr(), b.ptr());
|
||||
const double n = dtodf (b.ptr ());
|
||||
return a <= n;
|
||||
}
|
||||
|
||||
bool operator == (const real & a, const real & b)
|
||||
bool operator == (const real& a, const real& b)
|
||||
{
|
||||
return diseq (a.ptr (), b.ptr ());
|
||||
}
|
||||
}
|
||||
|
||||
bool operator == (double a, const real & b)
|
||||
{
|
||||
bool operator == (double a, const real& b)
|
||||
{
|
||||
const double n = dtodf (b.ptr ());
|
||||
return a == n;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator != (const real & a, const real & b)
|
||||
bool operator != (const real& a, const real& b)
|
||||
|
||||
{
|
||||
{
|
||||
return !diseq (a.ptr (), b.ptr ());
|
||||
}
|
||||
}
|
||||
|
||||
bool operator != (double a, const real & b)
|
||||
bool operator != (double a, const real& b)
|
||||
|
||||
{
|
||||
{
|
||||
const double n = dtodf (b.ptr ());
|
||||
return a != n;
|
||||
}
|
||||
}
|
||||
|
||||
real operator % (const real & a, const long b)
|
||||
real operator % (const real& a, const long b)
|
||||
|
||||
{
|
||||
{
|
||||
dmodl (__tmp_real.ptr (), a.ptr (), b);
|
||||
return __tmp_real;
|
||||
}
|
||||
}
|
||||
|
||||
void swap (real & a, real & b)
|
||||
void swap (real& a, real& b)
|
||||
|
||||
{
|
||||
{
|
||||
SwapDecimal (a.ptr (), b.ptr ());
|
||||
}
|
||||
}
|
||||
|
||||
real fnc_min (const real & a, const real & b)
|
||||
real fnc_min (const real& a, const real& b)
|
||||
|
||||
{
|
||||
{
|
||||
dmin (__tmp_real.ptr (), a.ptr (), b.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
}
|
||||
|
||||
real fnc_max (const real & a, const real & b)
|
||||
real fnc_max (const real& a, const real& b)
|
||||
|
||||
{
|
||||
{
|
||||
dmax (__tmp_real.ptr (), a.ptr (), b.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
}
|
||||
|
||||
real sqrt (const real & a)
|
||||
real sqrt (const real& a)
|
||||
|
||||
{
|
||||
{
|
||||
dsqrt (__tmp_real.ptr (), a.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
}
|
||||
|
||||
real sqr (const real & a)
|
||||
real sqr (const real& a)
|
||||
|
||||
{
|
||||
{
|
||||
dmul (__tmp_real.ptr (), a.ptr (), a.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
}
|
||||
|
||||
real exp10 (const real & a)
|
||||
real exp10 (const real& a)
|
||||
|
||||
{
|
||||
{
|
||||
dalog (__tmp_real.ptr (), a.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
}
|
||||
|
||||
real pow (const real & a, const real & b)
|
||||
real pow (const real& a, const real& b)
|
||||
|
||||
{
|
||||
{
|
||||
dpow (__tmp_real.ptr (), a.ptr (), b.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
}
|
||||
|
||||
real exp (const real & a)
|
||||
real exp (const real& a)
|
||||
|
||||
{
|
||||
{
|
||||
dexp (__tmp_real.ptr (), a.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
}
|
||||
|
||||
real log10 (const real & a)
|
||||
|
||||
{
|
||||
|
||||
real log10 (const real& a)
|
||||
|
||||
{
|
||||
dlog (__tmp_real.ptr (), a.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
}
|
||||
|
||||
real log (const real & a)
|
||||
real log (const real& a)
|
||||
|
||||
{
|
||||
{
|
||||
dln (__tmp_real.ptr (), a.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
}
|
||||
|
||||
real sin (const real & a)
|
||||
real sin (const real& a)
|
||||
|
||||
{
|
||||
{
|
||||
dsin (__tmp_real.ptr (), a.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
}
|
||||
|
||||
real cos (const real & a)
|
||||
real cos (const real& a)
|
||||
|
||||
{
|
||||
{
|
||||
dcos (__tmp_real.ptr (), a.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
}
|
||||
|
||||
real tan (const real & a)
|
||||
real tan (const real& a)
|
||||
|
||||
{
|
||||
{
|
||||
dtan (__tmp_real.ptr (), a.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
}
|
||||
|
||||
real abs (const real & a)
|
||||
real abs (const real& a)
|
||||
|
||||
{
|
||||
{
|
||||
dabs (__tmp_real.ptr (), a.ptr ());
|
||||
return __tmp_real;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Distrib
|
||||
@ -784,15 +767,15 @@ bool operator == (const real & a, const real & b)
|
||||
// /////////////////////////////////////////////////////////
|
||||
|
||||
void TDistrib ::add (real slice)
|
||||
{
|
||||
{
|
||||
if (slice > real (1.0))
|
||||
slice /= 100.0;
|
||||
CHECK (!_ready, "TDistrib: les jeux sont faits");
|
||||
_slices.add (slice);
|
||||
}
|
||||
}
|
||||
|
||||
real TDistrib ::get ()
|
||||
{
|
||||
{
|
||||
_ready = TRUE;
|
||||
CHECK (_current < _slices.items (), "TDistrib: too many gets");
|
||||
real r = _tot * ((real &) _slices[_current++]);
|
||||
@ -804,10 +787,10 @@ real TDistrib ::get ()
|
||||
else
|
||||
_prog += r;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
void TDistrib ::init (const real & r)
|
||||
{
|
||||
void TDistrib ::init (const real& r)
|
||||
{
|
||||
_current = 0; _prog = 0;
|
||||
_tot = r; _ready = FALSE;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user