Eneboo - Documentación para desarrolladores
src/libmysql_std/include/decimal.h
Ir a la documentación de este archivo.
00001 /* Copyright (C) 2000 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
00015 
00016 #ifndef _decimal_h
00017 #define _decimal_h
00018 
00019 typedef enum
00020 {TRUNCATE=0, HALF_EVEN, HALF_UP, CEILING, FLOOR}
00021   decimal_round_mode;
00022 typedef int32 decimal_digit_t;
00023 
00024 typedef struct st_decimal_t {
00025   int    intg, frac, len;
00026   my_bool sign;
00027   decimal_digit_t *buf;
00028 } decimal_t;
00029 
00030 int internal_str2dec(const char *from, decimal_t *to, char **end,
00031                      my_bool fixed);
00032 int decimal2string(decimal_t *from, char *to, int *to_len,
00033                    int fixed_precision, int fixed_decimals,
00034                    char filler);
00035 int decimal2ulonglong(decimal_t *from, ulonglong *to);
00036 int ulonglong2decimal(ulonglong from, decimal_t *to);
00037 int decimal2longlong(decimal_t *from, longlong *to);
00038 int longlong2decimal(longlong from, decimal_t *to);
00039 int decimal2double(decimal_t *from, double *to);
00040 int double2decimal(double from, decimal_t *to);
00041 int decimal_actual_fraction(decimal_t *from);
00042 int decimal2bin(decimal_t *from, char *to, int precision, int scale);
00043 int bin2decimal(char *from, decimal_t *to, int precision, int scale);
00044 
00045 int decimal_size(int precision, int scale);
00046 int decimal_bin_size(int precision, int scale);
00047 int decimal_result_size(decimal_t *from1, decimal_t *from2, char op,
00048                         int param);
00049 
00050 int decimal_intg(decimal_t *from);
00051 int decimal_add(decimal_t *from1, decimal_t *from2, decimal_t *to);
00052 int decimal_sub(decimal_t *from1, decimal_t *from2, decimal_t *to);
00053 int decimal_cmp(decimal_t *from1, decimal_t *from2);
00054 int decimal_mul(decimal_t *from1, decimal_t *from2, decimal_t *to);
00055 int decimal_div(decimal_t *from1, decimal_t *from2, decimal_t *to,
00056                 int scale_incr);
00057 int decimal_mod(decimal_t *from1, decimal_t *from2, decimal_t *to);
00058 int decimal_round(decimal_t *from, decimal_t *to, int new_scale,
00059                   decimal_round_mode mode);
00060 int decimal_is_zero(decimal_t *from);
00061 void max_decimal(int precision, int frac, decimal_t *to);
00062 
00063 #define string2decimal(A,B,C) internal_str2dec((A), (B), (C), 0)
00064 #define string2decimal_fixed(A,B,C) internal_str2dec((A), (B), (C), 1)
00065 
00066 /* set a decimal_t to zero */
00067 
00068 #define decimal_make_zero(dec)        do {                \
00069                                         (dec)->buf[0]=0;    \
00070                                         (dec)->intg=1;      \
00071                                         (dec)->frac=0;      \
00072                                         (dec)->sign=0;      \
00073                                       } while(0)
00074 
00075 /*
00076   returns the length of the buffer to hold string representation
00077   of the decimal (including decimal dot, possible sign and \0)
00078 */
00079 
00080 #define decimal_string_size(dec) (((dec)->intg ? (dec)->intg : 1) + \
00081                                   (dec)->frac + ((dec)->frac > 0) + 2)
00082 
00083 /* negate a decimal */
00084 #define decimal_neg(dec) do { (dec)->sign^=1; } while(0)
00085 
00086 /*
00087   conventions:
00088 
00089     decimal_smth() == 0     -- everything's ok
00090     decimal_smth() <= 1     -- result is usable, but precision loss is possible
00091     decimal_smth() <= 2     -- result can be unusable, most significant digits
00092                                could've been lost
00093     decimal_smth() >  2     -- no result was generated
00094 */
00095 
00096 #define E_DEC_OK                0
00097 #define E_DEC_TRUNCATED         1
00098 #define E_DEC_OVERFLOW          2
00099 #define E_DEC_DIV_ZERO          4
00100 #define E_DEC_BAD_NUM           8
00101 #define E_DEC_OOM              16
00102 
00103 #define E_DEC_ERROR            31
00104 #define E_DEC_FATAL_ERROR      30
00105 
00106 #endif
00107 
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'