Fixed Class Reference

#include <fixed.h>


Public Types

enum  { ALIGN = 1, COMMAS = 2, DECIMAL = 4 }

Public Member Functions

void equalize_precision (Fixed &)
void setprecision (int)
 Fixed (int x, int p)
 Fixed (QString a)
 Fixed (const char *a)
 Fixed ()
Fixed operator[] (int) const
Fixed operator= (Fixed)
Fixed operator= (int)
QString toQString (QChar separadorDecimal= ',')

Data Fields

Fixed_numerator value
int precision

Private Member Functions

void fromFixed (const char *)

Friends

Fixed operator+ (Fixed, Fixed)
Fixed operator- (Fixed, Fixed)
Fixed operator * (Fixed, Fixed)
Fixed operator/ (Fixed, Fixed)
Fixed operator- (Fixed)
bool operator== (Fixed, Fixed)
bool operator< (Fixed, Fixed)
Fixed operator- (int, Fixed)
Fixed operator/ (int, Fixed)
bool operator== (int, Fixed)
bool operator< (int, Fixed)
Fixed operator+ (Fixed, int)
Fixed operator- (Fixed, int)
Fixed operator * (Fixed, int)
Fixed operator/ (Fixed, int)
bool operator== (Fixed, int)
bool operator< (Fixed, int)


Detailed Description

Definition at line 26 of file fixed.h.


Member Enumeration Documentation

anonymous enum

Enumerator:
ALIGN 
COMMAS 
DECIMAL 

Definition at line 63 of file fixed.h.

00063 {ALIGN = 1, COMMAS = 2, DECIMAL = 4};


Constructor & Destructor Documentation

Fixed::Fixed ( int  x,
int  p 
)

Parameters:
x 
p 

Definition at line 23 of file fixed.cpp.

References _depura(), precision, and value.

00023                          {
00024     _depura("Fixed::Fixed", 0);
00025     value = x;
00026     precision = p;
00027     _depura("END Fixed::Fixed", 0);
00028 }

Fixed::Fixed ( QString  a  ) 

Parameters:
a 

Definition at line 35 of file fixed.cpp.

References _depura(), and fromFixed().

00035                       {
00036     _depura("Fixed::Fixed", 0);
00037     fromFixed(a.toAscii());
00038     _depura("END Fixed::Fixed", 0);
00039 }

Fixed::Fixed ( const char *  a  ) 

Parameters:
a 

Definition at line 46 of file fixed.cpp.

References _depura(), and fromFixed().

00046                           {
00047     _depura("Fixed::Fixed", 0);
00048     fromFixed(a);
00049     _depura("END Fixed::Fixed", 0);
00050 }

Fixed::Fixed (  ) 

Definition at line 56 of file fixed.cpp.

References _depura(), precision, and value.

Referenced by FichaBf::calculaypintatotales(), FichaBf::generaRML(), FichaBf::trataLineasDescuento(), FichaBf::trataLineasDetalle(), and FichaBf::trataTotales().

00056              {
00057     _depura("Fixed::Fixed", 0);
00058     value = 0;
00059     precision = 1;
00060     _depura("END Fixed::Fixed", 0);
00061 
00062 }


Member Function Documentation

void Fixed::fromFixed ( const char *  s  )  [private]

Parameters:
s 

Definition at line 224 of file fixed.cpp.

References _depura(), MAX_FIXED_PRECISION, precision, and value.

Referenced by Fixed().

00224                                    {
00225     _depura("Fixed::fromFixed", 0);
00226     value = 0;
00227     precision = 0;
00228     int c;
00229     while ((c = *s++) == ' ' || c == '\t')
00230         ;
00231     bool negative;
00232     if (c == '-') {
00233         negative = true;
00234         c = *s++;
00235     } else {
00236         negative = false;
00237     } // end if
00238     bool decimal = false;
00239     while (precision < MAX_FIXED_PRECISION) {
00240         if ('0' <= c && c <= '9') {
00241             value = value * 10 + (c - '0');
00242             if (decimal)
00243                 precision++;
00244         } else if (c == '.' || c ==',') {
00245             if (decimal)
00246                 break;
00247             decimal = true;
00248         } else if (c != ',')
00249             break;
00250         c = *s++;
00251     } // end while
00252     if (negative)
00253         value = - value;
00254     if (value == 0)
00255         precision = 1;
00256     _depura("END Fixed::fromFixed", 0);
00257 }

void Fixed::equalize_precision ( Fixed x  ) 

Parameters:
x 

Definition at line 183 of file fixed.cpp.

References _depura(), precision, and value.

Referenced by operator+(), operator-(), operator<(), and operator==().

00183                                        {
00184     _depura("Fixed::equalize_precision", 0);
00185     while (precision < x.precision)   {
00186         value *= 10;
00187         precision ++;
00188     } // end while
00189     while (x.precision < precision)  {
00190         x.value *= 10 ;
00191         x.precision ++;
00192     } // end while
00193     _depura("END Fixed::equalize_precision", 0);
00194 }

