mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
arbitrary precision decimal numbers
strings/llstr.c: small optimization BitKeeper/etc/ignore: Added strings/test_decimal to the ignore list
This commit is contained in:
@ -920,3 +920,4 @@ vio/test-ssl
|
|||||||
vio/test-sslclient
|
vio/test-sslclient
|
||||||
vio/test-sslserver
|
vio/test-sslserver
|
||||||
vio/viotest-ssl
|
vio/viotest-ssl
|
||||||
|
strings/test_decimal
|
||||||
|
68
include/decimal.h
Normal file
68
include/decimal.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/* Copyright (C) 2000 MySQL AB
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||||
|
|
||||||
|
#ifndef _decimal_h
|
||||||
|
#define _decimal_h
|
||||||
|
|
||||||
|
#include <my_global.h>
|
||||||
|
#include <m_ctype.h>
|
||||||
|
#include <my_sys.h> /* for my_alloca */
|
||||||
|
|
||||||
|
typedef enum {TRUNCATE=0, EVEN} dec_round_mode;
|
||||||
|
typedef uint32 decimal_digit;
|
||||||
|
|
||||||
|
typedef struct st_decimal {
|
||||||
|
int intg, frac, len;
|
||||||
|
my_bool sign;
|
||||||
|
decimal_digit *buf;
|
||||||
|
} decimal;
|
||||||
|
|
||||||
|
int decimal2string(decimal *from, char *to, uint *to_len);
|
||||||
|
int string2decimal(char *from, decimal *to, char **end);
|
||||||
|
int decimal2ulonglong(decimal *from, ulonglong *to);
|
||||||
|
int ulonglong2decimal(ulonglong from, decimal *to);
|
||||||
|
int decimal2longlong(decimal *from, longlong *to);
|
||||||
|
int longlong2decimal(longlong from, decimal *to);
|
||||||
|
int decimal2double(decimal *from, double *to);
|
||||||
|
int double2decimal(double from, decimal *to);
|
||||||
|
|
||||||
|
int decimal_add(decimal *from1, decimal *from2, decimal *to);
|
||||||
|
int decimal_sub(decimal *from1, decimal *from2, decimal *to);
|
||||||
|
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_result_size(decimal *from1, decimal *from2, char op, int param);
|
||||||
|
int decimal_round(decimal *dec, int new_scale, dec_round_mode mode);
|
||||||
|
|
||||||
|
/*
|
||||||
|
conventions:
|
||||||
|
|
||||||
|
decimal_smth() == 0 -- everything's ok
|
||||||
|
decimal_smth() <= 0 -- result is usable, precision loss is possible
|
||||||
|
decimal_smth() <= 1 -- result is unusable, but most significant digits
|
||||||
|
can be lost
|
||||||
|
decimal_smth() > 1 -- no result was generated
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define E_DEC_TRUNCATED -1
|
||||||
|
#define E_DEC_OK 0
|
||||||
|
#define E_DEC_OVERFLOW 1
|
||||||
|
#define E_DEC_DIV_ZERO 2
|
||||||
|
#define E_DEC_BAD_NUM 3
|
||||||
|
#define E_DEC_OOM 4
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -22,19 +22,19 @@ pkglib_LIBRARIES = libmystrings.a
|
|||||||
# Exact one of ASSEMBLER_X
|
# Exact one of ASSEMBLER_X
|
||||||
if ASSEMBLER_x86
|
if ASSEMBLER_x86
|
||||||
ASRCS = strings-x86.s longlong2str-x86.s my_strtoll10-x86.s
|
ASRCS = strings-x86.s longlong2str-x86.s my_strtoll10-x86.s
|
||||||
CSRCS = bfill.c bmove.c bmove512.c bchange.c strxnmov.c int2str.c str2int.c r_strinstr.c strtod.c bcmp.c strtol.c strtoul.c strtoll.c strtoull.c llstr.c strnlen.c ctype.c ctype-simple.c ctype-mb.c ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-gb2312.c ctype-gbk.c ctype-sjis.c ctype-tis620.c ctype-ujis.c ctype-utf8.c ctype-ucs2.c ctype-uca.c ctype-win1250ch.c ctype-bin.c ctype-latin1.c my_vsnprintf.c xml.c ctype-extra.c
|
CSRCS = bfill.c bmove.c bmove512.c bchange.c strxnmov.c int2str.c str2int.c r_strinstr.c strtod.c bcmp.c strtol.c strtoul.c strtoll.c strtoull.c llstr.c strnlen.c ctype.c ctype-simple.c ctype-mb.c ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-gb2312.c ctype-gbk.c ctype-sjis.c ctype-tis620.c ctype-ujis.c ctype-utf8.c ctype-ucs2.c ctype-uca.c ctype-win1250ch.c ctype-bin.c ctype-latin1.c my_vsnprintf.c xml.c decimal.c ctype-extra.c
|
||||||
else
|
else
|
||||||
if ASSEMBLER_sparc32
|
if ASSEMBLER_sparc32
|
||||||
# These file MUST all be on the same line!! Otherwise automake
|
# These file MUST all be on the same line!! Otherwise automake
|
||||||
# generats a very broken makefile
|
# generats a very broken makefile
|
||||||
ASRCS = bmove_upp-sparc.s strappend-sparc.s strend-sparc.s strinstr-sparc.s strmake-sparc.s strmov-sparc.s strnmov-sparc.s strstr-sparc.s
|
ASRCS = bmove_upp-sparc.s strappend-sparc.s strend-sparc.s strinstr-sparc.s strmake-sparc.s strmov-sparc.s strnmov-sparc.s strstr-sparc.s
|
||||||
CSRCS = strcont.c strfill.c strcend.c is_prefix.c longlong2str.c bfill.c bmove.c bmove512.c bchange.c strxnmov.c int2str.c str2int.c r_strinstr.c strtod.c bcmp.c strtol.c strtoul.c strtoll.c strtoull.c llstr.c strnlen.c strxmov.c ctype.c ctype-simple.c ctype-mb.c ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-gb2312.c ctype-gbk.c ctype-sjis.c ctype-tis620.c ctype-ujis.c ctype-utf8.c ctype-ucs2.c ctype-uca.c ctype-win1250ch.c ctype-bin.c ctype-latin1.c my_vsnprintf.c xml.c ctype-extra.c my_strtoll10.c
|
CSRCS = strcont.c strfill.c strcend.c is_prefix.c longlong2str.c bfill.c bmove.c bmove512.c bchange.c strxnmov.c int2str.c str2int.c r_strinstr.c strtod.c bcmp.c strtol.c strtoul.c strtoll.c strtoull.c llstr.c strnlen.c strxmov.c ctype.c ctype-simple.c ctype-mb.c ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-gb2312.c ctype-gbk.c ctype-sjis.c ctype-tis620.c ctype-ujis.c ctype-utf8.c ctype-ucs2.c ctype-uca.c ctype-win1250ch.c ctype-bin.c ctype-latin1.c my_vsnprintf.c xml.c decimal.c ctype-extra.c my_strtoll10.c
|
||||||
else
|
else
|
||||||
#no assembler
|
#no assembler
|
||||||
ASRCS =
|
ASRCS =
|
||||||
# These file MUST all be on the same line!! Otherwise automake
|
# These file MUST all be on the same line!! Otherwise automake
|
||||||
# generats a very broken makefile
|
# generats a very broken makefile
|
||||||
CSRCS = strxmov.c bmove_upp.c strappend.c strcont.c strend.c strfill.c strcend.c is_prefix.c strstr.c strinstr.c strmake.c strnmov.c strmov.c longlong2str.c bfill.c bmove.c bmove512.c bchange.c strxnmov.c int2str.c str2int.c r_strinstr.c strtod.c bcmp.c strtol.c strtoul.c strtoll.c strtoull.c llstr.c strnlen.c ctype.c ctype-simple.c ctype-mb.c ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-gb2312.c ctype-gbk.c ctype-sjis.c ctype-tis620.c ctype-ujis.c ctype-utf8.c ctype-ucs2.c ctype-uca.c ctype-win1250ch.c ctype-bin.c ctype-latin1.c my_vsnprintf.c xml.c ctype-extra.c my_strtoll10.c
|
CSRCS = strxmov.c bmove_upp.c strappend.c strcont.c strend.c strfill.c strcend.c is_prefix.c strstr.c strinstr.c strmake.c strnmov.c strmov.c longlong2str.c bfill.c bmove.c bmove512.c bchange.c strxnmov.c int2str.c str2int.c r_strinstr.c strtod.c bcmp.c strtol.c strtoul.c strtoll.c strtoull.c llstr.c strnlen.c ctype.c ctype-simple.c ctype-mb.c ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-gb2312.c ctype-gbk.c ctype-sjis.c ctype-tis620.c ctype-ujis.c ctype-utf8.c ctype-ucs2.c ctype-uca.c ctype-win1250ch.c ctype-bin.c ctype-latin1.c my_vsnprintf.c xml.c decimal.c ctype-extra.c my_strtoll10.c
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -43,9 +43,9 @@ noinst_PROGRAMS = conf_to_src
|
|||||||
DISTCLEANFILES = ctype_autoconf.c
|
DISTCLEANFILES = ctype_autoconf.c
|
||||||
# Default charset definitions
|
# Default charset definitions
|
||||||
EXTRA_DIST = ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-win1250ch.c \
|
EXTRA_DIST = ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-win1250ch.c \
|
||||||
ctype-gb2312.c ctype-gbk.c ctype-sjis.c ctype-utf8.c \
|
ctype-gb2312.c ctype-gbk.c ctype-sjis.c ctype-utf8.c \
|
||||||
ctype-ucs2.c ctype-uca.c ctype-tis620.c ctype-ujis.c \
|
ctype-ucs2.c ctype-uca.c ctype-tis620.c ctype-ujis.c \
|
||||||
xml.c strto.c strings-x86.s \
|
xml.c decimal.c strto.c strings-x86.s \
|
||||||
longlong2str.c longlong2str-x86.s \
|
longlong2str.c longlong2str-x86.s \
|
||||||
my_strtoll10.c my_strtoll10-x86.s \
|
my_strtoll10.c my_strtoll10-x86.s \
|
||||||
strxmov.c bmove_upp.c strappend.c strcont.c strend.c \
|
strxmov.c bmove_upp.c strappend.c strcont.c strend.c \
|
||||||
@ -54,7 +54,7 @@ EXTRA_DIST = ctype-big5.c ctype-czech.c ctype-euc_kr.c ctype-win1250ch.c \
|
|||||||
bmove_upp-sparc.s strappend-sparc.s strend-sparc.s \
|
bmove_upp-sparc.s strappend-sparc.s strend-sparc.s \
|
||||||
strinstr-sparc.s strmake-sparc.s strmov-sparc.s \
|
strinstr-sparc.s strmake-sparc.s strmov-sparc.s \
|
||||||
strnmov-sparc.s strstr-sparc.s strxmov-sparc.s \
|
strnmov-sparc.s strstr-sparc.s strxmov-sparc.s \
|
||||||
t_ctype.h
|
t_ctype.h
|
||||||
|
|
||||||
libmystrings_a_LIBADD=
|
libmystrings_a_LIBADD=
|
||||||
conf_to_src_SOURCES = conf_to_src.c xml.c ctype.c
|
conf_to_src_SOURCES = conf_to_src.c xml.c ctype.c
|
||||||
@ -73,8 +73,17 @@ if ASSEMBLER
|
|||||||
$(AS) $(ASFLAGS) -o $@ $<
|
$(AS) $(ASFLAGS) -o $@ $<
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
FLAGS=$(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) @NOINST_LDFLAGS@
|
||||||
|
LIBS=libmystrings.a
|
||||||
|
|
||||||
str_test: str_test.c $(LIBRARIES)
|
str_test: str_test.c $(LIBRARIES)
|
||||||
$(LINK) $(FLAGS) -DMAIN $INCLUDES $(srcdir)/str_test.c $(LDADD) $(LIBS) $(pkglib_LIBRARIES)
|
$(LINK) $(FLAGS) -DMAIN $(INCLUDES) $(srcdir)/str_test.c $(LDADD) $(LIBS) $(pkglib_LIBRARIES)
|
||||||
|
|
||||||
|
test_decimal$(EXEEXT): decimal.c $(LIBRARIES)
|
||||||
|
$(CP) $(srcdir)/decimal.c ./test_decimal.c
|
||||||
|
$(LINK) $(FLAGS) -DMAIN ./test_decimal.c $(LDADD) $(LIBS)
|
||||||
|
$(RM) -f ./test_decimal.c
|
||||||
|
|
||||||
# Don't update the files from bitkeeper
|
# Don't update the files from bitkeeper
|
||||||
%::SCCS/s.%
|
%::SCCS/s.%
|
||||||
|
|
||||||
|
1627
strings/decimal.c
Normal file
1627
strings/decimal.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -30,6 +30,6 @@
|
|||||||
|
|
||||||
char *llstr(longlong value,char *buff)
|
char *llstr(longlong value,char *buff)
|
||||||
{
|
{
|
||||||
longlong2str(value,buff,-10);
|
longlong10_to_str(value,buff,-10);
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user