Corretta ceil per i numeri negativi (2 la vendetta).
git-svn-id: svn://10.65.10.50/trunk@27 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
b6fc4a65e3
commit
3d2d9d579f
170
include/real.cpp
170
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,7 +32,7 @@ real::real (double a)
|
||||
|
||||
}
|
||||
|
||||
char *real::eng2ita (char *s)
|
||||
char *real ::eng2ita (char *s)
|
||||
{
|
||||
if (s)
|
||||
{
|
||||
@ -43,7 +43,7 @@ char *real::eng2ita (char *s)
|
||||
return s;
|
||||
}
|
||||
|
||||
char *real::ita2eng (const char *s)
|
||||
char *real ::ita2eng (const char *s)
|
||||
{
|
||||
int j = 0;
|
||||
if (s)
|
||||
@ -66,13 +66,14 @@ char *real::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;
|
||||
@ -90,46 +91,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 ());
|
||||
|
||||
@ -142,39 +143,37 @@ real& real::operator /= (const real& b)
|
||||
#endif
|
||||
|
||||
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)
|
||||
@ -236,7 +235,7 @@ char *real::string (int len, int dec, char pad) const
|
||||
}
|
||||
|
||||
// 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);
|
||||
@ -246,14 +245,14 @@ char* real::stringa (int len, int dec, char pad) const
|
||||
}
|
||||
|
||||
// Certified 75%
|
||||
char *real::literals () const
|
||||
char *real ::literals () const
|
||||
{
|
||||
const char *primi20[] =
|
||||
{"", "uno", "due", "tre", "quattro",
|
||||
"cinque", "sei", "sette", "otto",
|
||||
"nove", "dieci", "undici", "dodici",
|
||||
"tredici", "quattordici", "quindici", "sedici"
|
||||
"diciassette", "diciotto", "diciannove"};
|
||||
"tredici", "quattordici", "quindici", "sedici",
|
||||
"diciassette", "diciotto", "diciannove"};
|
||||
const char *decine[] =
|
||||
{"zero", "dieci", "venti", "trenta", "quaranta",
|
||||
"cinquanta", "sessanta", "settanta", "ottanta",
|
||||
@ -285,7 +284,7 @@ char *real::literals () const
|
||||
if (v < 0)
|
||||
v = 0;
|
||||
const int val = atoi (&r[v]);
|
||||
r.cut (v); // Elimina ultimi 3 caratteri
|
||||
r.cut (v); // Elimina ultimi 3 caratteri
|
||||
|
||||
v = val;
|
||||
if (v >= 100)
|
||||
@ -326,7 +325,7 @@ char *real::literals () const
|
||||
}
|
||||
|
||||
// Certified 75%
|
||||
char *real::points (int dec) const
|
||||
char *real ::points (int dec) const
|
||||
{
|
||||
const char *str = stringa ();
|
||||
const int neg = (*str == '-') ? 1 : 0;
|
||||
@ -341,7 +340,7 @@ char *real::points (int dec) const
|
||||
{
|
||||
if (n[dot] == '\0')
|
||||
n << ',';
|
||||
const int d = strlen (str + dot + 1); // Decimals already
|
||||
const int d = strlen (str + dot + 1); // Decimals already
|
||||
// there
|
||||
|
||||
if (d <= dec)
|
||||
@ -357,6 +356,7 @@ char *real::points (int dec) const
|
||||
return __string;
|
||||
}
|
||||
|
||||
|
||||
HIDDEN int get_picture_decimals (const TString & picture)
|
||||
{
|
||||
int decimali = 0;
|
||||
@ -371,7 +371,9 @@ HIDDEN int 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 ();
|
||||
@ -425,25 +427,28 @@ char *real::string (const char *picture) const
|
||||
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)
|
||||
{
|
||||
@ -457,10 +462,10 @@ real& real::round (int prec)
|
||||
return *this;
|
||||
}
|
||||
|
||||
real& real::ceil (int prec)
|
||||
real & real ::ceil (int prec)
|
||||
{
|
||||
double p = 1.0;
|
||||
if (prec)
|
||||
if (prec != 0)
|
||||
{
|
||||
p = ::pow (10.0, -prec);
|
||||
divdfd (ptr (), ptr (), p);
|
||||
@ -469,51 +474,52 @@ real& real::ceil (int prec)
|
||||
DEC integer;
|
||||
dint (&integer, ptr ()); // Extract the integer part
|
||||
|
||||
if (disne (ptr (), &integer)) // If different ...
|
||||
|
||||
if (disgt (ptr (), &integer)) // If positive ...
|
||||
addid (ptr (), &integer, 1); // add 1
|
||||
else
|
||||
dcpy(ptr(), &integer); // If negative
|
||||
|
||||
if (prec)
|
||||
if (prec != 0)
|
||||
muldfd (ptr (), ptr (), p);
|
||||
|
||||
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;
|
||||
@ -521,42 +527,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;
|
||||
@ -564,7 +570,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;
|
||||
@ -572,12 +578,12 @@ 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);
|
||||
// return disgt(__tmp_real.ptr(), b.ptr());
|
||||
@ -585,13 +591,13 @@ bool operator > (double a, const real& b)
|
||||
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);
|
||||
@ -600,13 +606,13 @@ bool operator < (double a, const real& b)
|
||||
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);
|
||||
@ -615,13 +621,13 @@ bool operator >= (double a, const real& b)
|
||||
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);
|
||||
@ -630,130 +636,128 @@ bool operator <= (double a, const real& b)
|
||||
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;
|
||||
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 ());
|
||||
@ -789,7 +793,7 @@ real TDistrib ::get ()
|
||||
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