summaryrefslogtreecommitdiff
path: root/include/decimal.h
diff options
context:
space:
mode:
authorunknown <serg@serg.mylan>2004-10-29 00:22:54 +0200
committerunknown <serg@serg.mylan>2004-10-29 00:22:54 +0200
commitbbfb40404f18f718a7fa400057f3971d11f7578a (patch)
tree432393f37248c6330762895d90e00e5f9a20f229 /include/decimal.h
parent2260f6d8e038e5b4bf69f2a6a14993e3b9c086eb (diff)
downloadmariadb-git-bbfb40404f18f718a7fa400057f3971d11f7578a.tar.gz
new api per hf request:
string2decimal_fixed decimal_round(from, to) decimal_make_zero decimal_string_size decimal_neg strings/decimal.c: new api per hf request: string2decimal_fixed decimal_round(from, to) decimal_make_zero
Diffstat (limited to 'include/decimal.h')
-rw-r--r--include/decimal.h23
1 files changed, 22 insertions, 1 deletions
diff --git a/include/decimal.h b/include/decimal.h
index fbe507f4049..e1a495f1f2b 100644
--- a/include/decimal.h
+++ b/include/decimal.h
@@ -30,6 +30,7 @@ typedef struct st_decimal {
int decimal2string(decimal *from, char *to, int *to_len);
int string2decimal(char *from, decimal *to, char **end);
+int string2decimal_fixed(char *from, decimal *to, char **end);
int decimal2ulonglong(decimal *from, ulonglong *to);
int ulonglong2decimal(ulonglong from, decimal *to);
int decimal2longlong(decimal *from, longlong *to);
@@ -49,14 +50,34 @@ int decimal_cmp(decimal *from1, decimal *from2);
int decimal_mul(decimal *from1, decimal *from2, decimal *to);
int decimal_div(decimal *from1, decimal *from2, decimal *to, int scale_incr);
int decimal_mod(decimal *from1, decimal *from2, decimal *to);
-int decimal_round(decimal *dec, int new_scale, dec_round_mode mode);
+int decimal_round(decimal *from, decimal *to, int new_scale, dec_round_mode mode);
/*
the following works only on special "zero" decimal, not on any
decimal that happen to evaluate to zero
*/
+
#define decimal_is_zero(dec) ((dec)->intg1==1 && (dec)->frac1==0 && (dec)->buf[0]==0)
+/* set a decimal to zero */
+
+#define decimal_make_zero(dec) do { \
+ (dec)->buf[0]=0; \
+ (dec)->intg=1; \
+ (dec)->frac=0; \
+ (dec)->sign=0; \
+ } while(0)
+
+/*
+ returns the length of the buffer to hold string representation
+ of the decimal
+*/
+
+#define decimal_string_size(dec) ((dec)->intg + (dec)->frac + ((dec)->frac > 0) + 1)
+
+/* negate a decimal */
+#define decimal_neg(dec) do { (dec)->sign=!(dec)->sign; } while(0)
+
/*
conventions: