Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
0dc24603
Commit
0dc24603
authored
Nov 30, 2010
by
Eoghan Sherry
Committed by
Robert Griesemer
Nov 30, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
big: fix (*Rat) SetFrac64(a, b) when b < 0.
R=gri CC=golang-dev
https://golang.org/cl/3352041
parent
e1149aa0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
+24
-2
rat.go
src/pkg/big/rat.go
+1
-2
rat_test.go
src/pkg/big/rat_test.go
+23
-0
No files found.
src/pkg/big/rat.go
View file @
0dc24603
...
...
@@ -35,9 +35,8 @@ func (z *Rat) SetFrac(a, b *Int) *Rat {
func
(
z
*
Rat
)
SetFrac64
(
a
,
b
int64
)
*
Rat
{
z
.
a
.
SetInt64
(
a
)
if
b
<
0
{
z
.
b
.
setUint64
(
uint64
(
-
b
))
b
=
-
b
z
.
a
.
neg
=
!
z
.
a
.
neg
return
z
.
norm
()
}
z
.
b
=
z
.
b
.
setUint64
(
uint64
(
b
))
return
z
.
norm
()
...
...
src/pkg/big/rat_test.go
View file @
0dc24603
...
...
@@ -257,3 +257,26 @@ func TestIssue820(t *testing.T) {
t
.
Errorf
(
"got %s want %s"
,
z
,
q
)
}
}
var
setFrac64Tests
=
[]
struct
{
a
,
b
int64
out
string
}{
{
0
,
1
,
"0"
},
{
0
,
-
1
,
"0"
},
{
1
,
1
,
"1"
},
{
-
1
,
1
,
"-1"
},
{
1
,
-
1
,
"-1"
},
{
-
1
,
-
1
,
"1"
},
{
-
9223372036854775808
,
-
9223372036854775808
,
"1"
},
}
func
TestRatSetFrac64Rat
(
t
*
testing
.
T
)
{
for
i
,
test
:=
range
setFrac64Tests
{
x
:=
new
(
Rat
)
.
SetFrac64
(
test
.
a
,
test
.
b
)
if
x
.
RatString
()
!=
test
.
out
{
t
.
Errorf
(
"#%d got %s want %s"
,
i
,
x
.
RatString
(),
test
.
out
)
}
}
}
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