Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
0b7f26d7
Commit
0b7f26d7
authored
Oct 19, 2004
by
serg@serg.mylan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decimal to/from bin, and utility functions
parent
5fd2c489
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
314 additions
and
29 deletions
+314
-29
include/decimal.h
include/decimal.h
+24
-15
strings/Makefile.am
strings/Makefile.am
+4
-5
strings/decimal.c
strings/decimal.c
+286
-9
No files found.
include/decimal.h
View file @
0b7f26d7
...
...
@@ -18,11 +18,9 @@
#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
u
int32
decimal_digit
;
typedef
int32
decimal_digit
;
typedef
struct
st_decimal
{
int
intg
,
frac
,
len
;
...
...
@@ -30,7 +28,7 @@ typedef struct st_decimal {
decimal_digit
*
buf
;
}
decimal
;
int
decimal2string
(
decimal
*
from
,
char
*
to
,
u
int
*
to_len
);
int
decimal2string
(
decimal
*
from
,
char
*
to
,
int
*
to_len
);
int
string2decimal
(
char
*
from
,
decimal
*
to
,
char
**
end
);
int
decimal2ulonglong
(
decimal
*
from
,
ulonglong
*
to
);
int
ulonglong2decimal
(
ulonglong
from
,
decimal
*
to
);
...
...
@@ -38,31 +36,42 @@ 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
decimal2bin
(
decimal
*
from
,
char
*
to
,
int
precision
,
int
scale
);
int
bin2decimal
(
char
*
from
,
decimal
*
to
,
int
precision
,
int
scale
);
int
decimal_size
(
int
precision
,
int
scale
);
int
decimal_bin_size
(
int
precision
,
int
scale
);
int
decimal_result_size
(
decimal
*
from1
,
decimal
*
from2
,
char
op
,
int
param
);
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
);
/*
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)
/*
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
c
an be
lost
decimal_smth() >
1
-- no result was generated
decimal_smth() <=
1 -- result is usable, but
precision loss is possible
decimal_smth() <=
2 -- result can be unusable,
most significant digits
c
ould've been
lost
decimal_smth() >
2
-- 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
#define E_DEC_TRUNCATED 1
#define E_DEC_OVERFLOW 2
#define E_DEC_DIV_ZERO 3
#define E_DEC_BAD_NUM 4
#define E_DEC_OOM 5
#endif
strings/Makefile.am
View file @
0b7f26d7
...
...
@@ -74,14 +74,13 @@ if ASSEMBLER
endif
FLAGS
=
$(DEFS)
$(INCLUDES)
$(CPPFLAGS)
$(CFLAGS)
@NOINST_LDFLAGS@
LIBS
=
libmystrings.a
str_test
:
str_test.c $(LIBRARIES)
$(LINK)
$(FLAGS)
-DMAIN
$(INCLUDES)
$(srcdir)
/str_test.c
$(LDADD)
$(
LIBS)
$(
pkglib_LIBRARIES)
str_test
:
str_test.c $(
pkglib_
LIBRARIES)
$(LINK)
$(FLAGS)
-DMAIN
$(INCLUDES)
$(srcdir)
/str_test.c
$(LDADD)
$(pkglib_LIBRARIES)
test_decimal$(EXEEXT)
:
decimal.c $(LIBRARIES)
test_decimal$(EXEEXT)
:
decimal.c $(
pkglib_
LIBRARIES)
$(CP)
$(srcdir)
/decimal.c ./test_decimal.c
$(LINK)
$(FLAGS)
-DMAIN
./test_decimal.c
$(LDADD)
$(
LIB
S)
$(LINK)
$(FLAGS)
-DMAIN
./test_decimal.c
$(LDADD)
$(
pkglib_LIBRARIE
S)
$(RM)
-f
./test_decimal.c
# Don't update the files from bitkeeper
...
...
strings/decimal.c
View file @
0b7f26d7
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment