Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
gostnops
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
gostnops
Commits
c3a70b81
Unverified
Commit
c3a70b81
authored
Jul 10, 2019
by
望哥
Committed by
GitHub
Jul 10, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8 from aliiohs/ChangeTOStringName
transfer ToString to ToBytes
parents
ae4ac3e9
9f6eb473
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
21 deletions
+21
-21
decimal.go
math/big/decimal.go
+2
-2
decimal_test.go
math/big/decimal_test.go
+19
-19
No files found.
math/big/decimal.go
View file @
c3a70b81
...
...
@@ -266,7 +266,7 @@ func (d *Decimal) String() string {
tmp
:=
*
d
_
=
tmp
.
Round
(
&
tmp
,
int
(
tmp
.
resultFrac
),
ModeHalfEven
)
//todo terror.Log(errors.Trace(err))
return
string
(
tmp
.
To
String
())
return
string
(
tmp
.
To
Bytes
())
}
func
(
d
*
Decimal
)
stringSize
()
int
{
...
...
@@ -314,7 +314,7 @@ func (d *Decimal) removeTrailingZeros() (lastWordIdx int, digitsFrac int) {
// str - result string
// errCode - eDecOK/eDecTruncate/eDecOverflow
//
func
(
d
*
Decimal
)
To
String
()
(
str
[]
byte
)
{
func
(
d
*
Decimal
)
To
Bytes
()
(
str
[]
byte
)
{
str
=
make
([]
byte
,
d
.
stringSize
())
digitsFrac
:=
int
(
d
.
digitsFrac
)
wordStartIdx
,
digitsInt
:=
d
.
removeLeadingZeros
()
...
...
math/big/decimal_test.go
View file @
c3a70b81
...
...
@@ -39,7 +39,7 @@ func TestFromInt(t *testing.T) {
}
for
_
,
tt
:=
range
tests
{
dec
:=
NewDecFromInt
(
tt
.
input
)
str
:=
dec
.
To
String
()
str
:=
dec
.
To
Bytes
()
assert
.
Equal
(
t
,
string
(
str
),
tt
.
output
)
}
}
...
...
@@ -56,7 +56,7 @@ func TestFromUint(t *testing.T) {
for
_
,
tt
:=
range
tests
{
var
dec
Decimal
dec
.
FromUint
(
tt
.
input
)
str
:=
dec
.
To
String
()
str
:=
dec
.
To
Bytes
()
assert
.
Equal
(
t
,
string
(
str
),
tt
.
output
)
}
}
...
...
@@ -122,7 +122,7 @@ func TestFromFloat(t *testing.T) {
}
for
_
,
tt
:=
range
tests
{
dec
:=
NewDecFromFloatForTest
(
tt
.
f
)
str
:=
dec
.
To
String
()
str
:=
dec
.
To
Bytes
()
assert
.
Equal
(
t
,
string
(
str
),
tt
.
s
)
}
}
...
...
@@ -235,7 +235,7 @@ func TestRemoveTrailingZeros(t *testing.T) {
// calculate the number of digits after point but trailing zero
digitsFracExp
:=
0
str
:=
string
(
dec
.
To
String
())
str
:=
string
(
dec
.
To
Bytes
())
point
:=
strings
.
Index
(
str
,
"."
)
if
point
!=
-
1
{
pos
:=
len
(
str
)
-
1
...
...
@@ -268,7 +268,7 @@ func TestShift(t *testing.T) {
//origin := dec
err
=
dec
.
Shift
(
ca
.
shift
)
assert
.
Equal
(
t
,
err
,
ca
.
err
)
result
:=
dec
.
To
String
()
result
:=
dec
.
To
Bytes
()
//, Commentf("origin:%s\ndec:%s", origin.String(), string(result))
assert
.
Equal
(
t
,
string
(
result
),
ca
.
output
)
}
...
...
@@ -398,7 +398,7 @@ func TestRoundWithHalfEven(t *testing.T) {
var
rounded
Decimal
err
:=
dec
.
Round
(
&
rounded
,
ca
.
scale
,
ModeHalfEven
)
assert
.
Equal
(
t
,
err
,
ca
.
err
)
result
:=
rounded
.
To
String
()
result
:=
rounded
.
To
Bytes
()
assert
.
Equal
(
t
,
string
(
result
),
ca
.
output
)
}
}
...
...
@@ -432,7 +432,7 @@ func TestRoundWithTruncate(t *testing.T) {
var
rounded
Decimal
err
:=
dec
.
Round
(
&
rounded
,
ca
.
scale
,
ModeTruncate
)
assert
.
Equal
(
t
,
err
,
ca
.
err
)
result
:=
rounded
.
To
String
()
result
:=
rounded
.
To
Bytes
()
assert
.
Equal
(
t
,
string
(
result
),
ca
.
output
)
}
}
...
...
@@ -467,7 +467,7 @@ func TestRoundWithCeil(t *testing.T) {
var
rounded
Decimal
err
:=
dec
.
Round
(
&
rounded
,
ca
.
scale
,
modeCeiling
)
assert
.
Equal
(
t
,
err
,
ca
.
err
)
result
:=
rounded
.
To
String
()
result
:=
rounded
.
To
Bytes
()
assert
.
Equal
(
t
,
string
(
result
),
ca
.
output
)
}
}
...
...
@@ -494,7 +494,7 @@ func TestFromString(t *testing.T) {
if
err
!=
nil
{
assert
.
Equal
(
t
,
err
,
ca
.
err
)
}
result
:=
string
(
dec
.
To
String
())
result
:=
string
(
dec
.
To
Bytes
())
assert
.
Equal
(
t
,
result
,
ca
.
output
)
}
wordBufLen
=
1
...
...
@@ -506,13 +506,13 @@ func TestFromString(t *testing.T) {
var
dec
Decimal
err
:=
dec
.
FromBytes
([]
byte
(
ca
.
input
))
assert
.
Equal
(
t
,
err
,
ca
.
err
)
result
:=
string
(
dec
.
To
String
())
result
:=
string
(
dec
.
To
Bytes
())
assert
.
Equal
(
t
,
result
,
ca
.
output
)
}
wordBufLen
=
maxWordBufLen
}
func
TestTo
String
(
t
*
testing
.
T
)
{
func
TestTo
Bytes
(
t
*
testing
.
T
)
{
type
tcase
struct
{
input
string
output
string
...
...
@@ -525,7 +525,7 @@ func TestToString(t *testing.T) {
for
_
,
ca
:=
range
tests
{
var
dec
Decimal
_
=
dec
.
FromBytes
([]
byte
(
ca
.
input
))
result
:=
dec
.
To
String
()
result
:=
dec
.
To
Bytes
()
assert
.
Equal
(
t
,
string
(
result
),
ca
.
output
)
}
}
...
...
@@ -564,7 +564,7 @@ func TestToBinFromBin(t *testing.T) {
var
dec2
Decimal
_
,
err
=
dec2
.
FromBin
(
buf
,
ca
.
precision
,
ca
.
frac
)
assert
.
Equal
(
t
,
err
,
nil
)
str
:=
dec2
.
To
String
()
str
:=
dec2
.
To
Bytes
()
assert
.
Equal
(
t
,
string
(
str
),
ca
.
output
)
}
var
dec
Decimal
...
...
@@ -637,7 +637,7 @@ func TestMaxDecimal(t *testing.T) {
for
_
,
tt
:=
range
tests
{
var
dec
Decimal
maxDecimal
(
tt
.
prec
,
tt
.
frac
,
&
dec
)
str
:=
dec
.
To
String
()
str
:=
dec
.
To
Bytes
()
assert
.
Equal
(
t
,
string
(
str
),
tt
.
result
)
}
}
...
...
@@ -656,7 +656,7 @@ func TestNeg(t *testing.T) {
for
_
,
tt
:=
range
tests
{
a
:=
NewDecFromStringForTest
(
tt
.
a
)
negResult
:=
DecimalNeg
(
a
)
result
:=
negResult
.
To
String
()
result
:=
negResult
.
To
Bytes
()
assert
.
Equal
(
t
,
string
(
result
),
tt
.
result
)
}
}
...
...
@@ -691,7 +691,7 @@ func TestAdd(t *testing.T) {
var
sum
Decimal
err
:=
DecimalAdd
(
a
,
b
,
&
sum
)
assert
.
Equal
(
t
,
err
,
tt
.
err
)
result
:=
sum
.
To
String
()
result
:=
sum
.
To
Bytes
()
assert
.
Equal
(
t
,
string
(
result
),
tt
.
result
)
}
}
...
...
@@ -725,7 +725,7 @@ func TestSub(t *testing.T) {
b
.
FromBytes
([]
byte
(
tt
.
b
))
err
:=
DecimalSub
(
&
a
,
&
b
,
&
sum
)
assert
.
Equal
(
t
,
err
,
tt
.
err
)
result
:=
sum
.
To
String
()
result
:=
sum
.
To
Bytes
()
assert
.
Equal
(
t
,
string
(
result
),
tt
.
result
)
}
}
...
...
@@ -794,7 +794,7 @@ func TestDivMod(t *testing.T) {
if
tt
.
err
==
ErrDivByZero
{
continue
}
result
:=
to
.
To
String
()
result
:=
to
.
To
Bytes
()
assert
.
Equal
(
t
,
string
(
result
),
tt
.
result
)
}
...
...
@@ -816,7 +816,7 @@ func TestDivMod(t *testing.T) {
if
tt
.
err
==
ErrDivByZero
{
continue
}
result
:=
to
.
To
String
()
result
:=
to
.
To
Bytes
()
assert
.
Equal
(
t
,
string
(
result
),
tt
.
result
)
}
...
...
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