void Fixed::setprecision ( int  prec  ) 

Parameters:
prec 

Definition at line 201 of file fixed.cpp.

References _depura(), precision, and value.

Referenced by toQString().

00201                                  {
00202     _depura("Fixed::setprecision", 0);
00203     while (precision < prec) {
00204         value *= 10;
00205         precision ++;
00206     } // end while
00207     while (prec < precision) {
00208         Fixed_numerator aux;
00209         aux = value;
00210         value = (Fixed_numerator) (value / 10);
00211         if ((aux % 10) >=5) {
00212             value++;
00213         } // end if
00214         precision--;
00215     } // end while
00216     _depura("END Fixed::setprecision", 0);
00217 }

Fixed Fixed::operator[] ( int   )  const

Definition at line 294 of file fixed.cpp.

References _depura().

00294                                      {
00295     _depura("Fixed::operator[]");
00296     Fixed x(0, p);
00297     _depura("END Fixed::operator[]");
00298     return x;
00299 }

Fixed Fixed::operator= ( Fixed   ) 

Definition at line 79 of file fixed.cpp.

References precision, and value.

00079                                 {
00080     value = x.value;
00081     precision = x.precision;
00082     return *this;
00083 }

Fixed Fixed::operator= ( int   ) 

Definition at line 86 of file fixed.cpp.

References precision, and value.

00086                               {
00087     value = x;
00088     precision = 0;
00089     return *this;
00090 }

QString Fixed::toQString ( QChar  separadorDecimal = ','  ) 

Parameters:
separadorDecimal 
Returns:

prevent buffer overflow if result is still negative.

10/07/2007 Se cambio para poder poner otro caracter como separador decimal.

Definition at line 115 of file fixed.cpp.

References _depura(), ALIGN, COMMAS, DECIMAL, integer(), MAX_FIXED_LENGTH, MAX_FIXED_PRECISION, precision, setprecision(), and value.

Referenced by libromayorprint::accept(), CAnualesPrintView::agregaValores(), Asiento1View::asiento_regularizacion(), pluginCAnualesODS::balanceSituacionODS(), Asiento1View::calculaypintatotales(), Q19QToolButton::click(), EFQToolButton::escribe_descuento_factura(), EFQToolButton::escribe_linea_factura(), FichaBf::generaRML(), Arbol::hojaactual(), extractoview1::imprimeExtractoCuenta(), Ticket::imprimir(), Ticket::insertarArticulo(), EFQToolButtonImportar::obten_descuento_factura(), CAnualesPrintView::on_mui_aceptar_clicked(), RegistroIvaView::on_mui_generarPrevisiones_clicked(), RegistroIvaView::pintabaseimp(), RegistroIvaView::pintaiva(), MTicket::pintar(), PresupuestoView::pintatotales(), PedidoProveedorView::pintatotales(), PedidoClienteView::pintatotales(), FacturaView::pintatotales(), FacturaProveedorView::pintatotales(), AlbaranProveedorView::pintatotales(), AlbaranClienteView::pintatotales(), Ticket::ponerCantidad(), Ticket::ponerPrecio(), PagosList::presentar(), CobrosList::presentar(), extractoview1::presentar(), AsientosView::presentar(), BalanceView::presentarSyS(), CAnualesPrintView::procesaFormula(), cobropagoview::s_recalculaSaldo(), Ticket_pintar(), FichaBf::trataLineasDescuento(), FichaBf::trataLineasDetalle(), and FichaBf::trataTotales().

00115                                                {
00116     _depura("Fixed::toQString", 0);
00117     setprecision(2);
00118     int options = COMMAS;
00119     Fixed_numerator x = value;
00120     bool negative;
00121     if (x < 0) {
00122         x = -x;
00124         if (x < 0)
00125             x = x - 1;
00126         negative = true;
00127     } else
00128         negative = false;
00129     Fixed_numerator n = 0;
00130     Fixed_numerator units = 0;
00131     unsigned char buffer[MAX_FIXED_LENGTH + MAX_FIXED_PRECISION];
00132     for (unsigned int i = 0; i <= sizeof(buffer); i++)
00133         buffer[i] = 0;
00134     do {
00135         if (n == precision) {
00136             if (n > 0 || options & DECIMAL)
00139                 //buffer[sizeof(buffer) - ++n] = ',';
00140 
00141                 buffer[sizeof(buffer) - ++n] = separadorDecimal.toAscii();
00142 
00143             units = n;
00144         }
00145         Fixed_numerator y;
00146         y = (Fixed_numerator) x / 10;
00147         buffer[sizeof(buffer) - ++n] = integer(x - y * 10) + '0';
00148         x = y;
00149     } while (n <= precision || x != 0);
00150     if (negative)
00151         buffer[sizeof(buffer) - ++n] = '-';
00152     if (options & ALIGN) {
00153         while (n - units < MAX_FIXED_LENGTH - 2)
00154             buffer[sizeof(buffer) - ++n] = ' ';
00155     }
00156     QString a((const char *) buffer + sizeof(buffer) - n);
00157     _depura("END Fixed::toQString", 0);
00158     return a;
00159 }


