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
c4de2498
Commit
c4de2498
authored
May 06, 2009
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
signs on div and mod
R=r OCL=28319 CL=28319
parent
1d6bd79c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
197 additions
and
1 deletion
+197
-1
mparith2.c
src/cmd/gc/mparith2.c
+13
-1
divmod.go
test/ken/divmod.go
+184
-0
No files found.
src/cmd/gc/mparith2.c
View file @
c4de2498
...
...
@@ -570,7 +570,12 @@ mpmovecfix(Mpint *a, vlong c)
void
mpdivmodfixfix
(
Mpint
*
q
,
Mpint
*
r
,
Mpint
*
n
,
Mpint
*
d
)
{
int
i
;
int
i
,
ns
,
ds
;
ns
=
n
->
neg
;
ds
=
d
->
neg
;
n
->
neg
=
0
;
d
->
neg
=
0
;
mpmovefixfix
(
r
,
n
);
mpmovecfix
(
q
,
0
);
...
...
@@ -588,6 +593,8 @@ mpdivmodfixfix(Mpint *q, Mpint *r, Mpint *n, Mpint *d)
if
(
i
>=
Mpprec
*
Mpscale
)
{
q
->
ovf
=
1
;
r
->
ovf
=
1
;
n
->
neg
=
ns
;
d
->
neg
=
ds
;
yyerror
(
"set ovf in mpdivmodfixfix"
);
return
;
}
...
...
@@ -604,6 +611,11 @@ mpdivmodfixfix(Mpint *q, Mpint *r, Mpint *n, Mpint *d)
mpsubfixfix
(
r
,
d
);
}
}
n
->
neg
=
ns
;
d
->
neg
=
ds
;
r
->
neg
=
ns
;
q
->
neg
=
ns
^
ds
;
}
void
...
...
test/ken/divmod.go
0 → 100644
View file @
c4de2498
// $G $D/$F.go && $L $F.$A && ./$A.out
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
main
const
(
n1
=
+
5
;
n2
=
-
5
;
d1
=
+
3
;
d2
=
-
3
;
q1
=
+
1
;
q2
=
-
1
;
q3
=
-
1
;
q4
=
+
1
;
r1
=
+
2
;
r2
=
-
2
;
r3
=
+
2
;
r4
=
-
2
;
)
func
main
()
{
/* ideals */
if
n1
/
d1
!=
q1
||
n1
%
d1
!=
r1
{
panicln
(
n1
,
d1
,
n1
/
d1
,
n1
%
d1
);
}
if
n2
/
d1
!=
q2
||
n2
%
d1
!=
r2
{
panicln
(
n2
,
d1
,
n2
/
d1
,
n2
%
d1
);
}
if
n1
/
d2
!=
q3
||
n1
%
d2
!=
r3
{
panicln
(
n1
,
d2
,
n1
/
d2
,
n1
%
d2
);
}
if
n2
/
d2
!=
q4
||
n2
%
d2
!=
r4
{
panicln
(
n2
,
d2
,
n2
/
d2
,
n2
%
d2
);
}
/* int */
var
in1
int
=
+
5
;
var
in2
int
=
-
5
;
var
id1
int
=
+
3
;
var
id2
int
=
-
3
;
if
in1
/
id1
!=
q1
||
in1
%
id1
!=
r1
{
panicln
(
in1
,
id1
,
in1
/
id1
,
in1
%
id1
);
}
if
in2
/
id1
!=
q2
||
in2
%
id1
!=
r2
{
panicln
(
in2
,
id1
,
in2
/
id1
,
in2
%
id1
);
}
if
in1
/
id2
!=
q3
||
in1
%
id2
!=
r3
{
panicln
(
in1
,
id2
,
in1
/
id2
,
in1
%
id2
);
}
if
in2
/
id2
!=
q4
||
in2
%
id2
!=
r4
{
panicln
(
in2
,
id2
,
in2
/
id2
,
in2
%
id2
);
}
/* int8 */
var
bn1
int8
=
+
5
;
var
bn2
int8
=
-
5
;
var
bd1
int8
=
+
3
;
var
bd2
int8
=
-
3
;
if
bn1
/
bd1
!=
q1
||
bn1
%
bd1
!=
r1
{
panicln
(
bn1
,
bd1
,
bn1
/
bd1
,
bn1
%
bd1
);
}
if
bn2
/
bd1
!=
q2
||
bn2
%
bd1
!=
r2
{
panicln
(
bn2
,
bd1
,
bn2
/
bd1
,
bn2
%
bd1
);
}
if
bn1
/
bd2
!=
q3
||
bn1
%
bd2
!=
r3
{
panicln
(
bn1
,
bd2
,
bn1
/
bd2
,
bn1
%
bd2
);
}
if
bn2
/
bd2
!=
q4
||
bn2
%
bd2
!=
r4
{
panicln
(
bn2
,
bd2
,
bn2
/
bd2
,
bn2
%
bd2
);
}
/* int16 */
var
sn1
int16
=
+
5
;
var
sn2
int16
=
-
5
;
var
sd1
int16
=
+
3
;
var
sd2
int16
=
-
3
;
if
sn1
/
sd1
!=
q1
||
sn1
%
sd1
!=
r1
{
panicln
(
sn1
,
sd1
,
sn1
/
sd1
,
sn1
%
sd1
);
}
if
sn2
/
sd1
!=
q2
||
sn2
%
sd1
!=
r2
{
panicln
(
sn2
,
sd1
,
sn2
/
sd1
,
sn2
%
sd1
);
}
if
sn1
/
sd2
!=
q3
||
sn1
%
sd2
!=
r3
{
panicln
(
sn1
,
sd2
,
sn1
/
sd2
,
sn1
%
sd2
);
}
if
sn2
/
sd2
!=
q4
||
sn2
%
sd2
!=
r4
{
panicln
(
sn2
,
sd2
,
sn2
/
sd2
,
sn2
%
sd2
);
}
/* int32 */
var
ln1
int32
=
+
5
;
var
ln2
int32
=
-
5
;
var
ld1
int32
=
+
3
;
var
ld2
int32
=
-
3
;
if
ln1
/
ld1
!=
q1
||
ln1
%
ld1
!=
r1
{
panicln
(
ln1
,
ld1
,
ln1
/
ld1
,
ln1
%
ld1
);
}
if
ln2
/
ld1
!=
q2
||
ln2
%
ld1
!=
r2
{
panicln
(
ln2
,
ld1
,
ln2
/
ld1
,
ln2
%
ld1
);
}
if
ln1
/
ld2
!=
q3
||
ln1
%
ld2
!=
r3
{
panicln
(
ln1
,
ld2
,
ln1
/
ld2
,
ln1
%
ld2
);
}
if
ln2
/
ld2
!=
q4
||
ln2
%
ld2
!=
r4
{
panicln
(
ln2
,
ld2
,
ln2
/
ld2
,
ln2
%
ld2
);
}
/* int64 */
var
qn1
int64
=
+
5
;
var
qn2
int64
=
-
5
;
var
qd1
int64
=
+
3
;
var
qd2
int64
=
-
3
;
if
qn1
/
qd1
!=
q1
||
qn1
%
qd1
!=
r1
{
panicln
(
qn1
,
qd1
,
qn1
/
qd1
,
qn1
%
qd1
);
}
if
qn2
/
qd1
!=
q2
||
qn2
%
qd1
!=
r2
{
panicln
(
qn2
,
qd1
,
qn2
/
qd1
,
qn2
%
qd1
);
}
if
qn1
/
qd2
!=
q3
||
qn1
%
qd2
!=
r3
{
panicln
(
qn1
,
qd2
,
qn1
/
qd2
,
qn1
%
qd2
);
}
if
qn2
/
qd2
!=
q4
||
qn2
%
qd2
!=
r4
{
panicln
(
qn2
,
qd2
,
qn2
/
qd2
,
qn2
%
qd2
);
}
/* uint */
var
uin1
uint
=
+
5
;
var
uid1
uint
=
+
3
;
if
uin1
/
uid1
!=
q1
||
uin1
%
uid1
!=
r1
{
panicln
(
uin1
,
uid1
,
uin1
/
uid1
,
uin1
%
uid1
);
}
/* uint8 */
var
ubn1
uint8
=
+
5
;
var
ubd1
uint8
=
+
3
;
if
ubn1
/
ubd1
!=
q1
||
ubn1
%
ubd1
!=
r1
{
panicln
(
ubn1
,
ubd1
,
ubn1
/
ubd1
,
ubn1
%
ubd1
);
}
/* uint16 */
var
usn1
uint16
=
+
5
;
var
usd1
uint16
=
+
3
;
if
usn1
/
usd1
!=
q1
||
usn1
%
usd1
!=
r1
{
panicln
(
usn1
,
usd1
,
usn1
/
usd1
,
usn1
%
usd1
);
}
/* uint32 */
var
uln1
uint32
=
+
5
;
var
uld1
uint32
=
+
3
;
if
uln1
/
uld1
!=
q1
||
uln1
%
uld1
!=
r1
{
panicln
(
uln1
,
uld1
,
uln1
/
uld1
,
uln1
%
uld1
);
}
/* uint64 */
var
uqn1
uint64
=
+
5
;
var
uqd1
uint64
=
+
3
;
if
uqn1
/
uqd1
!=
q1
||
uqn1
%
uqd1
!=
r1
{
panicln
(
uqn1
,
uqd1
,
uqn1
/
uqd1
,
uqn1
%
uqd1
);
}
if
n1
/
uqd1
!=
q1
||
n1
%
uqd1
!=
r1
{
panicln
(
n1
,
uqd1
,
n1
/
uqd1
,
n1
%
uqd1
);
}
if
uqn1
/
d1
!=
q1
||
uqn1
%
d1
!=
r1
{
panicln
(
uqn1
,
d1
,
uqn1
/
d1
,
uqn1
%
d1
);
}
}
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