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
afd18341
Commit
afd18341
authored
Oct 31, 2004
by
serg@serg.mylan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new round mode - half_up
parent
65ba0138
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
17 deletions
+18
-17
include/decimal.h
include/decimal.h
+2
-2
strings/decimal.c
strings/decimal.c
+16
-15
No files found.
include/decimal.h
View file @
afd18341
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
#include <my_global.h>
#include <my_global.h>
typedef
enum
{
TRUNCATE
=
0
,
EVEN
}
dec
_round_mode
;
typedef
enum
{
TRUNCATE
=
0
,
HALF_EVEN
,
HALF_UP
}
decimal
_round_mode
;
typedef
int32
decimal_digit
;
typedef
int32
decimal_digit
;
typedef
struct
st_decimal
{
typedef
struct
st_decimal
{
...
@@ -50,7 +50,7 @@ int decimal_cmp(decimal *from1, decimal *from2);
...
@@ -50,7 +50,7 @@ int decimal_cmp(decimal *from1, decimal *from2);
int
decimal_mul
(
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_div
(
decimal
*
from1
,
decimal
*
from2
,
decimal
*
to
,
int
scale_incr
);
int
decimal_mod
(
decimal
*
from1
,
decimal
*
from2
,
decimal
*
to
);
int
decimal_mod
(
decimal
*
from1
,
decimal
*
from2
,
decimal
*
to
);
int
decimal_round
(
decimal
*
from
,
decimal
*
to
,
int
new_scale
,
dec_round_mode
mode
);
int
decimal_round
(
decimal
*
from
,
decimal
*
to
,
int
new_scale
,
dec
imal
_round_mode
mode
);
/*
/*
the following works only on special "zero" decimal, not on any
the following works only on special "zero" decimal, not on any
...
...
strings/decimal.c
View file @
afd18341
...
@@ -816,7 +816,7 @@ int decimal_bin_size(int precision, int scale)
...
@@ -816,7 +816,7 @@ int decimal_bin_size(int precision, int scale)
E_DEC_OK/E_DEC_TRUNCATED
E_DEC_OK/E_DEC_TRUNCATED
*/
*/
int
decimal_round
(
decimal
*
from
,
decimal
*
to
,
int
scale
,
dec_round_mode
mode
)
int
decimal_round
(
decimal
*
from
,
decimal
*
to
,
int
scale
,
dec
imal
_round_mode
mode
)
{
{
int
frac0
=
ROUND_UP
(
scale
),
frac1
=
ROUND_UP
(
from
->
frac
),
int
frac0
=
ROUND_UP
(
scale
),
frac1
=
ROUND_UP
(
from
->
frac
),
intg0
=
ROUND_UP
(
from
->
intg
),
error
=
E_DEC_OK
,
len
=
to
->
len
;
intg0
=
ROUND_UP
(
from
->
intg
),
error
=
E_DEC_OK
,
len
=
to
->
len
;
...
@@ -867,7 +867,7 @@ int decimal_round(decimal *from, decimal *to, int scale, dec_round_mode mode)
...
@@ -867,7 +867,7 @@ int decimal_round(decimal *from, decimal *to, int scale, dec_round_mode mode)
if
(
mode
!=
TRUNCATE
)
if
(
mode
!=
TRUNCATE
)
{
{
x
=
buf0
[
1
]
/
DIG_MASK
;
x
=
buf0
[
1
]
/
DIG_MASK
;
if
(
x
>
5
||
(
x
==
5
&&
*
buf0
&
1
))
if
(
x
>
5
||
(
x
==
5
&&
(
mode
==
HALF_UP
||
*
buf0
&
1
)
))
(
*
buf1
)
++
;
(
*
buf1
)
++
;
}
}
}
}
...
@@ -878,7 +878,7 @@ int decimal_round(decimal *from, decimal *to, int scale, dec_round_mode mode)
...
@@ -878,7 +878,7 @@ int decimal_round(decimal *from, decimal *to, int scale, dec_round_mode mode)
{
{
x
=*
buf1
/
powers10
[
pos
];
x
=*
buf1
/
powers10
[
pos
];
y
=
x
%
10
;
y
=
x
%
10
;
if
(
y
>
5
||
(
y
==
5
&&
(
x
/
10
)
&
1
))
if
(
y
>
5
||
(
y
==
5
&&
(
mode
==
HALF_UP
||
(
x
/
10
)
&
1
)
))
x
+=
10
;
x
+=
10
;
*
buf1
=
x
*
powers10
[
pos
]
-
y
;
*
buf1
=
x
*
powers10
[
pos
]
-
y
;
}
}
...
@@ -1811,7 +1811,7 @@ void test_md(char *s1, char *s2)
...
@@ -1811,7 +1811,7 @@ void test_md(char *s1, char *s2)
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
void
test_ro
(
char
*
s1
,
int
n
,
dec_round_mode
mode
)
void
test_ro
(
char
*
s1
,
int
n
,
dec
imal
_round_mode
mode
)
{
{
char
s
[
100
];
char
s
[
100
];
int
res
;
int
res
;
...
@@ -1941,17 +1941,18 @@ main()
...
@@ -1941,17 +1941,18 @@ main()
test_dv
(
"0"
,
"987"
);
test_dv
(
"0"
,
"987"
);
printf
(
"==== decimal_round ====
\n
"
);
printf
(
"==== decimal_round ====
\n
"
);
test_ro
(
"15.1"
,
0
,
EVEN
);
test_ro
(
"15.1"
,
0
,
HALF_UP
);
test_ro
(
"15.5"
,
0
,
EVEN
);
test_ro
(
"15.5"
,
0
,
HALF_UP
);
test_ro
(
"15.9"
,
0
,
EVEN
);
test_ro
(
"15.5"
,
0
,
HALF_UP
);
test_ro
(
"-15.1"
,
0
,
EVEN
);
test_ro
(
"15.9"
,
0
,
HALF_UP
);
test_ro
(
"-15.5"
,
0
,
EVEN
);
test_ro
(
"-15.1"
,
0
,
HALF_UP
);
test_ro
(
"-15.9"
,
0
,
EVEN
);
test_ro
(
"-15.5"
,
0
,
HALF_UP
);
test_ro
(
"15.1"
,
1
,
EVEN
);
test_ro
(
"-15.9"
,
0
,
HALF_UP
);
test_ro
(
"-15.1"
,
1
,
EVEN
);
test_ro
(
"15.1"
,
1
,
HALF_UP
);
test_ro
(
"15.17"
,
1
,
EVEN
);
test_ro
(
"-15.1"
,
1
,
HALF_UP
);
test_ro
(
"15.4"
,
-
1
,
EVEN
);
test_ro
(
"15.17"
,
1
,
HALF_UP
);
test_ro
(
"-15.4"
,
-
1
,
EVEN
);
test_ro
(
"15.4"
,
-
1
,
HALF_UP
);
test_ro
(
"-15.4"
,
-
1
,
HALF_UP
);
test_ro
(
"5678.123451"
,
-
4
,
TRUNCATE
);
test_ro
(
"5678.123451"
,
-
4
,
TRUNCATE
);
test_ro
(
"5678.123451"
,
-
3
,
TRUNCATE
);
test_ro
(
"5678.123451"
,
-
3
,
TRUNCATE
);
test_ro
(
"5678.123451"
,
-
2
,
TRUNCATE
);
test_ro
(
"5678.123451"
,
-
2
,
TRUNCATE
);
...
...
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