Friends And Related Function Documentation

Fixed operator+ ( Fixed  x,
Fixed  y 
) [friend]

Definition at line 65 of file fixed.cpp.

00065                                     {
00066     x.equalize_precision(y);
00067     x.value = x.value + y.value;
00068     return x;
00069 }

Fixed operator- ( Fixed  x,
Fixed  y 
) [friend]

Definition at line 302 of file fixed.cpp.

00302                                     {
00303     x.equalize_precision(y);
00304     x.value = x.value - y.value;
00305     return x;
00306 }

Fixed operator * ( Fixed  x,
Fixed  y 
) [friend]

Definition at line 287 of file fixed.cpp.

00287                                     {
00288     x.value = x.value * y.value;
00289     x.precision = x.precision + y.precision;
00290     return x;
00291 }

Fixed operator/ ( Fixed  x,
Fixed  y 
) [friend]

Definition at line 93 of file fixed.cpp.

00093                                     {
00094     x.value = x.value / y.value;
00095     x.precision += y.precision;
00096     return x;
00097 }

Fixed operator- ( Fixed  x  )  [friend]

Definition at line 276 of file fixed.cpp.

00276                            {
00277     x.value = -x.value;
00278     return x;
00279 }

bool operator== ( Fixed  x,
Fixed  y 
) [friend]

Definition at line 162 of file fixed.cpp.

00162                                     {
00163     x.equalize_precision(y);
00164     return x.value == y.value;
00165 }

bool operator< ( Fixed  x,
Fixed  y 
) [friend]

Definition at line 260 of file fixed.cpp.

00260                                    {
00261     x.equalize_precision(y);
00262     return x.value < y.value;
00263 }

Fixed operator- ( int  x,
Fixed  y 
) [friend]

Definition at line 314 of file fixed.cpp.

00314                                   {
00315     return Fixed(x, 0) - y;
00316 }

Fixed operator/ ( int  x,
Fixed  y 
) [friend]

Definition at line 105 of file fixed.cpp.

00105                                   {
00106     return Fixed(x, 0) / y;
00107 }

bool operator== ( int  x,
Fixed  y 
) [friend]

Definition at line 174 of file fixed.cpp.

00174                                   {
00175     return Fixed(x, 0) == y;
00176 }

bool operator< ( int  x,
Fixed  y 
) [friend]

Definition at line 271 of file fixed.cpp.

00271                                  {
00272     return Fixed(x, 0) < y;
00273 }

Fixed operator+ ( Fixed  x,
int  y 
) [friend]

Definition at line 73 of file fixed.cpp.

00073                                   {
00074     return x + Fixed(y, 0);
00075 }

Fixed operator- ( Fixed  x,
int  y 
) [friend]

Definition at line 309 of file fixed.cpp.

00309                                   {
00310     return x - Fixed(y, 0);
00311 }

Fixed operator * ( Fixed  x,
int  y 
) [friend]

Definition at line 282 of file fixed.cpp.

00282                                   {
00283     return x * Fixed(y, 0);
00284 }

Fixed operator/ ( Fixed  x,
int  y 
) [friend]

Definition at line 100 of file fixed.cpp.

00100                                   {
00101     return x / Fixed(y, 0);
00102 }

bool operator== ( Fixed  x,
int  y 
) [friend]

Definition at line 168 of file fixed.cpp.

00168                                   {
00169     return x == Fixed(y, 0);
00170 }

bool operator< ( Fixed  x,
int  y 
) [friend]

Definition at line 266 of file fixed.cpp.

00266                                  {
00267     return x < Fixed(y, 0);
00268 }


Field Documentation

Fixed_numerator Fixed::value

Definition at line 32 of file fixed.h.

Referenced by FichaBf::calculaypintatotales(), equalize_precision(), Fixed(), fromFixed(), FichaBf::generaRML(), Ticket::imprimir(), PedidoProveedorView::imprimir(), FacturaProveedorView::imprimirFacturaProveedor(), operator *(), operator+(), operator-(), operator/(), operator<(), operator=(), operator==(), MTicket::pintar(), setprecision(), Ticket_pintar(), toQString(), and FichaBf::trataTotales().

int Fixed::precision

Definition at line 33 of file fixed.h.

Referenced by equalize_precision(), Fixed(), fromFixed(), operator *(), operator/(), operator=(), setprecision(), and toQString().


The documentation for this class was generated from the following files:
Generated on Sat Dec 15 00:01:54 2007 for BulmaGes by  doxygen 1.5.1