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
a1585b67
Commit
a1585b67
authored
Nov 17, 2008
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix the easy parts of bug120
R=r,ken DELTA=66 (52 added, 3 deleted, 11 changed) OCL=19386 CL=19389
parent
b7f01f9f
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
64 additions
and
15 deletions
+64
-15
src/cmd/gc/go.h
src/cmd/gc/go.h
+1
-0
src/cmd/gc/mparith1.c
src/cmd/gc/mparith1.c
+14
-3
src/cmd/gc/mparith2.c
src/cmd/gc/mparith2.c
+11
-0
test/bugs/bug120.go
test/bugs/bug120.go
+20
-1
test/const.go
test/const.go
+1
-1
test/convlit.go
test/convlit.go
+1
-1
test/fmt_test.go
test/fmt_test.go
+1
-1
test/golden.out
test/golden.out
+15
-8
No files found.
src/cmd/gc/go.h
View file @
a1585b67
...
@@ -558,6 +558,7 @@ void mprshfixfix(Mpint *a, Mpint *b);
...
@@ -558,6 +558,7 @@ void mprshfixfix(Mpint *a, Mpint *b);
void
mpxorfixfix
(
Mpint
*
a
,
Mpint
*
b
);
void
mpxorfixfix
(
Mpint
*
a
,
Mpint
*
b
);
void
mpcomfix
(
Mpint
*
a
);
void
mpcomfix
(
Mpint
*
a
);
vlong
mpgetfix
(
Mpint
*
a
);
vlong
mpgetfix
(
Mpint
*
a
);
double
mpgetfixflt
(
Mpint
*
a
);
/*
/*
* mparith3.c
* mparith3.c
...
...
src/cmd/gc/mparith1.c
View file @
a1585b67
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
#include <u.h>
#include <errno.h>
#include "go.h"
#include "go.h"
/// uses arithmetic
/// uses arithmetic
...
@@ -149,7 +151,7 @@ mpcomfix(Mpint *a)
...
@@ -149,7 +151,7 @@ mpcomfix(Mpint *a)
void
void
mpmovefixflt
(
Mpflt
*
a
,
Mpint
*
b
)
mpmovefixflt
(
Mpflt
*
a
,
Mpint
*
b
)
{
{
mpmovecflt
(
a
,
mpgetfix
(
b
));
mpmovecflt
(
a
,
mpgetfix
flt
(
b
));
}
}
void
void
...
@@ -200,6 +202,15 @@ mpatoflt(Mpflt *a, char *as)
...
@@ -200,6 +202,15 @@ mpatoflt(Mpflt *a, char *as)
{
{
int
dp
,
c
,
f
,
ef
,
ex
,
zer
;
int
dp
,
c
,
f
,
ef
,
ex
,
zer
;
char
*
s
;
char
*
s
;
double
f64
;
/* until Mpflt is really mp, use strtod to get rounding right */
errno
=
0
;
f64
=
strtod
(
as
,
&
s
);
mpmovecflt
(
a
,
f64
);
if
(
errno
!=
0
)
a
->
ovf
=
1
;
return
;
s
=
as
;
s
=
as
;
dp
=
0
;
/* digits after decimal point */
dp
=
0
;
/* digits after decimal point */
...
@@ -279,14 +290,14 @@ mpatoflt(Mpflt *a, char *as)
...
@@ -279,14 +290,14 @@ mpatoflt(Mpflt *a, char *as)
return
;
return
;
bad:
bad:
warn
(
"set ovf in mpatof
"
);
warn
(
"set ovf in mpatof
: %s"
,
as
);
mpmovecflt
(
a
,
0
.
0
);
mpmovecflt
(
a
,
0
.
0
);
}
}
//
//
// fixed point input
// fixed point input
// required syntax is [+-][0[x]]d*
// required syntax is [+-][0[x]]d*
//
//
void
void
mpatofix
(
Mpint
*
a
,
char
*
as
)
mpatofix
(
Mpint
*
a
,
char
*
as
)
{
{
...
...
src/cmd/gc/mparith2.c
View file @
a1585b67
...
@@ -459,6 +459,17 @@ mpgetfix(Mpint *a)
...
@@ -459,6 +459,17 @@ mpgetfix(Mpint *a)
return
v
;
return
v
;
}
}
double
mpgetfixflt
(
Mpint
*
a
)
{
// answer might not fit in intermediate vlong, so format
// to string and then let the string routine convert.
char
buf
[
1000
];
snprint
(
buf
,
sizeof
buf
,
"%B"
,
a
);
return
strtod
(
buf
,
nil
);
}
void
void
mpmovecfix
(
Mpint
*
a
,
vlong
c
)
mpmovecfix
(
Mpint
*
a
,
vlong
c
)
{
{
...
...
test/bugs/bug120.go
View file @
a1585b67
...
@@ -19,8 +19,21 @@ var tests = []Test {
...
@@ -19,8 +19,21 @@ var tests = []Test {
Test
{
456.7
,
"456.7"
,
"456.7"
},
Test
{
456.7
,
"456.7"
,
"456.7"
},
Test
{
1e23
+
8.5e6
,
"1e23+8.5e6"
,
"1.0000000000000001e+23"
},
Test
{
1e23
+
8.5e6
,
"1e23+8.5e6"
,
"1.0000000000000001e+23"
},
Test
{
100000000000000008388608
,
"100000000000000008388608"
,
"1.0000000000000001e+23"
},
Test
{
100000000000000008388608
,
"100000000000000008388608"
,
"1.0000000000000001e+23"
},
Test
{
1e23
+
8388609
,
"1e23+8388609"
,
"1.0000000000000001e+23"
},
// "x" = the floating point value from converting the string x.
// These are exactly representable in 64-bit floating point:
// 1e23-8388608
// 1e23+8388608
// The former has an even mantissa, so "1e23" rounds to 1e23-8388608.
// If "1e23+8388608" is implemented as "1e23" + "8388608",
// that ends up computing 1e23-8388608 + 8388608 = 1e23,
// which rounds back to 1e23-8388608.
// The correct answer, of course, would be "1e23+8388608" = 1e23+8388608.
// This is not going to be correct until 6g has multiprecision floating point.
// A simpler case is "1e23+1", which should also round to 1e23+8388608.
Test
{
1e23
+
8.388608e6
,
"1e23+8.388608e6"
,
"1.0000000000000001e+23"
},
Test
{
1e23
+
8.388608e6
,
"1e23+8.388608e6"
,
"1.0000000000000001e+23"
},
Test
{
1e23
+
8.388609e6
,
"1e23+8.388609e6
"
,
"1.0000000000000001e+23"
},
Test
{
1e23
+
1
,
"1e23+1
"
,
"1.0000000000000001e+23"
},
}
}
func
main
()
{
func
main
()
{
...
@@ -30,6 +43,12 @@ func main() {
...
@@ -30,6 +43,12 @@ func main() {
v
:=
strconv
.
ftoa64
(
t
.
f
,
'g'
,
-
1
);
v
:=
strconv
.
ftoa64
(
t
.
f
,
'g'
,
-
1
);
if
v
!=
t
.
out
{
if
v
!=
t
.
out
{
println
(
"Bad float64 const:"
,
t
.
in
,
"want"
,
t
.
out
,
"got"
,
v
);
println
(
"Bad float64 const:"
,
t
.
in
,
"want"
,
t
.
out
,
"got"
,
v
);
x
,
overflow
,
ok
:=
strconv
.
atof64
(
t
.
out
);
if
!
ok
{
panicln
(
"bug120: strconv.atof64"
,
t
.
out
);
}
println
(
"
\t
want exact:"
,
strconv
.
ftoa64
(
x
,
'g'
,
1000
));
println
(
"
\t
got exact: "
,
strconv
.
ftoa64
(
t
.
f
,
'g'
,
1000
));
ok
=
false
;
ok
=
false
;
}
}
}
}
...
...
test/const.go
View file @
a1585b67
...
@@ -76,7 +76,7 @@ func ints() {
...
@@ -76,7 +76,7 @@ func ints() {
func
floats
()
{
func
floats
()
{
assert
(
f0
==
c0
,
"f0"
);
assert
(
f0
==
c0
,
"f0"
);
assert
(
f1
==
c1
,
"f1"
);
assert
(
f1
==
c1
,
"f1"
);
assert
(
fhuge
>
fhuge_1
,
"fhuge"
);
assert
(
fhuge
==
fhuge_1
,
"fhuge"
);
// float64 can't distinguish fhuge, fhuge_1.
assert
(
fhuge_1
+
1
==
fhuge
,
"fhuge 1"
);
assert
(
fhuge_1
+
1
==
fhuge
,
"fhuge 1"
);
assert
(
fhuge
+
fm1
+
1
==
fhuge
,
"fm1"
);
assert
(
fhuge
+
fm1
+
1
==
fhuge
,
"fm1"
);
assert
(
f3div2
==
1.5
,
"3./2."
);
assert
(
f3div2
==
1.5
,
"3./2."
);
...
...
test/convlit.go
View file @
a1585b67
...
@@ -25,7 +25,7 @@ var bad5 = "a" + 'a'; // ERROR "literals|incompatible"
...
@@ -25,7 +25,7 @@ var bad5 = "a" + 'a'; // ERROR "literals|incompatible"
var
bad6
int
=
1.5
;
// ERROR "convert"
var
bad6
int
=
1.5
;
// ERROR "convert"
var
bad7
int
=
1e100
;
// ERROR "overflow"
var
bad7
int
=
1e100
;
// ERROR "overflow"
var
bad8
float
=
1e10
00
;
// ERROR "overflow"
var
bad8
float
32
=
1e2
00
;
// ERROR "overflow"
// but these implicit conversions are okay
// but these implicit conversions are okay
var
good1
string
=
"a"
;
var
good1
string
=
"a"
;
...
...
test/fmt_test.go
View file @
a1585b67
...
@@ -80,7 +80,7 @@ func main() {
...
@@ -80,7 +80,7 @@ func main() {
E
(
f
.
s
(
"
\t
20.8e
\t
|"
)
.
wp
(
20
,
8
)
.
e
(
1.2345e3
)
.
s
(
"|"
),
"
\t
20.8e
\t
| 1.23450000e+03|"
);
E
(
f
.
s
(
"
\t
20.8e
\t
|"
)
.
wp
(
20
,
8
)
.
e
(
1.2345e3
)
.
s
(
"|"
),
"
\t
20.8e
\t
| 1.23450000e+03|"
);
E
(
f
.
s
(
"
\t
20f
\t
|"
)
.
w
(
20
)
.
f64
(
1.23456789e3
)
.
s
(
"|"
),
"
\t
20f
\t
| 1234.567890|"
);
E
(
f
.
s
(
"
\t
20f
\t
|"
)
.
w
(
20
)
.
f64
(
1.23456789e3
)
.
s
(
"|"
),
"
\t
20f
\t
| 1234.567890|"
);
E
(
f
.
s
(
"
\t
20f
\t
|"
)
.
w
(
20
)
.
f64
(
1.23456789e-3
)
.
s
(
"|"
),
"
\t
20f
\t
| 0.001235|"
);
E
(
f
.
s
(
"
\t
20f
\t
|"
)
.
w
(
20
)
.
f64
(
1.23456789e-3
)
.
s
(
"|"
),
"
\t
20f
\t
| 0.001235|"
);
E
(
f
.
s
(
"
\t
20f
\t
|"
)
.
w
(
20
)
.
f64
(
12345678901.23456789
)
.
s
(
"|"
),
"
\t
20f
\t
| 12345678901.2345
70
|"
);
E
(
f
.
s
(
"
\t
20f
\t
|"
)
.
w
(
20
)
.
f64
(
12345678901.23456789
)
.
s
(
"|"
),
"
\t
20f
\t
| 12345678901.2345
68
|"
);
E
(
f
.
s
(
"
\t
-20f
\t
|"
)
.
w
(
-
20
)
.
f64
(
1.23456789e3
)
.
s
(
"|"
),
"
\t
-20f
\t
|1234.567890 |"
);
E
(
f
.
s
(
"
\t
-20f
\t
|"
)
.
w
(
-
20
)
.
f64
(
1.23456789e3
)
.
s
(
"|"
),
"
\t
-20f
\t
|1234.567890 |"
);
E
(
f
.
s
(
"
\t
20.8f
\t
|"
)
.
wp
(
20
,
8
)
.
f64
(
1.23456789e3
)
.
s
(
"|"
),
"
\t
20.8f
\t
| 1234.56789000|"
);
E
(
f
.
s
(
"
\t
20.8f
\t
|"
)
.
wp
(
20
,
8
)
.
f64
(
1.23456789e3
)
.
s
(
"|"
),
"
\t
20.8f
\t
| 1234.56789000|"
);
E
(
f
.
s
(
"
\t
20.8f
\t
|"
)
.
wp
(
20
,
8
)
.
f64
(
1.23456789e-3
)
.
s
(
"|"
),
"
\t
20.8f
\t
| 0.00123457|"
);
E
(
f
.
s
(
"
\t
20.8f
\t
|"
)
.
wp
(
20
,
8
)
.
f64
(
1.23456789e-3
)
.
s
(
"|"
),
"
\t
20.8f
\t
| 0.00123457|"
);
...
...
test/golden.out
View file @
a1585b67
...
@@ -11,11 +11,10 @@ errchk: ./convlit.go: unmatched error messages:
...
@@ -11,11 +11,10 @@ errchk: ./convlit.go: unmatched error messages:
==================================================
==================================================
./convlit.go:8: cannot convert non-integer constant to int
./convlit.go:8: cannot convert non-integer constant to int
./convlit.go:11: overflow converting constant to int
./convlit.go:11: overflow converting constant to int
./convlit.go:12: overflow
converting constant to floa
t
./convlit.go:12: overflow
in float constan
t
./convlit.go:8: cannot convert non-integer constant to int
./convlit.go:8: cannot convert non-integer constant to int
./convlit.go:9: cannot convert non-integer constant to int
./convlit.go:9: cannot convert non-integer constant to int
./convlit.go:11: overflow converting constant to int
./convlit.go:11: overflow converting constant to int
./convlit.go:12: overflow converting constant to float
==================================================
==================================================
=========== ./helloworld.go
=========== ./helloworld.go
...
@@ -37,6 +36,9 @@ Faulting address: 0x0
...
@@ -37,6 +36,9 @@ Faulting address: 0x0
pc: xxx
pc: xxx
=========== ./method2.go
BUG: errchk: command succeeded unexpectedly: 6g ./method2.go
=========== ./peano.go
=========== ./peano.go
0! = 1
0! = 1
1! = 1
1! = 1
...
@@ -88,6 +90,9 @@ BUG should compile
...
@@ -88,6 +90,9 @@ BUG should compile
=========== bugs/bug041.go
=========== bugs/bug041.go
BUG: compilation succeeds incorrectly
BUG: compilation succeeds incorrectly
=========== bugs/bug046.go
BUG: errchk: command succeeded unexpectedly: 6g bugs/bug046.go
=========== bugs/bug064.go
=========== bugs/bug064.go
bugs/bug064.go:15: illegal types for operand: CALL
bugs/bug064.go:15: illegal types for operand: CALL
int
int
...
@@ -115,6 +120,9 @@ bugs/bug098.go:10: illegal types for operand: AS
...
@@ -115,6 +120,9 @@ bugs/bug098.go:10: illegal types for operand: AS
**M
**M
BUG should compile
BUG should compile
=========== bugs/bug104.go
BUG: errchk: command succeeded unexpectedly: 6g bugs/bug104.go
=========== bugs/bug105.go
=========== bugs/bug105.go
bugs/bug105.go:8: P: undefined
bugs/bug105.go:8: P: undefined
bugs/bug105.go:9: illegal types for operand: RETURN
bugs/bug105.go:9: illegal types for operand: RETURN
...
@@ -142,13 +150,12 @@ panic on line 85 PC=xxx
...
@@ -142,13 +150,12 @@ panic on line 85 PC=xxx
BUG: should not fail
BUG: should not fail
=========== bugs/bug120.go
=========== bugs/bug120.go
Bad float64 const: 456.7 want 456.7 got 456.70000000000005
Bad float64 const: 100000000000000008388608 want 1.0000000000000001e+23 got 2.0037642052907827e+17
Bad float64 const: 1e23+8.388608e6 want 1.0000000000000001e+23 got 1e+23
Bad float64 const: 1e23+8.388608e6 want 1.0000000000000001e+23 got 1e+23
bug120
want exact: 100000000000000008388608
got exact: 99999999999999991611392
panic on line 139 PC=xxx
Bad float64 const: 1e23+1 want 1.0000000000000001e+23 got 1e+23
BUG: bug120
want exact: 100000000000000008388608
got exact: 99999999999999991611392
=========== fixedbugs/bug016.go
=========== fixedbugs/bug016.go
fixedbugs/bug016.go:7: overflow converting constant to uint
fixedbugs/bug016.go:7: overflow converting constant to uint
...
...
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