Aggiunta implementazione dei real tramite i long double
msksheet.* Corretta gestione focus dall'esterno allo sheet git-svn-id: svn://10.65.10.50/trunk@2043 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
f9191c118f
commit
83c7e3992e
@ -9,8 +9,6 @@
|
|||||||
#define NULL 0L
|
#define NULL 0L
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class TArray;
|
|
||||||
|
|
||||||
// @doc EXTERNAL
|
// @doc EXTERNAL
|
||||||
//
|
//
|
||||||
// @type COMPARE_FUNCTION | Prototipo funzione di confronto tra elementi della
|
// @type COMPARE_FUNCTION | Prototipo funzione di confronto tra elementi della
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <setjmp.h>
|
|
||||||
#else
|
#else
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@ -61,7 +60,12 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __LONGDOUBLE__
|
||||||
|
typedef unsigned int word;
|
||||||
|
#define ELLIPSES ...
|
||||||
|
#else
|
||||||
#include <gm.h>
|
#include <gm.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(__MSHELL_H) && !defined(FOXPRO)
|
#if !defined(__MSHELL_H) && !defined(FOXPRO)
|
||||||
#include "mshell.h"
|
#include "mshell.h"
|
||||||
@ -246,8 +250,10 @@ extern "C" {
|
|||||||
void CEndProg(void );
|
void CEndProg(void );
|
||||||
int execprog(int ,char *, ELLIPSES);
|
int execprog(int ,char *, ELLIPSES);
|
||||||
|
|
||||||
|
#ifndef __LONGDOUBLE__
|
||||||
void CEditDec(DEC *,int ,int ,char *);
|
void CEditDec(DEC *,int ,int ,char *);
|
||||||
void CConvDec(char *,DEC *);
|
void CConvDec(char *,DEC *);
|
||||||
|
#endif
|
||||||
|
|
||||||
int CIOResult(void );
|
int CIOResult(void );
|
||||||
TDitta *CGetDitta(char *);
|
TDitta *CGetDitta(char *);
|
||||||
|
@ -851,8 +851,10 @@ int CPutField(fieldname,recd,fin,recout)
|
|||||||
if ((recd->Fd[p].TypeF == Int4F) || (recd->Fd[p].TypeF == EZeroF))
|
if ((recd->Fd[p].TypeF == Int4F) || (recd->Fd[p].TypeF == EZeroF))
|
||||||
sprintf(s, frm, *((long *) fin)) ;
|
sprintf(s, frm, *((long *) fin)) ;
|
||||||
else
|
else
|
||||||
|
#ifndef __LONGDOUBLE__
|
||||||
if (recd->Fd[p].TypeF == RealF) dsprintf(s, frm, (DEC *) fin);
|
if (recd->Fd[p].TypeF == RealF) dsprintf(s, frm, (DEC *) fin);
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
if (recd->Fd[p].TypeF == WordF) sprintf(s, frm, *((unsigned *) fin)) ;
|
if (recd->Fd[p].TypeF == WordF) sprintf(s, frm, *((unsigned *) fin)) ;
|
||||||
else
|
else
|
||||||
if (recd->Fd[p].TypeF == CharF)
|
if (recd->Fd[p].TypeF == CharF)
|
||||||
|
@ -273,23 +273,23 @@ void TExpression::eval()
|
|||||||
{
|
{
|
||||||
o2 = (real&) evalstack.pop();
|
o2 = (real&) evalstack.pop();
|
||||||
o1 = (real&) evalstack.pop();
|
o1 = (real&) evalstack.pop();
|
||||||
evalstack.push(o1 + o2);
|
evalstack.push(real(o1 + o2));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _minus:
|
case _minus:
|
||||||
o2 = (real&) evalstack.pop();
|
o2 = (real&) evalstack.pop();
|
||||||
o1 = (real&) evalstack.pop();
|
o1 = (real&) evalstack.pop();
|
||||||
evalstack.push(o1 - o2);
|
evalstack.push(real(o1 - o2));
|
||||||
break;
|
break;
|
||||||
case _multiply:
|
case _multiply:
|
||||||
o2 = (real&) evalstack.pop();
|
o2 = (real&) evalstack.pop();
|
||||||
o1 = (real&) evalstack.pop();
|
o1 = (real&) evalstack.pop();
|
||||||
evalstack.push(o1 * o2);
|
evalstack.push(real(o1 * o2));
|
||||||
break;
|
break;
|
||||||
case _divide:
|
case _divide:
|
||||||
o2 = (real&) evalstack.pop();
|
o2 = (real&) evalstack.pop();
|
||||||
o1 = (real&) evalstack.pop();
|
o1 = (real&) evalstack.pop();
|
||||||
evalstack.push(o1 / o2);
|
evalstack.push(real(o1 / o2));
|
||||||
break;
|
break;
|
||||||
case _chgs:
|
case _chgs:
|
||||||
o1 = (real&) evalstack.pop();
|
o1 = (real&) evalstack.pop();
|
||||||
@ -417,31 +417,31 @@ void TExpression::eval()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _sqrt:
|
case _sqrt:
|
||||||
evalstack.push(sqrt((real&) evalstack.pop()));
|
evalstack.push(real(sqrt((real&) evalstack.pop())));
|
||||||
break;
|
break;
|
||||||
case _sqr:
|
case _sqr:
|
||||||
evalstack.push(sqr((real&) evalstack.pop()));
|
evalstack.push(real(sqr((real&) evalstack.pop())));
|
||||||
break;
|
break;
|
||||||
case _exp10:
|
case _exp10:
|
||||||
evalstack.push(exp10((real&) evalstack.pop()));
|
evalstack.push(real(exp10((real&) evalstack.pop())));
|
||||||
break;
|
break;
|
||||||
case _exp:
|
case _exp:
|
||||||
evalstack.push(exp((real&) evalstack.pop()));
|
evalstack.push(real(exp((real&) evalstack.pop())));
|
||||||
break;
|
break;
|
||||||
case _log10:
|
case _log10:
|
||||||
evalstack.push(log10((real&) evalstack.pop()));
|
evalstack.push(real(log10((real&) evalstack.pop())));
|
||||||
break;
|
break;
|
||||||
case _log:
|
case _log:
|
||||||
evalstack.push(log((real&) evalstack.pop()));
|
evalstack.push(real(log((real&) evalstack.pop())));
|
||||||
break;
|
break;
|
||||||
case _sin:
|
case _sin:
|
||||||
evalstack.push(sin((real&) evalstack.pop()));
|
evalstack.push(real(sin((real&) evalstack.pop())));
|
||||||
break;
|
break;
|
||||||
case _cos:
|
case _cos:
|
||||||
evalstack.push(cos((real&) evalstack.pop()));
|
evalstack.push(real(cos((real&) evalstack.pop())));
|
||||||
break;
|
break;
|
||||||
case _tan:
|
case _tan:
|
||||||
evalstack.push(tan((real&) evalstack.pop()));
|
evalstack.push(real(tan((real&) evalstack.pop())));
|
||||||
break;
|
break;
|
||||||
case _left:
|
case _left:
|
||||||
o2 = (real&) evalstack.pop();
|
o2 = (real&) evalstack.pop();
|
||||||
@ -467,16 +467,17 @@ void TExpression::eval()
|
|||||||
case _pow:
|
case _pow:
|
||||||
o2 = (real&) evalstack.pop();
|
o2 = (real&) evalstack.pop();
|
||||||
o1 = (real&) evalstack.pop();
|
o1 = (real&) evalstack.pop();
|
||||||
evalstack.push(pow(o1, o2));
|
evalstack.push(real(pow(o1, o2)));
|
||||||
break;
|
break;
|
||||||
|
case _min:
|
||||||
o2 = (real&)evalstack.pop();
|
o2 = (real&)evalstack.pop();
|
||||||
o1 = (real&)evalstack.pop();
|
o1 = (real&)evalstack.pop();
|
||||||
evalstack.push(fnc_min(o1, o2));
|
evalstack.push(real(fnc_min(o1, o2)));
|
||||||
break;
|
break;
|
||||||
case _max:
|
case _max:
|
||||||
o2 = (real&) evalstack.pop();
|
o2 = (real&) evalstack.pop();
|
||||||
o1 = (real&) evalstack.pop();
|
o1 = (real&) evalstack.pop();
|
||||||
evalstack.push(fnc_min(o1, o2));
|
evalstack.push(real(fnc_max(o1, o2)));
|
||||||
break;
|
break;
|
||||||
case _upper:
|
case _upper:
|
||||||
s1 = (TString&) evalstack.pop();
|
s1 = (TString&) evalstack.pop();
|
||||||
|
@ -2322,8 +2322,10 @@ bool TRectype::get_memo(const char* fieldname, TTextfile& txt) const
|
|||||||
TDate TRectype::get_date(const char* fieldname) const
|
TDate TRectype::get_date(const char* fieldname) const
|
||||||
|
|
||||||
{
|
{
|
||||||
const TRecfield f((TRectype&)*this, fieldname);
|
if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == -1)
|
||||||
return (TDate) f;
|
UNKNOWN_FIELD(num(), fieldname);
|
||||||
|
TDate d(_isam_string);
|
||||||
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef FOXPRO
|
#ifndef FOXPRO
|
||||||
@ -2372,15 +2374,13 @@ void TRectype::put(const char* fieldname, word val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TRectype::put(const char* fieldname, const real& val)
|
void TRectype::put(const char* fieldname, const real& val)
|
||||||
|
|
||||||
{
|
{
|
||||||
if (CPutField((char*) fieldname, rec_des(), val.ptr(), _rec) == -1)
|
if (CPutFieldBuff((char*) fieldname, rec_des(), (char*)(const char*)val.string(), _rec) == -1)
|
||||||
UNKNOWN_FIELD(num(), fieldname);
|
UNKNOWN_FIELD(num(), fieldname);
|
||||||
setempty(FALSE);
|
setempty(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TRectype::put(const char* fieldname, const TDate& val)
|
void TRectype::put(const char* fieldname, const TDate& val)
|
||||||
|
|
||||||
{
|
{
|
||||||
TRecfield f(*this, fieldname);
|
TRecfield f(*this, fieldname);
|
||||||
f = val.string(full);
|
f = val.string(full);
|
||||||
@ -2824,9 +2824,8 @@ TRecfield::operator const real() const
|
|||||||
|
|
||||||
TRecfield::operator TDate() const
|
TRecfield::operator TDate() const
|
||||||
{
|
{
|
||||||
static TDate d;
|
__getfieldbuff(_len, _type, _p, _isam_string);
|
||||||
__getfieldbuff( _len, _type, _p, _isam_string);
|
TDate d(_isam_string);
|
||||||
d = _isam_string;
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,19 +30,6 @@
|
|||||||
@(H) 2.3.01.130 08/10/92 Bonazzi Corretto algoritmo lettura caratteri per >128
|
@(H) 2.3.01.130 08/10/92 Bonazzi Corretto algoritmo lettura caratteri per >128
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
BOOLEAN b; /*tipo BL*/
|
|
||||||
int i; /*tipo I*/
|
|
||||||
word w; /*tipo U*/
|
|
||||||
byte by; /*tipo BY*/
|
|
||||||
long l; /*tipo E*/
|
|
||||||
DEC r; /*tipo R*/
|
|
||||||
char c; /*tipo C*/
|
|
||||||
TrDate d; /*tipo D*/
|
|
||||||
Str80 s; /*tipo A*/
|
|
||||||
} conftype;
|
|
||||||
|
|
||||||
#ifndef DOS
|
#ifndef DOS
|
||||||
struct capentry {
|
struct capentry {
|
||||||
/* @(!) 2.3.01.130 */
|
/* @(!) 2.3.01.130 */
|
||||||
@ -63,7 +50,6 @@ struct keybar {
|
|||||||
/* @(:) 2.3.01.223 */
|
/* @(:) 2.3.01.223 */
|
||||||
};
|
};
|
||||||
|
|
||||||
extern conftype _int_cf;
|
|
||||||
extern char _int_res[513];
|
extern char _int_res[513];
|
||||||
extern uchar _int_s1[256];
|
extern uchar _int_s1[256];
|
||||||
/* @(!) 2.3.01.temp */
|
/* @(!) 2.3.01.temp */
|
||||||
@ -122,6 +108,5 @@ int gettdef ( char *, uchar *);
|
|||||||
/* @(:) 2.3.01.130 */
|
/* @(:) 2.3.01.130 */
|
||||||
void initctab(struct capentry *);
|
void initctab(struct capentry *);
|
||||||
void createaut (struct capentry *);
|
void createaut (struct capentry *);
|
||||||
void putconf(int, conftype *);
|
|
||||||
Word Hl_Port(Word);
|
Word Hl_Port(Word);
|
||||||
Word getser(void);
|
Word getser(void);
|
||||||
|
@ -2403,7 +2403,7 @@ word TBoolean_field::class_id() const
|
|||||||
|
|
||||||
void TBoolean_field::create(WINDOW parent)
|
void TBoolean_field::create(WINDOW parent)
|
||||||
{
|
{
|
||||||
wincreate(WC_CHECKBOX, _prompt.len()+4, 1, _prompt, parent, 0);
|
wincreate(WC_CHECKBOX, _prompt.len()+3, 1, _prompt, parent, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TBoolean_field::set_back_color(COLOR c) const
|
void TBoolean_field::set_back_color(COLOR c) const
|
||||||
|
@ -252,7 +252,7 @@ public:
|
|||||||
void disable()
|
void disable()
|
||||||
{ enable(FALSE); }
|
{ enable(FALSE); }
|
||||||
// @cmember Controlla se un campo e' abilitato
|
// @cmember Controlla se un campo e' abilitato
|
||||||
bool enabled() const
|
virtual bool enabled() const
|
||||||
{ return _flags.enabled; }
|
{ return _flags.enabled; }
|
||||||
// @cmember Rimette lo stato di dis/abilitazione del campo a seconda di come era settato sul file
|
// @cmember Rimette lo stato di dis/abilitazione del campo a seconda di come era settato sul file
|
||||||
void enable_default();
|
void enable_default();
|
||||||
|
@ -1824,8 +1824,8 @@ void TSheet_field::highlight() const
|
|||||||
if (rows > 0)
|
if (rows > 0)
|
||||||
{
|
{
|
||||||
_sheet->_firstfocus = FALSE;
|
_sheet->_firstfocus = FALSE;
|
||||||
if (_sheet->_edit_field == NULL)
|
_sheet->set_focus_cell(_sheet->rec2row(selected()), 1);
|
||||||
_sheet->set_focus_cell(0, 1);
|
_sheet->str2mask(selected());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -1835,6 +1835,11 @@ void TSheet_field::enable(bool on)
|
|||||||
_sheet->activate(on);
|
_sheet->activate(on);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TSheet_field::enabled() const
|
||||||
|
{
|
||||||
|
return items() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
void TSheet_field::enable_column(int column, bool on)
|
void TSheet_field::enable_column(int column, bool on)
|
||||||
{
|
{
|
||||||
_sheet->enable_column(column, on);
|
_sheet->enable_column(column, on);
|
||||||
|
@ -79,6 +79,8 @@ public:
|
|||||||
virtual void reset();
|
virtual void reset();
|
||||||
// @cmember Abilita/disabilita tutto lo spreadsheet (vedi <mf TMask_field::enable>)
|
// @cmember Abilita/disabilita tutto lo spreadsheet (vedi <mf TMask_field::enable>)
|
||||||
virtual void enable(bool on);
|
virtual void enable(bool on);
|
||||||
|
// @cmember Ritorna lo stato di abilitazione dello spreadsheet (vedi <mf TMask_field::enabled>)
|
||||||
|
virtual bool enabled() const;
|
||||||
|
|
||||||
// @cmember Aggiorna le righe dello spreadsheet con i valori salvati una volta che non ci sono
|
// @cmember Aggiorna le righe dello spreadsheet con i valori salvati una volta che non ci sono
|
||||||
// piu' processi attivi
|
// piu' processi attivi
|
||||||
|
1326
include/printapp.cpp
1326
include/printapp.cpp
File diff suppressed because it is too large
Load Diff
853
include/real.cpp
853
include/real.cpp
@ -1,5 +1,300 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <real.h>
|
||||||
|
|
||||||
|
HIDDEN char __string[80];
|
||||||
|
const real ZERO (0.0);
|
||||||
|
|
||||||
|
#ifdef __LONGDOUBLE__
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// @doc EXTERNAL
|
||||||
|
|
||||||
|
real::real () : _dec(0.0)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
real::real (const real& b) : _dec(b._dec)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
real::real (long double a) : _dec(a)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
bool real::is_real (const char *s)
|
||||||
|
{
|
||||||
|
if (s && *s)
|
||||||
|
{
|
||||||
|
const long double n = _atold(s);
|
||||||
|
if (n == 0.0)
|
||||||
|
{
|
||||||
|
for(; *s; s++) if (*s != '0' && *s != ' ' && *s != '.')
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
real::real (const char *s)
|
||||||
|
{
|
||||||
|
_dec = (s && *s) ? _atold(s) : 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
real& real::operator = (const real& b)
|
||||||
|
{
|
||||||
|
_dec = b._dec;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
real& real::operator = (long double b)
|
||||||
|
{
|
||||||
|
_dec = b;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
real& real::operator += (long double b)
|
||||||
|
{
|
||||||
|
_dec += b;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
real& real::operator -= (long double b)
|
||||||
|
{
|
||||||
|
_dec -= b;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
real& real::operator *= (long double b)
|
||||||
|
{
|
||||||
|
_dec *= b;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
real& real::operator /= (long double b)
|
||||||
|
{
|
||||||
|
_dec /= b;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @mfunc Ritorna il segno del reale
|
||||||
|
//
|
||||||
|
// @rdesc Ritorna i seguenti valori:
|
||||||
|
//
|
||||||
|
// @flag <lt> 0 | Se il numero e' minore di 0
|
||||||
|
// @flag = 0 | Se il numero e' uguale a 0
|
||||||
|
// @flag <gt> 0 | Se il numero e' maggiore di 0
|
||||||
|
int real::sign () const
|
||||||
|
{
|
||||||
|
const int s = _dec > 0.0 ? +1 : (_dec < 0.0 ? -1 : 0);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
real real::operator - () const
|
||||||
|
{
|
||||||
|
real n(-_dec);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
long real::integer () const
|
||||||
|
{
|
||||||
|
return (long)floorl(_dec);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Certified 91%
|
||||||
|
// @mfunc Trasforma un reale in stringa
|
||||||
|
//
|
||||||
|
// @rdesc Ritorna la stringa nella lunghezza richiesta
|
||||||
|
char *real::string (
|
||||||
|
int len, // @parm Lunghezza della stringa (compreso decimali)
|
||||||
|
int dec, // @parm Numero di decimali (default UNDEFINED)
|
||||||
|
char pad) const // @parm Carattere di riempimento (default ' ')
|
||||||
|
// @parm char * | picture | Formato della stringa
|
||||||
|
|
||||||
|
// @syntax string (int len, int dec, char pad);
|
||||||
|
// @syntax string (const char *picture);
|
||||||
|
//
|
||||||
|
// @comm Nel primo caso ritorna una stringa lunga <p len> con <p dec> decimali e
|
||||||
|
// inserisce nella stringa stessa il carattere <p pad> nel caso la
|
||||||
|
// lunghezza richiesta sia maggiore di quella che risulterebbe per la
|
||||||
|
// completa rappresentazione del reale.
|
||||||
|
// <nl>Nel secondo caso ritorna la stringa con il formato stabilito in
|
||||||
|
// <p picture>.
|
||||||
|
|
||||||
|
{
|
||||||
|
if (dec != UNDEFINED)
|
||||||
|
{
|
||||||
|
if (len != 0)
|
||||||
|
sprintf(__string, "%*.*Lf", len, dec, _dec);
|
||||||
|
else
|
||||||
|
sprintf(__string, "%.*Lf", dec, _dec);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (len != 0)
|
||||||
|
sprintf(__string, "%*Lf", len, _dec);
|
||||||
|
else
|
||||||
|
sprintf(__string, "%Lf", _dec);
|
||||||
|
|
||||||
|
if (strchr(__string, '.') != NULL)
|
||||||
|
{
|
||||||
|
int cut = strlen (__string);
|
||||||
|
for (int i = cut-1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if (__string[i] == '0')
|
||||||
|
cut--;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(__string[i] == '.')
|
||||||
|
cut--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
__string[cut] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const int lun = strlen (__string);
|
||||||
|
if (lun < len)
|
||||||
|
{
|
||||||
|
const int delta = len - lun;
|
||||||
|
for (int i = lun; i >= 0; i--)
|
||||||
|
__string[i + delta] = __string[i];
|
||||||
|
for (i = 0; i < delta; i++)
|
||||||
|
__string[i] = pad;
|
||||||
|
}
|
||||||
|
|
||||||
|
return __string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @mfunc real& | real | round | Arrotonda al numero di decimali passati
|
||||||
|
real& real::round (
|
||||||
|
int prec) // @parm Numero di decimali a cui arrotondare il numero (default 0)
|
||||||
|
|
||||||
|
// @comm Nel caso <p prec> sia:
|
||||||
|
//
|
||||||
|
// @flag <gt> 0 | Arrotonda al decimale
|
||||||
|
// @flag = 0 | Arrotonda all'intero
|
||||||
|
// @flag <lt> 0 | Arrotonda al valore passato (es. -3 arrotonda alle mille)
|
||||||
|
{
|
||||||
|
long double p = 1.0;
|
||||||
|
if (prec != 0)
|
||||||
|
{
|
||||||
|
p = powl (10.0, prec);
|
||||||
|
_dec *= p;
|
||||||
|
}
|
||||||
|
_dec = floorl(_dec + 0.5);
|
||||||
|
if (prec != 0)
|
||||||
|
_dec /= p;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
real& real::ceil (int prec)
|
||||||
|
{
|
||||||
|
long double p = 1.0;
|
||||||
|
if (prec != 0)
|
||||||
|
{
|
||||||
|
p = powl(10.0, prec);
|
||||||
|
_dec *= p;
|
||||||
|
}
|
||||||
|
_dec = ceill(_dec);
|
||||||
|
if (prec != 0)
|
||||||
|
_dec /= p;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
real& real::trunc(int prec)
|
||||||
|
{
|
||||||
|
long double p = 1.0;
|
||||||
|
if (prec != 0)
|
||||||
|
{
|
||||||
|
p = powl(10.0, prec);
|
||||||
|
_dec *= p;
|
||||||
|
}
|
||||||
|
_dec = floorl(_dec);
|
||||||
|
if (prec != 0)
|
||||||
|
_dec /= p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// @func Scambia il numero reale <p a> con il numero real <p b>
|
||||||
|
void swap (
|
||||||
|
real& a, // @parm Primo numero da scambiare
|
||||||
|
real& b) // @parm Secondo numero da scambiare
|
||||||
|
|
||||||
|
{
|
||||||
|
const real n = a;
|
||||||
|
a = b;
|
||||||
|
b = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
long double operator%(const real& a, const real& b)
|
||||||
|
{
|
||||||
|
const long double times = floorl(a / b);
|
||||||
|
const long double resto = a - b * times;
|
||||||
|
return resto;
|
||||||
|
}
|
||||||
|
|
||||||
|
long double sqrt(long double a)
|
||||||
|
{
|
||||||
|
return sqrtl(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
long double sqr(long double a)
|
||||||
|
{
|
||||||
|
return a*a;
|
||||||
|
}
|
||||||
|
|
||||||
|
long double exp10(long double a)
|
||||||
|
{
|
||||||
|
return powl(10.0, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
long double pow(long double a, long double b)
|
||||||
|
{
|
||||||
|
return powl(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
long double exp(long double a)
|
||||||
|
{
|
||||||
|
return expl(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
long double log10(long double a)
|
||||||
|
{
|
||||||
|
return log10l(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
long double log(long double a)
|
||||||
|
{
|
||||||
|
return logl(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
long double sin(long double a)
|
||||||
|
{
|
||||||
|
return sinl(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
long double cos(long double a)
|
||||||
|
{
|
||||||
|
return cosl(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
long double tan(long double a)
|
||||||
|
{
|
||||||
|
return tanl(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
long double abs(long double a)
|
||||||
|
{
|
||||||
|
return fabsl(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
#include <gm.h>
|
#include <gm.h>
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
@ -7,12 +302,8 @@ extern "C"
|
|||||||
double pow (double, double);
|
double pow (double, double);
|
||||||
} // Should be #include <math.h>
|
} // Should be #include <math.h>
|
||||||
|
|
||||||
#include <strings.h>
|
|
||||||
#include <real.h>
|
|
||||||
|
|
||||||
HIDDEN real __tmp_real;
|
HIDDEN real __tmp_real;
|
||||||
HIDDEN char __string[80];
|
|
||||||
const real ZERO (0.0);
|
|
||||||
|
|
||||||
// @doc EXTERNAL
|
// @doc EXTERNAL
|
||||||
|
|
||||||
@ -39,40 +330,6 @@ void real::trail( )
|
|||||||
deltrz (ptr (), ptr () ); // Delete Trailing zeroes
|
deltrz (ptr (), ptr () ); // Delete Trailing zeroes
|
||||||
}
|
}
|
||||||
|
|
||||||
char *real::eng2ita (char *s)
|
|
||||||
{
|
|
||||||
if (s)
|
|
||||||
{
|
|
||||||
char *dot = strchr (s, '.');
|
|
||||||
if (dot)
|
|
||||||
*dot = ',';
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *real::ita2eng (const char *s)
|
|
||||||
{
|
|
||||||
int j = 0;
|
|
||||||
if (s)
|
|
||||||
for (int i = 0; s[i]; i++)
|
|
||||||
{
|
|
||||||
switch (s[i])
|
|
||||||
{
|
|
||||||
case ' ':
|
|
||||||
case '.':
|
|
||||||
break;
|
|
||||||
case ',':
|
|
||||||
__string[j++] = '.';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
__string[j++] = s[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
__string[j] = '\0';
|
|
||||||
return __string;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool real::is_real (const char *s)
|
bool real::is_real (const char *s)
|
||||||
{
|
{
|
||||||
bool ok = FALSE;
|
bool ok = FALSE;
|
||||||
@ -86,26 +343,6 @@ bool real::is_real (const char *s)
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool real::is_natural (const char *s)
|
|
||||||
{
|
|
||||||
bool ok = s && *s != '\0';
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
while (*s == ' ')
|
|
||||||
s++; // Remove leading spaces before
|
|
||||||
|
|
||||||
if (*s)
|
|
||||||
{
|
|
||||||
while (isdigit(*s))
|
|
||||||
s++;
|
|
||||||
ok = *s == '\0';
|
|
||||||
}
|
|
||||||
else ok = FALSE;
|
|
||||||
|
|
||||||
}
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
real::real (const char *s)
|
real::real (const char *s)
|
||||||
{
|
{
|
||||||
if (s)
|
if (s)
|
||||||
@ -118,48 +355,48 @@ real::real (const char *s)
|
|||||||
dzero (ptr ());
|
dzero (ptr ());
|
||||||
}
|
}
|
||||||
|
|
||||||
real & real::operator = (const real & b)
|
real& real::operator =(const real & b)
|
||||||
{
|
{
|
||||||
dcpy (ptr (), b.ptr ());
|
dcpy (ptr (), b.ptr ());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
real & real::operator = (double a)
|
real& real::operator =(double a)
|
||||||
{
|
{
|
||||||
const real n (a);
|
const real n (a);
|
||||||
operator = (n);
|
operator = (n);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
real & real::operator += (const real & b)
|
real& real::operator += (const real & b)
|
||||||
{
|
{
|
||||||
dadd (ptr (), ptr (), b.ptr ());
|
dadd (ptr (), ptr (), b.ptr ());
|
||||||
trail( );
|
trail( );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
real & real::operator += (double a)
|
real& real::operator += (double a)
|
||||||
{
|
{
|
||||||
adddfd (ptr (), ptr (), a);
|
adddfd (ptr (), ptr (), a);
|
||||||
trail( );
|
trail( );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
real & real::operator -= (const real & b)
|
real& real::operator -= (const real & b)
|
||||||
{
|
{
|
||||||
dsub (ptr (), ptr (), b.ptr ());
|
dsub (ptr (), ptr (), b.ptr ());
|
||||||
trail( );
|
trail( );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
real & real::operator *= (const real & b)
|
real& real::operator *= (const real & b)
|
||||||
{
|
{
|
||||||
dmul (ptr (), ptr (), b.ptr ());
|
dmul (ptr (), ptr (), b.ptr ());
|
||||||
trail( );
|
trail( );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
real & real::operator /= (const real & b)
|
real& real::operator /= (const real & b)
|
||||||
{
|
{
|
||||||
const DEC *dst = ddiv (ptr (), ptr (), b.ptr ());
|
const DEC *dst = ddiv (ptr (), ptr (), b.ptr ());
|
||||||
|
|
||||||
@ -174,11 +411,6 @@ real & real::operator /= (const real & b)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
TObject *real:: dup () const
|
|
||||||
{
|
|
||||||
return new real (*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool real::is_zero () const
|
bool real::is_zero () const
|
||||||
{
|
{
|
||||||
return diszero (ptr ());
|
return diszero (ptr ());
|
||||||
@ -252,212 +484,6 @@ char *real::string (
|
|||||||
return __string;
|
return __string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Certified 99%
|
|
||||||
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
|
|
||||||
{
|
|
||||||
const char *primi20[] =
|
|
||||||
{"", "uno", "due", "tre", "quattro",
|
|
||||||
"cinque", "sei", "sette", "otto",
|
|
||||||
"nove", "dieci", "undici", "dodici",
|
|
||||||
"tredici", "quattordici", "quindici", "sedici",
|
|
||||||
"diciassette", "diciotto", "diciannove"};
|
|
||||||
const char *decine[] =
|
|
||||||
{"zero", "dieci", "venti", "trenta", "quaranta",
|
|
||||||
"cinquanta", "sessanta", "settanta", "ottanta",
|
|
||||||
"novanta", "cento"};
|
|
||||||
const char *uni[] =
|
|
||||||
{"uno", "mille", "unmilione", "unmiliardo"};
|
|
||||||
|
|
||||||
const char *potenze[] =
|
|
||||||
{"", "mila", "milioni", "miliardi"};
|
|
||||||
|
|
||||||
__tmp_real = *this;
|
|
||||||
__tmp_real.round (0);
|
|
||||||
TString80 r (__tmp_real.string (0, 0));
|
|
||||||
const bool negativo = r[0] == '-';
|
|
||||||
if (negativo)
|
|
||||||
r.ltrim (1);
|
|
||||||
|
|
||||||
TFixed_string risultato (__string, 80);
|
|
||||||
risultato.cut (0);
|
|
||||||
|
|
||||||
TString80 centinaia;
|
|
||||||
|
|
||||||
for (int migliaia = 0;; migliaia++)
|
|
||||||
{
|
|
||||||
int v = r.len () - 3;
|
|
||||||
if (v < -2)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (v < 0)
|
|
||||||
v = 0;
|
|
||||||
const int val = atoi (&r[v]);
|
|
||||||
r.cut (v); // Elimina ultimi 3 caratteri
|
|
||||||
|
|
||||||
v = val;
|
|
||||||
if (v >= 100)
|
|
||||||
{
|
|
||||||
const int c = v / 100;
|
|
||||||
if (c > 1)
|
|
||||||
centinaia = primi20[c];
|
|
||||||
else
|
|
||||||
centinaia.cut(0);
|
|
||||||
v -= c * 100;
|
|
||||||
centinaia << "cento";
|
|
||||||
} else centinaia.cut(0);
|
|
||||||
const int d = v / 10;
|
|
||||||
if (d > 1)
|
|
||||||
{
|
|
||||||
centinaia << decine[d];
|
|
||||||
v -= d * 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (val > 0)
|
|
||||||
{
|
|
||||||
if (v != 1)
|
|
||||||
{
|
|
||||||
centinaia << primi20[v] << potenze[migliaia];
|
|
||||||
}
|
|
||||||
else if (val > 1)
|
|
||||||
{
|
|
||||||
if (d > 1)
|
|
||||||
centinaia.cut (centinaia.len() - 1);
|
|
||||||
centinaia << "un" << (migliaia ? potenze[migliaia] : "o");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
centinaia = uni[migliaia];
|
|
||||||
}
|
|
||||||
|
|
||||||
risultato.insert(centinaia, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (negativo)
|
|
||||||
risultato.insert ("meno", 0);
|
|
||||||
return __string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Certified 75%
|
|
||||||
char *real ::points (int dec) const
|
|
||||||
{
|
|
||||||
const char *str = stringa (0, dec);
|
|
||||||
const int neg = (*str == '-') ? 1 : 0;
|
|
||||||
TFixed_string n ((char *) str, 24);
|
|
||||||
int i;
|
|
||||||
|
|
||||||
int dot = n.find (',');
|
|
||||||
if (dot < 0)
|
|
||||||
dot = n.len ();
|
|
||||||
|
|
||||||
if (dec > 0)
|
|
||||||
{
|
|
||||||
if (n[dot] == '\0')
|
|
||||||
n << ',';
|
|
||||||
const int d = strlen (str + dot + 1); // Decimals already there
|
|
||||||
|
|
||||||
if (d <= dec)
|
|
||||||
for (i = d; i < dec; i++)
|
|
||||||
n << '0';
|
|
||||||
else
|
|
||||||
n.cut (dot + dec + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = dot - 3; i > neg; i -= 3)
|
|
||||||
n.insert (".", i);
|
|
||||||
|
|
||||||
return __string;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
HIDDEN int get_picture_decimals (const TString& picture)
|
|
||||||
{
|
|
||||||
int decimali = 0;
|
|
||||||
const int virgola = picture.find (',');
|
|
||||||
if (virgola >= 0)
|
|
||||||
{
|
|
||||||
const int len = picture.len ();
|
|
||||||
for (int i = virgola + 1; i < len; i++)
|
|
||||||
if (strchr ("#@~", picture[i]))
|
|
||||||
decimali++;
|
|
||||||
}
|
|
||||||
return decimali;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char *real ::string (const char *picture)
|
|
||||||
const
|
|
||||||
{
|
|
||||||
if (*picture == '\0')
|
|
||||||
return string ();
|
|
||||||
if (*picture == '.')
|
|
||||||
return points (atoi (picture + 1));
|
|
||||||
if (strcmp (picture, "LETTERE") == 0)
|
|
||||||
return literals ();
|
|
||||||
|
|
||||||
TString80 v (string());
|
|
||||||
TString80 f (picture);
|
|
||||||
|
|
||||||
const int voluti = get_picture_decimals (f);
|
|
||||||
const int virgola = v.find ('.');
|
|
||||||
int decimali = (virgola >= 0) ? v.len () - virgola - 1 : 0;
|
|
||||||
|
|
||||||
for (; voluti > decimali; decimali++)
|
|
||||||
v << '@';
|
|
||||||
if (voluti < decimali)
|
|
||||||
v.cut (virgola + voluti + (voluti > 0));
|
|
||||||
|
|
||||||
int j = v.len () - 1;
|
|
||||||
for (int i = f.len () - 1; i >= 0 && j >= 0; i--)
|
|
||||||
{
|
|
||||||
char &z = f[i];
|
|
||||||
if (strchr ("#@^", z))
|
|
||||||
{
|
|
||||||
char c = v[j--];
|
|
||||||
if (j >= 0 && v[j] == '.')
|
|
||||||
j--;
|
|
||||||
if (z == '^')
|
|
||||||
c = ' ';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (c == '@')
|
|
||||||
c = (z == '@') ? '0' : ' ';
|
|
||||||
else
|
|
||||||
if (c == '-' && f[i+1] == '.')
|
|
||||||
{
|
|
||||||
f[i+1] = '-';
|
|
||||||
c = ' ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
z = c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (; i >= 0; i--)
|
|
||||||
switch (f[i])
|
|
||||||
{
|
|
||||||
case '#':
|
|
||||||
case '^':
|
|
||||||
case '.':
|
|
||||||
f[i] = ' ';
|
|
||||||
break;
|
|
||||||
case '@':
|
|
||||||
f[i] = '0';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return strcpy (__string, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// @func ostream& | operator <lt><lt> | Permette di reindirizzare il numero
|
// @func ostream& | operator <lt><lt> | Permette di reindirizzare il numero
|
||||||
// reale per la stampa
|
// reale per la stampa
|
||||||
@ -822,11 +848,12 @@ bool operator != (double a, const real & b)
|
|||||||
//
|
//
|
||||||
// @rdesc Ritorna il resto della divisione tra due numeri
|
// @rdesc Ritorna il resto della divisione tra due numeri
|
||||||
real operator % (
|
real operator % (
|
||||||
const real & a, // @parm Primo membro della divisione
|
const real& a, // @parm Primo membro della divisione
|
||||||
const long b) // @parm Secondo membro della divisione
|
const real& b) // @parm Secondo membro della divisione
|
||||||
|
|
||||||
{
|
{
|
||||||
dmodl (__tmp_real.ptr (), a.ptr (), b);
|
const long l = b.integer();
|
||||||
|
dmodl (__tmp_real.ptr (), a.ptr (), l);
|
||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -957,6 +984,274 @@ real abs (
|
|||||||
return __tmp_real;
|
return __tmp_real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Funzioni comuni dei due real
|
||||||
|
|
||||||
|
TObject* real::dup () const
|
||||||
|
{
|
||||||
|
return new real(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *real::eng2ita (char *s)
|
||||||
|
{
|
||||||
|
if (s)
|
||||||
|
{
|
||||||
|
char *dot = strchr (s, '.');
|
||||||
|
if (dot)
|
||||||
|
*dot = ',';
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *real::ita2eng (const char *s)
|
||||||
|
{
|
||||||
|
int j = 0;
|
||||||
|
if (s)
|
||||||
|
for (int i = 0; s[i]; i++)
|
||||||
|
{
|
||||||
|
switch (s[i])
|
||||||
|
{
|
||||||
|
case ' ':
|
||||||
|
case '.':
|
||||||
|
break;
|
||||||
|
case ',':
|
||||||
|
__string[j++] = '.';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
__string[j++] = s[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
__string[j] = '\0';
|
||||||
|
return __string;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool real::is_natural (const char *s)
|
||||||
|
{
|
||||||
|
bool ok = s && *s != '\0';
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
while (*s == ' ')
|
||||||
|
s++; // Remove leading spaces before
|
||||||
|
|
||||||
|
if (*s)
|
||||||
|
{
|
||||||
|
while (isdigit(*s))
|
||||||
|
s++;
|
||||||
|
ok = *s == '\0';
|
||||||
|
}
|
||||||
|
else ok = FALSE;
|
||||||
|
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Certified 75%
|
||||||
|
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"};
|
||||||
|
const char *decine[] =
|
||||||
|
{"zero", "dieci", "venti", "trenta", "quaranta",
|
||||||
|
"cinquanta", "sessanta", "settanta", "ottanta",
|
||||||
|
"novanta", "cento"};
|
||||||
|
const char *uni[] =
|
||||||
|
{"uno", "mille", "unmilione", "unmiliardo"};
|
||||||
|
|
||||||
|
const char *potenze[] =
|
||||||
|
{"", "mila", "milioni", "miliardi"};
|
||||||
|
|
||||||
|
real tmp_real = *this;
|
||||||
|
tmp_real.round();
|
||||||
|
|
||||||
|
TString80 r (tmp_real.string (0, 0));
|
||||||
|
const bool negativo = r[0] == '-';
|
||||||
|
if (negativo)
|
||||||
|
r.ltrim (1);
|
||||||
|
|
||||||
|
TFixed_string risultato (__string, 80);
|
||||||
|
risultato.cut (0);
|
||||||
|
|
||||||
|
TString80 centinaia;
|
||||||
|
|
||||||
|
for (int migliaia = 0;; migliaia++)
|
||||||
|
{
|
||||||
|
int v = r.len () - 3;
|
||||||
|
if (v < -2)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (v < 0)
|
||||||
|
v = 0;
|
||||||
|
const int val = atoi (&r[v]);
|
||||||
|
r.cut (v); // Elimina ultimi 3 caratteri
|
||||||
|
|
||||||
|
v = val;
|
||||||
|
if (v >= 100)
|
||||||
|
{
|
||||||
|
const int c = v / 100;
|
||||||
|
if (c > 1)
|
||||||
|
centinaia = primi20[c];
|
||||||
|
else
|
||||||
|
centinaia.cut(0);
|
||||||
|
v -= c * 100;
|
||||||
|
centinaia << "cento";
|
||||||
|
} else centinaia.cut(0);
|
||||||
|
const int d = v / 10;
|
||||||
|
if (d > 1)
|
||||||
|
{
|
||||||
|
centinaia << decine[d];
|
||||||
|
v -= d * 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val > 0)
|
||||||
|
{
|
||||||
|
if (v != 1)
|
||||||
|
{
|
||||||
|
centinaia << primi20[v] << potenze[migliaia];
|
||||||
|
}
|
||||||
|
else if (val > 1)
|
||||||
|
{
|
||||||
|
if (d > 1)
|
||||||
|
centinaia.cut (centinaia.len() - 1);
|
||||||
|
centinaia << "un" << (migliaia ? potenze[migliaia] : "o");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
centinaia = uni[migliaia];
|
||||||
|
}
|
||||||
|
|
||||||
|
risultato.insert(centinaia, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (negativo)
|
||||||
|
risultato.insert ("meno", 0);
|
||||||
|
return __string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Certified 75%
|
||||||
|
char* real::points (int dec) const
|
||||||
|
{
|
||||||
|
const char *str = stringa (0, dec);
|
||||||
|
const int neg = (*str == '-') ? 1 : 0;
|
||||||
|
TFixed_string n ((char *)str, 24);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
int dot = n.find (',');
|
||||||
|
if (dot < 0)
|
||||||
|
dot = n.len ();
|
||||||
|
|
||||||
|
if (dec > 0)
|
||||||
|
{
|
||||||
|
if (n[dot] == '\0')
|
||||||
|
n << ',';
|
||||||
|
const int d = strlen (str + dot + 1); // Decimals already there
|
||||||
|
|
||||||
|
if (d <= dec)
|
||||||
|
for (i = d; i < dec; i++)
|
||||||
|
n << '0';
|
||||||
|
else
|
||||||
|
n.cut (dot + dec + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = dot - 3; i > neg; i -= 3)
|
||||||
|
n.insert (".", i);
|
||||||
|
|
||||||
|
return __string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
HIDDEN int get_picture_decimals (const TString& picture)
|
||||||
|
{
|
||||||
|
int decimali = 0;
|
||||||
|
const int virgola = picture.find (',');
|
||||||
|
if (virgola >= 0)
|
||||||
|
{
|
||||||
|
const int len = picture.len ();
|
||||||
|
for (int i = virgola + 1; i < len; i++)
|
||||||
|
if (strchr ("#@~", picture[i]))
|
||||||
|
decimali++;
|
||||||
|
}
|
||||||
|
return decimali;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* real::string(const char *picture) const
|
||||||
|
{
|
||||||
|
if (*picture == '\0')
|
||||||
|
return string ();
|
||||||
|
if (*picture == '.')
|
||||||
|
return points (atoi (picture + 1));
|
||||||
|
if (strcmp (picture, "LETTERE") == 0)
|
||||||
|
return literals ();
|
||||||
|
|
||||||
|
TString80 v (string());
|
||||||
|
TString80 f (picture);
|
||||||
|
|
||||||
|
const int voluti = get_picture_decimals (f);
|
||||||
|
const int virgola = v.find ('.');
|
||||||
|
int decimali = (virgola >= 0) ? v.len () - virgola - 1 : 0;
|
||||||
|
|
||||||
|
for (; voluti > decimali; decimali++)
|
||||||
|
v << '@';
|
||||||
|
if (voluti < decimali)
|
||||||
|
v.cut (virgola + voluti + (voluti > 0));
|
||||||
|
|
||||||
|
int j = v.len () - 1;
|
||||||
|
for (int i = f.len () - 1; i >= 0 && j >= 0; i--)
|
||||||
|
{
|
||||||
|
char &z = f[i];
|
||||||
|
if (strchr ("#@^", z))
|
||||||
|
{
|
||||||
|
char c = v[j--];
|
||||||
|
if (j >= 0 && v[j] == '.')
|
||||||
|
j--;
|
||||||
|
if (z == '^')
|
||||||
|
c = ' ';
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (c == '@')
|
||||||
|
c = (z == '@') ? '0' : ' ';
|
||||||
|
else
|
||||||
|
if (c == '-' && f[i+1] == '.')
|
||||||
|
{
|
||||||
|
f[i+1] = '-';
|
||||||
|
c = ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
z = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (; i >= 0; i--)
|
||||||
|
switch (f[i])
|
||||||
|
{
|
||||||
|
case '#':
|
||||||
|
case '^':
|
||||||
|
case '.':
|
||||||
|
f[i] = ' ';
|
||||||
|
break;
|
||||||
|
case '@':
|
||||||
|
f[i] = '0';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return strcpy (__string, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Certified 99%
|
||||||
|
char *real ::stringa (int len, int dec, char pad) const
|
||||||
|
|
||||||
|
{
|
||||||
|
string (len, dec, pad);
|
||||||
|
if (dec > 0 || dec == UNDEFINED)
|
||||||
|
eng2ita (__string);
|
||||||
|
return __string;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
// Distrib
|
// Distrib
|
||||||
// Oggetto per dividere un real in varie sue percentuali
|
// Oggetto per dividere un real in varie sue percentuali
|
||||||
|
131
include/real.h
131
include/real.h
@ -1,21 +1,127 @@
|
|||||||
#ifndef __REAL_H
|
#ifndef __REAL_H
|
||||||
#define __REAL_H
|
#define __REAL_H
|
||||||
|
|
||||||
#ifndef GMDOTH
|
#ifndef __STRINGS_H
|
||||||
#include <gmsys1.h>
|
#include <strings.h>
|
||||||
#include <gfd.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __LONGDOUBLE__
|
||||||
|
|
||||||
|
// @doc EXTERNAL
|
||||||
|
|
||||||
|
// @class real | Classe per la gestione dei numeri reali
|
||||||
|
//
|
||||||
|
// @base public | TObject
|
||||||
|
class real : public TObject
|
||||||
|
{
|
||||||
|
// @access Private Member
|
||||||
|
|
||||||
|
// @cmember Numero reale
|
||||||
|
long double _dec;
|
||||||
|
|
||||||
|
// @access Protected Member
|
||||||
|
protected:
|
||||||
|
// @cmember Duplica il numero reale (vedi classe <c TObject>)
|
||||||
|
virtual TObject* dup() const;
|
||||||
|
// @cmember Traduce in lettere il numero reale
|
||||||
|
char* literals() const;
|
||||||
|
// @cmember Inserisce i punti separatori delle migliaia e riempe i decimali
|
||||||
|
// alla lunghezza passata (es: 3.000,20)
|
||||||
|
char* points(int decimals = 0) const;
|
||||||
|
|
||||||
|
// @access Public Member
|
||||||
|
public:
|
||||||
|
operator long double () const { return _dec; }
|
||||||
|
|
||||||
|
// @cmember Trasforma un numero dal formato inglese (decimali con punto) in
|
||||||
|
// formato italiano (decimali con virgola)
|
||||||
|
static char* eng2ita(char* s);
|
||||||
|
// @cmember Trasforma un numero dal formato italiano (decimali con virgola) in
|
||||||
|
// formato inglese (decimali con punto)
|
||||||
|
static char* ita2eng(const char* s);
|
||||||
|
// @cmember Controlla se si tratta di un numero reale (TRUE se vero)
|
||||||
|
static bool is_real(const char* n);
|
||||||
|
// @cmember Controlla se si tratta di un numero naturale intero (TRUE se vero)
|
||||||
|
static bool is_natural(const char* n);
|
||||||
|
|
||||||
|
// @cmember Trasforma un reale in stringa
|
||||||
|
char* string(int len = 0, int dec = UNDEFINED, char pad = ' ') const;
|
||||||
|
// @cmember Trasforma un reale in stringa (chiama <mf real::string>), ma
|
||||||
|
// ritorna il formato italiano
|
||||||
|
char* stringa(int len = 0, int dec = UNDEFINED, char pad = ' ') const;
|
||||||
|
// @cmember Ritorna la stringa con il formato passato
|
||||||
|
char* string(const char* picture) const;
|
||||||
|
|
||||||
|
// @cmember Controlla se si tratta di un reale uguale 0 (TRUE se 0)
|
||||||
|
bool is_zero() const
|
||||||
|
{ return _dec == 0.0; }
|
||||||
|
// @cmember Ritorna il segno del reale
|
||||||
|
int sign() const;
|
||||||
|
// @cmember Trasforma il reale in intero (operator int era troppo pericoloso)
|
||||||
|
long integer() const;
|
||||||
|
|
||||||
|
// @cmember Arrotonda al numero di decimali passati
|
||||||
|
real& round(int prec = 0) ;
|
||||||
|
// @cmember Tronca al numero di decimali passati (default 0)
|
||||||
|
real& trunc(int prec = 0) ;
|
||||||
|
// @cmember Arrotonda al numero successivo (della precisione passata)
|
||||||
|
real& ceil(int prec = 0);
|
||||||
|
// @cmember Assegna un reale
|
||||||
|
real& operator = (const real& a);
|
||||||
|
// @cmember Assegna un reale
|
||||||
|
real& operator =(long double a);
|
||||||
|
real& operator +=(long double a);
|
||||||
|
// @cmember Sottrae ad un reale il valore passato (passato per indirizzo)
|
||||||
|
real& operator -=(long double b);
|
||||||
|
// @cmember Moltiplica un reale per il valore passato (passato per indirizzo)
|
||||||
|
real& operator *=(long double b);
|
||||||
|
// @cmember Divide un reale per il valore passato (passato per indirizzo)
|
||||||
|
real& operator /=(long double b);
|
||||||
|
// @cmember Ritorna la negazione di un reale (TRUE se 0, altrimenti FALSE)
|
||||||
|
bool operator !() const
|
||||||
|
{ return _dec == 0.0; }
|
||||||
|
// @cmember Ritorna il risultato della differenza tra due reali
|
||||||
|
real operator -() const;
|
||||||
|
|
||||||
|
// @cmember Costruttore
|
||||||
|
real();
|
||||||
|
// @cmember Costruttore
|
||||||
|
real(const real& b);
|
||||||
|
// @cmember Costruttore
|
||||||
|
real(long double a);
|
||||||
|
// @cmember Costruttore
|
||||||
|
real(const char* s);
|
||||||
|
// @cmember Distruttore
|
||||||
|
virtual ~real()
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline long double fnc_min(long double a, long double b) { return a < b ? a : b; }
|
||||||
|
inline long double fnc_max(long double a, long double b) { return a > b ? a : b; }
|
||||||
|
|
||||||
|
long double operator%(const real& a, const real& b);
|
||||||
|
void swap(real& a, real& b) ;
|
||||||
|
long double sqrt(long double) ;
|
||||||
|
long double sqr(long double) ;
|
||||||
|
long double exp10(long double) ;
|
||||||
|
long double pow(long double, long double) ;
|
||||||
|
long double exp(long double a) ;
|
||||||
|
long double log10(long double a) ;
|
||||||
|
long double log(long double a) ;
|
||||||
|
long double sin(long double a) ;
|
||||||
|
long double cos(long double a) ;
|
||||||
|
long double tan(long double a) ;
|
||||||
|
long double abs(long double a) ;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
#ifndef __IOSTREAM_H
|
#ifndef __IOSTREAM_H
|
||||||
#include <iostream.h>
|
#include <iostream.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __STDTYPES_H
|
#ifndef GMDOTH
|
||||||
#include <stdtypes.h>
|
#include <gmsys1.h>
|
||||||
#endif
|
#include <gfd.h>
|
||||||
|
|
||||||
#ifndef __STRINGS_H
|
|
||||||
#include <strings.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// @doc EXTERNAL
|
// @doc EXTERNAL
|
||||||
@ -158,7 +264,7 @@ inline bool operator >=(const real& a, double b) { return operator <=(b, a); }
|
|||||||
inline bool operator ==(const real& a, double b) { return operator ==(b, a); }
|
inline bool operator ==(const real& a, double b) { return operator ==(b, a); }
|
||||||
inline bool operator !=(const real& a, double b) { return operator !=(b, a); }
|
inline bool operator !=(const real& a, double b) { return operator !=(b, a); }
|
||||||
|
|
||||||
real operator %(const real& a, const long b) ;
|
real operator %(const real& a, const real& b) ;
|
||||||
void swap(real& a, real& b) ;
|
void swap(real& a, real& b) ;
|
||||||
const real& fnc_min(const real& a, const real& b) ;
|
const real& fnc_min(const real& a, const real& b) ;
|
||||||
const real& fnc_max(const real& a, const real& b) ;
|
const real& fnc_max(const real& a, const real& b) ;
|
||||||
@ -173,6 +279,11 @@ real sin(const real& a) ;
|
|||||||
real cos(const real& a) ;
|
real cos(const real& a) ;
|
||||||
real tan(const real& a) ;
|
real tan(const real& a) ;
|
||||||
real abs(const real& a) ;
|
real abs(const real& a) ;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// TReal implementato coi maledetti DEC
|
||||||
|
|
||||||
extern const real ZERO;
|
extern const real ZERO;
|
||||||
|
|
||||||
// @class TDistrib | Classe per dividere un real in varie sue percentuali
|
// @class TDistrib | Classe per dividere un real in varie sue percentuali
|
||||||
|
Loading…
x
Reference in New Issue
Block a user