Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
83feedf7
Commit
83feedf7
authored
Feb 19, 2012
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gc: fix error for floating-point constant %
R=ken2 CC=golang-dev
https://golang.org/cl/5674108
parent
03f2289f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
27 deletions
+36
-27
src/cmd/gc/const.c
src/cmd/gc/const.c
+8
-0
test/const1.go
test/const1.go
+28
-27
No files found.
src/cmd/gc/const.c
View file @
83feedf7
...
...
@@ -660,6 +660,14 @@ evconst(Node *n)
}
mpdivfltflt
(
v
.
u
.
fval
,
rv
.
u
.
fval
);
break
;
case
TUP
(
OMOD
,
CTFLT
):
// The default case above would print 'ideal % ideal',
// which is not quite an ideal error.
if
(
!
n
->
diag
)
{
yyerror
(
"illegal constant expression: floating-point %% operation"
);
n
->
diag
=
1
;
}
return
;
case
TUP
(
OADD
,
CTCPLX
):
mpaddfltflt
(
&
v
.
u
.
cval
->
real
,
&
rv
.
u
.
cval
->
real
);
mpaddfltflt
(
&
v
.
u
.
cval
->
imag
,
&
rv
.
u
.
cval
->
imag
);
...
...
test/const1.go
View file @
83feedf7
...
...
@@ -16,11 +16,11 @@ const (
Int8
int8
=
101
Minus1
int8
=
-
1
Uint8
uint8
=
102
Const
=
103
Const
=
103
Float32
float32
=
104.5
Float64
float64
=
105.5
ConstFloat
=
106.5
ConstFloat
=
106.5
Big
float64
=
1e300
String
=
"abc"
...
...
@@ -38,32 +38,33 @@ var (
a8
=
Int8
*
Const
/
100
// ERROR "overflow"
a9
=
Int8
*
(
Const
/
100
)
// OK
b1
=
Uint8
*
Uint8
// ERROR "overflow"
b2
=
Uint8
*
-
1
// ERROR "overflow"
b3
=
Uint8
-
Uint8
// OK
b4
=
Uint8
-
Uint8
-
Uint8
// ERROR "overflow"
b5
=
uint8
(
^
0
)
// ERROR "overflow"
b6
=
^
uint8
(
0
)
// OK
b7
=
uint8
(
Minus1
)
// ERROR "overflow"
b8
=
uint8
(
int8
(
-
1
))
// ERROR "overflow"
b8a
=
uint8
(
-
1
)
// ERROR "overflow"
b9
byte
=
(
1
<<
10
)
>>
8
// OK
b10
byte
=
(
1
<<
10
)
// ERROR "overflow"
b11
byte
=
(
byte
(
1
)
<<
10
)
>>
8
// ERROR "overflow"
b12
byte
=
1000
// ERROR "overflow"
b13
byte
=
byte
(
1000
)
// ERROR "overflow"
b14
byte
=
byte
(
100
)
*
byte
(
100
)
// ERROR "overflow"
b15
byte
=
byte
(
100
)
*
100
// ERROR "overflow"
b16
byte
=
byte
(
0
)
*
1000
// ERROR "overflow"
b16a
byte
=
0
*
1000
// OK
b17
byte
=
byte
(
0
)
*
byte
(
1000
)
// ERROR "overflow"
b18
byte
=
Uint8
/
0
// ERROR "division by zero"
b1
=
Uint8
*
Uint8
// ERROR "overflow"
b2
=
Uint8
*
-
1
// ERROR "overflow"
b3
=
Uint8
-
Uint8
// OK
b4
=
Uint8
-
Uint8
-
Uint8
// ERROR "overflow"
b5
=
uint8
(
^
0
)
// ERROR "overflow"
b6
=
^
uint8
(
0
)
// OK
b7
=
uint8
(
Minus1
)
// ERROR "overflow"
b8
=
uint8
(
int8
(
-
1
))
// ERROR "overflow"
b8a
=
uint8
(
-
1
)
// ERROR "overflow"
b9
byte
=
(
1
<<
10
)
>>
8
// OK
b10
byte
=
(
1
<<
10
)
// ERROR "overflow"
b11
byte
=
(
byte
(
1
)
<<
10
)
>>
8
// ERROR "overflow"
b12
byte
=
1000
// ERROR "overflow"
b13
byte
=
byte
(
1000
)
// ERROR "overflow"
b14
byte
=
byte
(
100
)
*
byte
(
100
)
// ERROR "overflow"
b15
byte
=
byte
(
100
)
*
100
// ERROR "overflow"
b16
byte
=
byte
(
0
)
*
1000
// ERROR "overflow"
b16a
byte
=
0
*
1000
// OK
b17
byte
=
byte
(
0
)
*
byte
(
1000
)
// ERROR "overflow"
b18
byte
=
Uint8
/
0
// ERROR "division by zero"
c1
float64
=
Big
c2
float64
=
Big
*
Big
// ERROR "overflow"
c3
float64
=
float64
(
Big
)
*
Big
// ERROR "overflow"
c4
=
Big
*
Big
// ERROR "overflow"
c5
=
Big
/
0
// ERROR "division by zero"
c1
float64
=
Big
c2
float64
=
Big
*
Big
// ERROR "overflow"
c3
float64
=
float64
(
Big
)
*
Big
// ERROR "overflow"
c4
=
Big
*
Big
// ERROR "overflow"
c5
=
Big
/
0
// ERROR "division by zero"
c6
=
1000
%
1e3
// ERROR "floating-point % operation"
)
func
f
(
int
)
...
...
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