*** empty log message ***
git-svn-id: svn://10.65.10.50/trunk@18 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
65d9f0ec14
commit
3f5ce20380
@ -77,25 +77,30 @@ class TSpreadsheet:public TWindow
|
|||||||
{
|
{
|
||||||
return _mask;
|
return _mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
int items () const
|
int items () const
|
||||||
{
|
{
|
||||||
return _str.items ();
|
return _str.items ();
|
||||||
}
|
}
|
||||||
|
|
||||||
int columns () const
|
int columns () const
|
||||||
{
|
{
|
||||||
return _columns;
|
return _columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dirty () const
|
bool dirty () const
|
||||||
{
|
{
|
||||||
return _dirty;
|
return _dirty;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_notify (SPREADSHEET_NOTIFY n)
|
void set_notify (SPREADSHEET_NOTIFY n)
|
||||||
{
|
{
|
||||||
_notify = n;
|
_notify = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_dirty (bool spork = TRUE)
|
void set_dirty (bool spork = TRUE)
|
||||||
{_dirty = spork;
|
{
|
||||||
|
_dirty = spork;
|
||||||
}
|
}
|
||||||
|
|
||||||
TSpreadsheet (short x, short y, short dx, short dy, const char *maskname, int maskno,
|
TSpreadsheet (short x, short y, short dx, short dy, const char *maskname, int maskno,
|
||||||
@ -209,7 +214,8 @@ TSpreadsheet ::TSpreadsheet (short x, short y, short dx, short dy,
|
|||||||
{
|
{
|
||||||
const int cid = FIRST_FIELD + i; // Column & Field ID
|
const int cid = FIRST_FIELD + i; // Column & Field ID
|
||||||
const TMask_field * f = field (cid); // Field on mask
|
const TMask_field * f = field (cid); // Field on mask
|
||||||
const int w = width[i] + (f->has_query ()? 2 : 0); // Column width
|
const int w = width[i] + (f->has_query ()? 2 : 0); // Column
|
||||||
|
// width
|
||||||
|
|
||||||
long flags = XI_ATR_EDITMENU | XI_ATR_AUTOSCROLL;
|
long flags = XI_ATR_EDITMENU | XI_ATR_AUTOSCROLL;
|
||||||
if (f->class_id () == CLASS_REAL_FIELD) flags |= XI_ATR_RJUST;
|
if (f->class_id () == CLASS_REAL_FIELD) flags |= XI_ATR_RJUST;
|
||||||
|
File diff suppressed because it is too large
Load Diff
321
include/real.cpp
321
include/real.cpp
@ -2,7 +2,10 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <gm.h>
|
#include <gm.h>
|
||||||
|
|
||||||
extern "C" { double pow(double, double); } // Should be #include <math.h>
|
extern "C"
|
||||||
|
{
|
||||||
|
double pow (double, double);
|
||||||
|
} // Should be #include <math.h>
|
||||||
|
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <real.h>
|
#include <real.h>
|
||||||
@ -12,31 +15,41 @@ HIDDEN char __string[80];
|
|||||||
const real ZERO (0.0);
|
const real ZERO (0.0);
|
||||||
|
|
||||||
real ::real ()
|
real ::real ()
|
||||||
{ dzero(ptr()); }
|
{
|
||||||
|
dzero (ptr ());
|
||||||
|
}
|
||||||
|
|
||||||
real ::real (const real & b)
|
real ::real (const real & b)
|
||||||
{ dcpy(ptr(), b.ptr()); }
|
{
|
||||||
|
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)
|
dftodr (ptr (), a, 9); // Round the number (1.0 is NOT 0.999999999)
|
||||||
|
|
||||||
deltrz (ptr (), ptr ()); // Delete Trailing zeroes
|
deltrz (ptr (), ptr ()); // Delete Trailing zeroes
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char* real::eng2ita(char* s)
|
char *real ::
|
||||||
|
eng2ita (char *s)
|
||||||
{
|
{
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
char *dot = strchr (s, '.');
|
char *dot = strchr (s, '.');
|
||||||
if (dot) *dot = ',';
|
if (dot)
|
||||||
|
*dot = ',';
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* real::ita2eng(const char* s)
|
char *real ::
|
||||||
|
ita2eng (const char *s)
|
||||||
{
|
{
|
||||||
int j = 0;
|
int j = 0;
|
||||||
if (s) for (int i = 0; s[i]; i++)
|
if (s)
|
||||||
|
for (int i = 0; s[i]; i++)
|
||||||
{
|
{
|
||||||
switch (s[i])
|
switch (s[i])
|
||||||
{
|
{
|
||||||
@ -55,12 +68,15 @@ char* real::ita2eng(const char* s)
|
|||||||
return __string;
|
return __string;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool real::is_real(const char* s)
|
bool real ::
|
||||||
|
is_real (const char *s)
|
||||||
{
|
{
|
||||||
bool ok = FALSE;
|
bool ok = FALSE;
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
while(*s == ' ') s++; // Remove leading spaces before atod
|
while (*s == ' ')
|
||||||
|
s++; // Remove leading spaces before atod
|
||||||
|
|
||||||
ok = atod (__tmp_real.ptr (), (char *) s) != GM_NULL;
|
ok = atod (__tmp_real.ptr (), (char *) s) != GM_NULL;
|
||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
@ -69,7 +85,8 @@ bool real::is_real(const char* s)
|
|||||||
real ::real (const char *s)
|
real ::real (const char *s)
|
||||||
{
|
{
|
||||||
if (s)
|
if (s)
|
||||||
while(*s == ' ') s++; // Remove leading spaces before atod
|
while (*s == ' ')
|
||||||
|
s++; // Remove leading spaces before atod
|
||||||
|
|
||||||
if (s && *s)
|
if (s && *s)
|
||||||
atod (ptr (), (char *) s);
|
atod (ptr (), (char *) s);
|
||||||
@ -131,91 +148,106 @@ real& real::operator /=(const real& b)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
TObject* real::dup() const
|
TObject *real ::
|
||||||
{ return new real(*this); }
|
dup ()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return new real (*this);
|
||||||
|
}
|
||||||
|
|
||||||
bool real::is_zero() const
|
bool real ::is_zero ()
|
||||||
|
const
|
||||||
{
|
{
|
||||||
return diszero (ptr ());
|
return diszero (ptr ());
|
||||||
}
|
}
|
||||||
|
|
||||||
int real::sign() const
|
int real ::sign ()
|
||||||
{ return dsign(ptr()); }
|
const
|
||||||
|
{
|
||||||
|
return dsign (ptr ());
|
||||||
|
}
|
||||||
|
|
||||||
|
real real ::operator - ()
|
||||||
real real::operator -() const
|
const
|
||||||
{
|
{
|
||||||
real n;
|
real n;
|
||||||
dchgs (n.ptr (), ptr ());
|
dchgs (n.ptr (), ptr ());
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int real ::integer ()
|
||||||
int real::integer() const
|
const
|
||||||
{ return dtoi(ptr()); }
|
{
|
||||||
|
return dtoi (ptr ());
|
||||||
|
}
|
||||||
|
|
||||||
// Certified 91%
|
// 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;
|
__tmp_real = *this;
|
||||||
if (dec != UNDEFINED) __tmp_real.round(dec);
|
if (dec != UNDEFINED)
|
||||||
else deltrz(__tmp_real.ptr(), __tmp_real.ptr());
|
__tmp_real.round (dec);
|
||||||
|
else
|
||||||
|
deltrz (__tmp_real.ptr (), __tmp_real.ptr ());
|
||||||
|
|
||||||
// if (len == 0)
|
// if (len == 0)
|
||||||
dtoa (__string, __tmp_real.ptr ());
|
dtoa (__string, __tmp_real.ptr ());
|
||||||
/*
|
/*
|
||||||
else
|
* else
|
||||||
{
|
* {
|
||||||
char f[16];
|
* char f[16];
|
||||||
if (dec == UNDEFINED) sprintf(f, "%%%dt", len);
|
* if (dec == UNDEFINED) sprintf(f, "%%%dt", len);
|
||||||
else
|
* else
|
||||||
sprintf(f, "%%%d.%dt", len, dec);
|
* sprintf(f, "%%%d.%dt", len, dec);
|
||||||
dsprintf(__string, f, __tmp_real.ptr());
|
* dsprintf(__string, f, __tmp_real.ptr());
|
||||||
}
|
* }
|
||||||
|
*
|
||||||
if (dec <= 0 || dec == UNDEFINED) // Toglie una eventuale parte decimale .00
|
* if (dec <= 0 || dec == UNDEFINED) // Toglie una eventuale parte decimale .00
|
||||||
{
|
* {
|
||||||
if (dot)
|
* if (dot)
|
||||||
{
|
* {
|
||||||
for (const char* z = dot + 1; *z; z++)
|
* for (const char* z = dot + 1; *z; z++)
|
||||||
if (*z != '0') break;
|
* if (*z != '0') break;
|
||||||
if (!*z) *dot = '\0';
|
* if (!*z) *dot = '\0';
|
||||||
}
|
* }
|
||||||
}
|
* }
|
||||||
*/
|
*/
|
||||||
int lun = strlen (__string);
|
int lun = strlen (__string);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
char* dot = strchr(__string, '.');
|
* char* dot = strchr(__string, '.');
|
||||||
|
*
|
||||||
int d = dot ? strlen(dot+1) : 0; // Decimals already there
|
* int d = dot ? strlen(dot+1) : 0; // Decimals already there
|
||||||
|
*
|
||||||
if (d < dec)
|
* if (d < dec)
|
||||||
{
|
* {
|
||||||
if (dot == NULL) __string[lun++] = '.');
|
* if (dot == NULL) __string[lun++] = '.');
|
||||||
for (;d < dec; d++) __string[lun++] = '0';
|
* for (;d < dec; d++) __string[lun++] = '0';
|
||||||
__string[lun] = '\0';
|
* __string[lun] = '\0';
|
||||||
} else
|
* } else
|
||||||
if (dec >= 0 && d > dec)
|
* if (dec >= 0 && d > dec)
|
||||||
{
|
* {
|
||||||
*(dot+dec+(dec>0)) = '\0';
|
* *(dot+dec+(dec>0)) = '\0';
|
||||||
lun = strlen(__string);
|
* lun = strlen(__string);
|
||||||
}
|
* }
|
||||||
*/
|
*/
|
||||||
if (lun < len)
|
if (lun < len)
|
||||||
{
|
{
|
||||||
const int delta = len - lun;
|
const int delta = len - lun;
|
||||||
for (int i = lun; i >= 0; i--)
|
for (int i = lun; i >= 0; i--)
|
||||||
__string[i + delta] = __string[i];
|
__string[i + delta] = __string[i];
|
||||||
for (i = 0; i < delta; i++) __string[i] = pad;
|
for (i = 0; i < delta; i++)
|
||||||
|
__string[i] = pad;
|
||||||
}
|
}
|
||||||
|
|
||||||
return __string;
|
return __string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Certified 99%
|
// 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);
|
string (len, dec, pad);
|
||||||
@ -224,27 +256,32 @@ char* real::stringa(int len, int dec, char pad) const
|
|||||||
return __string;
|
return __string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Certified 75%
|
// Certified 75%
|
||||||
char* real::literals() const
|
char *real ::literals ()
|
||||||
|
const
|
||||||
{
|
{
|
||||||
const char* primi20[] = { "", "uno","due","tre","quattro",
|
const char *primi20[] =
|
||||||
|
{"", "uno", "due", "tre", "quattro",
|
||||||
"cinque", "sei", "sette", "otto",
|
"cinque", "sei", "sette", "otto",
|
||||||
"nove", "dieci", "undici", "dodici",
|
"nove", "dieci", "undici", "dodici",
|
||||||
"tredici", "quattordici", "quindici", "sedici"
|
"tredici", "quattordici", "quindici", "sedici"
|
||||||
"diciassette", "diciotto", "diciannove"};
|
"diciassette", "diciotto", "diciannove"};
|
||||||
const char* decine[] = { "zero", "dieci", "venti", "trenta", "quaranta",
|
const char *decine[] =
|
||||||
|
{"zero", "dieci", "venti", "trenta", "quaranta",
|
||||||
"cinquanta", "sessanta", "settanta", "ottanta",
|
"cinquanta", "sessanta", "settanta", "ottanta",
|
||||||
"novanta", "cento"};
|
"novanta", "cento"};
|
||||||
const char* uni[] = { "uno", "mille", "unmilione", "unmiliardo" };
|
const char *uni[] =
|
||||||
|
{"uno", "mille", "unmilione", "unmiliardo"};
|
||||||
|
|
||||||
const char* potenze[] = { "", "mila", "milioni", "miliardi" };
|
const char *potenze[] =
|
||||||
|
{"", "mila", "milioni", "miliardi"};
|
||||||
|
|
||||||
__tmp_real = *this;
|
__tmp_real = *this;
|
||||||
__tmp_real.round (0);
|
__tmp_real.round (0);
|
||||||
TString r (__tmp_real.string (0, 0));
|
TString r (__tmp_real.string (0, 0));
|
||||||
const bool negativo = r[0] == '-';
|
const bool negativo = r[0] == '-';
|
||||||
if (negativo) r.ltrim(1);
|
if (negativo)
|
||||||
|
r.ltrim (1);
|
||||||
|
|
||||||
TFixed_string risultato (__string, 80);
|
TFixed_string risultato (__string, 80);
|
||||||
risultato.cut (0);
|
risultato.cut (0);
|
||||||
@ -254,9 +291,11 @@ char* real::literals() const
|
|||||||
for (int migliaia = 0;; migliaia++)
|
for (int migliaia = 0;; migliaia++)
|
||||||
{
|
{
|
||||||
int v = r.len () - 3;
|
int v = r.len () - 3;
|
||||||
if (v < -2) break;
|
if (v < -2)
|
||||||
|
break;
|
||||||
|
|
||||||
if (v < 0) v = 0;
|
if (v < 0)
|
||||||
|
v = 0;
|
||||||
const int val = atoi (&r[v]);
|
const int val = atoi (&r[v]);
|
||||||
r.cut (v); // Elimina ultimi 3 caratteri
|
r.cut (v); // Elimina ultimi 3 caratteri
|
||||||
|
|
||||||
@ -264,8 +303,10 @@ char* real::literals() const
|
|||||||
if (v >= 100)
|
if (v >= 100)
|
||||||
{
|
{
|
||||||
const int c = v / 100;
|
const int c = v / 100;
|
||||||
if (c > 1) centinaia = primi20[c];
|
if (c > 1)
|
||||||
else centinaia.cut(0);
|
centinaia = primi20[c];
|
||||||
|
else
|
||||||
|
centinaia.cut (0);
|
||||||
v -= c * 100;
|
v -= c * 100;
|
||||||
centinaia << "cento";
|
centinaia << "cento";
|
||||||
}
|
}
|
||||||
@ -278,23 +319,28 @@ char* real::literals() const
|
|||||||
if (v != 1)
|
if (v != 1)
|
||||||
{
|
{
|
||||||
centinaia << primi20[v] << potenze[migliaia];
|
centinaia << primi20[v] << potenze[migliaia];
|
||||||
} else
|
}
|
||||||
if (val > 1)
|
else if (val > 1)
|
||||||
{
|
{
|
||||||
if (d > 1) centinaia.cut(centinaia.len()-1);
|
if (d > 1)
|
||||||
|
centinaia.cut (centinaia.len () - 1);
|
||||||
centinaia << "un" << (migliaia ? potenze[migliaia] : "o");
|
centinaia << "un" << (migliaia ? potenze[migliaia] : "o");
|
||||||
} else centinaia = uni[migliaia];
|
}
|
||||||
|
else
|
||||||
|
centinaia = uni[migliaia];
|
||||||
|
|
||||||
risultato.insert (centinaia, 0);
|
risultato.insert (centinaia, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (negativo) risultato.insert("meno", 0);
|
if (negativo)
|
||||||
|
risultato.insert ("meno", 0);
|
||||||
return __string;
|
return __string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Certified 75%
|
// Certified 75%
|
||||||
char* real::points(int dec) const
|
char *real ::
|
||||||
|
points (int dec)
|
||||||
|
const
|
||||||
{
|
{
|
||||||
const char *str = stringa ();
|
const char *str = stringa ();
|
||||||
const int neg = (*str == '-') ? 1 : 0;
|
const int neg = (*str == '-') ? 1 : 0;
|
||||||
@ -302,14 +348,19 @@ char* real::points(int dec) const
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
int dot = n.find (',');
|
int dot = n.find (',');
|
||||||
if (dot < 0) dot = n.len();
|
if (dot < 0)
|
||||||
|
dot = n.len ();
|
||||||
|
|
||||||
if (dec > 0)
|
if (dec > 0)
|
||||||
{
|
{
|
||||||
if (n[dot] == '\0') n << ',';
|
if (n[dot] == '\0')
|
||||||
const int d = strlen(str+dot+1); // Decimals already there
|
n << ',';
|
||||||
|
const int d = strlen (str + dot + 1); // Decimals already
|
||||||
|
// there
|
||||||
|
|
||||||
if (d <= dec)
|
if (d <= dec)
|
||||||
for (i = d; i < dec; i++) n << '0';
|
for (i = d; i < dec; i++)
|
||||||
|
n << '0';
|
||||||
else
|
else
|
||||||
n.cut (dot + dec + 1);
|
n.cut (dot + dec + 1);
|
||||||
}
|
}
|
||||||
@ -320,8 +371,8 @@ char* real::points(int dec) const
|
|||||||
return __string;
|
return __string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HIDDEN int
|
||||||
HIDDEN int get_picture_decimals(const TString& picture)
|
get_picture_decimals (const TString & picture)
|
||||||
{
|
{
|
||||||
int decimali = 0;
|
int decimali = 0;
|
||||||
const int virgola = picture.find (',');
|
const int virgola = picture.find (',');
|
||||||
@ -329,17 +380,22 @@ HIDDEN int get_picture_decimals(const TString& picture)
|
|||||||
{
|
{
|
||||||
const int len = picture.len ();
|
const int len = picture.len ();
|
||||||
for (int i = virgola + 1; i < len; i++)
|
for (int i = virgola + 1; i < len; i++)
|
||||||
if (strchr("#@~", picture[i])) decimali++;
|
if (strchr ("#@~", picture[i]))
|
||||||
|
decimali++;
|
||||||
}
|
}
|
||||||
return decimali;
|
return decimali;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *real ::
|
||||||
char* real::string(const char* picture) const
|
string (const char *picture)
|
||||||
|
const
|
||||||
{
|
{
|
||||||
if (*picture == '\0') return string();
|
if (*picture == '\0')
|
||||||
if (*picture == '.') return points(atoi(picture+1));
|
return string ();
|
||||||
if (strcmp(picture, "LETTERE") == 0) return literals();
|
if (*picture == '.')
|
||||||
|
return points (atoi (picture + 1));
|
||||||
|
if (strcmp (picture, "LETTERE") == 0)
|
||||||
|
return literals ();
|
||||||
|
|
||||||
TString v (string ());
|
TString v (string ());
|
||||||
TString f (picture);
|
TString f (picture);
|
||||||
@ -348,7 +404,8 @@ char* real::string(const char* picture) const
|
|||||||
const int virgola = v.find ('.');
|
const int virgola = v.find ('.');
|
||||||
int decimali = (virgola >= 0) ? v.len () - virgola - 1 : 0;
|
int decimali = (virgola >= 0) ? v.len () - virgola - 1 : 0;
|
||||||
|
|
||||||
for ( ;voluti > decimali; decimali++) v << '@';
|
for (; voluti > decimali; decimali++)
|
||||||
|
v << '@';
|
||||||
if (voluti < decimali)
|
if (voluti < decimali)
|
||||||
v.cut (virgola + voluti + (voluti > 0));
|
v.cut (virgola + voluti + (voluti > 0));
|
||||||
|
|
||||||
@ -359,9 +416,12 @@ char* real::string(const char* picture) const
|
|||||||
if (strchr ("#@~", z))
|
if (strchr ("#@~", z))
|
||||||
{
|
{
|
||||||
char c = v[j--];
|
char c = v[j--];
|
||||||
if (v[j] == '.') j--;
|
if (v[j] == '.')
|
||||||
if (z == '~') c = ' '; else
|
j--;
|
||||||
if (c == '@') c = (z == '@') ? '0' : ' ';
|
if (z == '~')
|
||||||
|
c = ' ';
|
||||||
|
else if (c == '@')
|
||||||
|
c = (z == '@') ? '0' : ' ';
|
||||||
z = c;
|
z = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -370,21 +430,24 @@ char* real::string(const char* picture) const
|
|||||||
{
|
{
|
||||||
case '#':
|
case '#':
|
||||||
case '~':
|
case '~':
|
||||||
case '.': f[i] = ' '; break;
|
case '.':
|
||||||
case '@': f[i] = '0'; break;
|
f[i] = ' ';
|
||||||
default :break;
|
break;
|
||||||
|
case '@':
|
||||||
|
f[i] = '0';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return strcpy (__string, f);
|
return strcpy (__string, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ostream & operator << (ostream & out, const real & a)
|
ostream & operator << (ostream & out, const real & a)
|
||||||
|
|
||||||
{
|
{
|
||||||
return out << a.string ();
|
return out << a.string ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
istream & operator >> (istream & in, real & a)
|
istream & operator >> (istream & in, real & a)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -393,13 +456,12 @@ istream& operator >>(istream& in, real& a)
|
|||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int real ::
|
||||||
int real::precision()
|
precision ()
|
||||||
{
|
{
|
||||||
return dprec (ptr ());
|
return dprec (ptr ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real & real ::round (int prec)
|
real & real ::round (int prec)
|
||||||
{
|
{
|
||||||
if (prec < 0)
|
if (prec < 0)
|
||||||
@ -414,7 +476,6 @@ real& real::round(int prec)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real & real ::ceil (int prec)
|
real & real ::ceil (int prec)
|
||||||
{
|
{
|
||||||
double p = 1.0;
|
double p = 1.0;
|
||||||
@ -424,8 +485,11 @@ real& real::ceil(int prec)
|
|||||||
divdfd (ptr (), ptr (), p);
|
divdfd (ptr (), ptr (), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEC integer; dint(&integer, ptr()); // Extract the integer part
|
DEC integer;
|
||||||
|
dint (&integer, ptr ()); // Extract the integer part
|
||||||
|
|
||||||
if (disne (ptr (), &integer)) // If different ...
|
if (disne (ptr (), &integer)) // If different ...
|
||||||
|
|
||||||
addid (ptr (), &integer, 1); // add 1
|
addid (ptr (), &integer, 1); // add 1
|
||||||
|
|
||||||
if (prec)
|
if (prec)
|
||||||
@ -434,14 +498,12 @@ real& real::ceil(int prec)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real & real ::trunc (int prec)
|
real & real ::trunc (int prec)
|
||||||
{
|
{
|
||||||
dtrunc (ptr (), ptr (), prec);
|
dtrunc (ptr (), ptr (), prec);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real operator + (const real & a, const real & b)
|
real operator + (const real & a, const real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -449,7 +511,6 @@ real operator +(const real& a, const real& b)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real operator + (double a, const real & b)
|
real operator + (double a, const real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -457,7 +518,6 @@ real operator +(double a, const real& b)
|
|||||||
return __tmp_real += b;
|
return __tmp_real += b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real operator + (const real & a, double b)
|
real operator + (const real & a, double b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -465,7 +525,6 @@ real operator +(const real& a, double b)
|
|||||||
return __tmp_real += b;
|
return __tmp_real += b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real operator - (const real & a, const real & b)
|
real operator - (const real & a, const real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -473,7 +532,6 @@ real operator -(const real& a, const real& b)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real operator - (double a, const real & b)
|
real operator - (double a, const real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -482,7 +540,6 @@ real operator -(double a, const real& b)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real operator - (const real & a, double b)
|
real operator - (const real & a, double b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -490,7 +547,6 @@ real operator -(const real& a, double b)
|
|||||||
return __tmp_real -= a;
|
return __tmp_real -= a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real operator *(const real & a, const real & b)
|
real operator *(const real & a, const real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -498,7 +554,6 @@ real operator *(const real& a, const real& b)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real operator *(double a, const real & b)
|
real operator *(double a, const real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -506,7 +561,6 @@ real operator *(double a, const real& b)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real operator *(const real & a, double b)
|
real operator *(const real & a, double b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -514,7 +568,6 @@ real operator *(const real& a, double b)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real operator / (const real & a, const real & b)
|
real operator / (const real & a, const real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -522,7 +575,6 @@ real operator /(const real& a, const real& b)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real operator / (double a, const real & b)
|
real operator / (double a, const real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -531,7 +583,6 @@ real operator /(double a, const real& b)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real operator / (const real & a, double b)
|
real operator / (const real & a, double b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -540,13 +591,11 @@ real operator /(const real& a, double b)
|
|||||||
return __tmp_real;
|
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 ());
|
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);
|
||||||
@ -555,14 +604,12 @@ bool operator >(double a, const real& b)
|
|||||||
return a > n;
|
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 ());
|
return dislt (a.ptr (), b.ptr ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool operator < (double a, const real & b)
|
bool operator < (double a, const real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -572,14 +619,12 @@ bool operator <(double a, const real& b)
|
|||||||
return a < n;
|
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 ());
|
return disge (a.ptr (), b.ptr ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool operator >= (double a, const real & b)
|
bool operator >= (double a, const real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -589,14 +634,12 @@ bool operator >=(double a, const real& b)
|
|||||||
return a >= n;
|
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 ());
|
return disle (a.ptr (), b.ptr ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool operator <= (double a, const real & b)
|
bool operator <= (double a, const real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -606,27 +649,23 @@ bool operator <=(double a, const real& b)
|
|||||||
return a <= n;
|
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 ());
|
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 ());
|
const double n = dtodf (b.ptr ());
|
||||||
return a == n;
|
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 ());
|
return !diseq (a.ptr (), b.ptr ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool operator != (double a, const real & b)
|
bool operator != (double a, const real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -634,7 +673,6 @@ bool operator !=(double a, const real& b)
|
|||||||
return a != n;
|
return a != n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real operator % (const real & a, const long b)
|
real operator % (const real & a, const long b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -642,14 +680,12 @@ real operator %(const real& a, const long b)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void swap (real & a, real & b)
|
void swap (real & a, real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
SwapDecimal (a.ptr (), b.ptr ());
|
SwapDecimal (a.ptr (), b.ptr ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real fnc_min (const real & a, const real & b)
|
real fnc_min (const real & a, const real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -657,7 +693,6 @@ real fnc_min(const real& a, const real& b)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real fnc_max (const real & a, const real & b)
|
real fnc_max (const real & a, const real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -665,7 +700,6 @@ real fnc_max(const real& a, const real& b)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real sqrt (const real & a)
|
real sqrt (const real & a)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -673,7 +707,6 @@ real sqrt(const real& a)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real sqr (const real & a)
|
real sqr (const real & a)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -681,7 +714,6 @@ real sqr(const real& a)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real exp10 (const real & a)
|
real exp10 (const real & a)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -689,7 +721,6 @@ real exp10(const real& a)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real pow (const real & a, const real & b)
|
real pow (const real & a, const real & b)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -697,7 +728,6 @@ real pow(const real& a, const real& b)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real exp (const real & a)
|
real exp (const real & a)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -712,7 +742,6 @@ real log10(const real& a)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real log (const real & a)
|
real log (const real & a)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -720,7 +749,6 @@ real log(const real& a)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real sin (const real & a)
|
real sin (const real & a)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -728,7 +756,6 @@ real sin(const real& a)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real cos (const real & a)
|
real cos (const real & a)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -736,7 +763,6 @@ real cos(const real& a)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real tan (const real & a)
|
real tan (const real & a)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -744,7 +770,6 @@ real tan(const real& a)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real abs (const real & a)
|
real abs (const real & a)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -752,14 +777,12 @@ real abs(const real& a)
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
// Distrib
|
// Distrib
|
||||||
// Oggetto per dividere un real in varie sue percentuali
|
// Oggetto per dividere un real in varie sue percentuali
|
||||||
// in modo che la loro somma dia sempre il real di partenza
|
// in modo che la loro somma dia sempre il real di partenza
|
||||||
// /////////////////////////////////////////////////////////
|
// /////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
void TDistrib ::add (real slice)
|
void TDistrib ::add (real slice)
|
||||||
{
|
{
|
||||||
if (slice > real (1.0))
|
if (slice > real (1.0))
|
||||||
@ -774,8 +797,12 @@ real TDistrib::get()
|
|||||||
CHECK (_current < _slices.items (), "TDistrib: too many gets");
|
CHECK (_current < _slices.items (), "TDistrib: too many gets");
|
||||||
real r = _tot * ((real &) _slices[_current++]);
|
real r = _tot * ((real &) _slices[_current++]);
|
||||||
r.round (_decs);
|
r.round (_decs);
|
||||||
if (r > _tot - _prog) { r = _tot-_prog; _prog = _tot; }
|
if (r > _tot - _prog)
|
||||||
else _prog += r;
|
{
|
||||||
|
r = _tot - _prog; _prog = _tot;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
_prog += r;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -784,5 +811,3 @@ void TDistrib::init(const real& r)
|
|||||||
_current = 0; _prog = 0;
|
_current = 0; _prog = 0;
|
||||||
_tot = r; _ready = FALSE;
|
_tot = r; _ready = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user