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
b1a3463a
Commit
b1a3463a
authored
Jun 10, 2008
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
made fp numbers from integers and
checked values SVN=121972
parent
36f21e00
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
56 deletions
+72
-56
float_lit.go
test/float_lit.go
+72
-56
No files found.
test/float_lit.go
View file @
b1a3463a
...
...
@@ -7,87 +7,103 @@
package
main
func
close
(
a
,
b
double
)
bool
pow10
(
pow
int
)
double
{
if
a
==
0
{
if
b
==
0
{
if
pow
<
0
{
return
1
/
pow10
(
-
pow
);
}
if
pow
>
0
{
return
pow10
(
pow
-
1
)
*
10
;
}
return
1
;
}
func
close
(
da
double
,
ia
,
ib
int64
,
pow
int
)
bool
{
db
:=
double
(
ia
)
/
double
(
ib
);
db
=
db
*
pow10
(
pow
);
if
da
==
0
{
if
db
==
0
{
return
true
;
}
return
false
;
}
d
:=
a
-
b
;
if
d
<
0
{
d
=
-
d
;
dd
:=
da
-
db
;
if
dd
<
0
{
dd
=
-
dd
;
}
e
:=
a
;
if
e
<
0
{
e
=
-
e
;
de
:=
da
;
if
de
<
0
{
de
=
-
de
;
}
if
e
*
1.0e-14
>
d
{
if
de
*
1.0e-14
>
dd
{
return
true
;
}
return
false
;
}
func
main
()
int
{
func
main
()
{
if
!
close
(
0.
,
0
.
)
{
print
"0. is "
,
0.
,
" should be "
,
0.
,
"
\n
"
;
return
1
;
}
if
!
close
(
+
10.
,
+
10.
)
{
print
"+10. is "
,
+
10.
,
" should be "
,
+
10.
,
"
\n
"
;
return
1
;
}
if
!
close
(
-
210.
,
-
210
.
)
{
print
"-210. is "
,
-
210.
,
" should be "
,
-
210.
,
"
\n
"
;
return
1
;
}
if
!
close
(
0.
,
0
,
1
,
0
)
{
print
"0. is "
,
0.
,
"
\n
"
;
}
if
!
close
(
+
10.
,
10
,
1
,
0
)
{
print
"+10. is "
,
+
10.
,
"
\n
"
;
}
if
!
close
(
-
210.
,
-
210
,
1
,
0
)
{
print
"-210. is "
,
-
210.
,
"
\n
"
;
}
if
!
close
(
.0
,
.0
)
{
print
".0 is "
,
.0
,
" should be "
,
.0
,
"
\n
"
;
return
1
;
}
if
!
close
(
+
.01
,
+
.01
)
{
print
"+.01 is "
,
+
.01
,
" should be "
,
+
.01
,
"
\n
"
;
return
1
;
}
if
!
close
(
-
.012
,
-
.012
)
{
print
"-.012 is "
,
-
.012
,
" should be "
,
-
.012
,
"
\n
"
;
return
1
;
}
if
!
close
(
.0
,
0
,
1
,
0
)
{
print
".0 is "
,
.0
,
"
\n
"
;
}
if
!
close
(
+
.01
,
1
,
100
,
0
)
{
print
"+.01 is "
,
+
.01
,
"
\n
"
;
}
if
!
close
(
-
.012
,
-
12
,
1000
,
0
)
{
print
"-.012 is "
,
-
.012
,
"
\n
"
;
}
if
!
close
(
0.0
,
0
.0
)
{
print
"0.0 is "
,
0.0
,
" should be "
,
0.0
,
"
\n
"
;
return
1
;
}
if
!
close
(
+
10.01
,
+
10.01
)
{
print
"+10.01 is "
,
+
10.01
,
" should be "
,
+
10.01
,
"
\n
"
;
return
1
;
}
if
!
close
(
-
210.012
,
-
210
.012
)
{
print
"-210.012 is "
,
-
210.012
,
" should be "
,
-
210.012
,
"
\n
"
;
return
1
;
}
if
!
close
(
0.0
,
0
,
1
,
0
)
{
print
"0.0 is "
,
0.0
,
"
\n
"
;
}
if
!
close
(
+
10.01
,
1001
,
100
,
0
)
{
print
"+10.01 is "
,
+
10.01
,
"
\n
"
;
}
if
!
close
(
-
210.012
,
-
210
012
,
1000
,
0
)
{
print
"-210.012 is "
,
-
210.012
,
"
\n
"
;
}
if
!
close
(
0E+1
,
0
E+1
)
{
print
"0E+1 is "
,
0E+1
,
" should be "
,
0E+1
,
"
\n
"
;
return
1
;
}
if
!
close
(
+
10e2
,
+
10e2
)
{
print
"+10e2 is "
,
+
10e2
,
" should be "
,
+
10e2
,
"
\n
"
;
return
1
;
}
if
!
close
(
-
210e3
,
-
210
e3
)
{
print
"-210e3 is "
,
-
210e3
,
" should be "
,
-
210e3
,
"
\n
"
;
return
1
;
}
if
!
close
(
0E+1
,
0
,
1
,
0
)
{
print
"0E+1 is "
,
0E+1
,
"
\n
"
;
}
if
!
close
(
+
10e2
,
10
,
1
,
2
)
{
print
"+10e2 is "
,
+
10e2
,
"
\n
"
;
}
if
!
close
(
-
210e3
,
-
210
,
1
,
3
)
{
print
"-210e3 is "
,
-
210e3
,
"
\n
"
;
}
if
!
close
(
0E-1
,
0
E-1
)
{
print
"0E-1 is "
,
0E-1
,
" should be "
,
0E-1
,
"
\n
"
;
return
1
;
}
if
!
close
(
+
0e23
,
+
0e23
)
{
print
"+0e23 is "
,
+
0e23
,
" should be "
,
+
0e23
,
"
\n
"
;
return
1
;
}
if
!
close
(
-
0e345
,
-
0e345
)
{
print
"-0e345 is "
,
-
0e345
,
" should be "
,
-
0e345
,
"
\n
"
;
return
1
;
}
if
!
close
(
0E-1
,
0
,
1
,
0
)
{
print
"0E-1 is "
,
0E-1
,
"
\n
"
;
}
if
!
close
(
+
0e23
,
0
,
1
,
23
)
{
print
"+0e23 is "
,
+
0e23
,
"
\n
"
;
}
if
!
close
(
-
0e345
,
0
,
1
,
345
)
{
print
"-0e345 is "
,
-
0e345
,
"
\n
"
;
}
if
!
close
(
0E1
,
0
E1
)
{
print
"0E1 is "
,
0E1
,
" should be "
,
0E1
,
"
\n
"
;
return
1
;
}
if
!
close
(
+
10e23
,
+
10e23
)
{
print
"+10e23 is "
,
+
10e23
,
" should be "
,
+
10e23
,
"
\n
"
;
return
1
;
}
// if !close(-210e345, -210e345) { print "-210e345 is ", -210e345, " should be ", -210e345, "\n"; return 1
; }
if
!
close
(
0E1
,
0
,
1
,
1
)
{
print
"0E1 is "
,
0E1
,
"
\n
"
;
}
if
!
close
(
+
10e23
,
10
,
1
,
23
)
{
print
"+10e23 is "
,
+
10e23
,
"
\n
"
;
}
if
!
close
(
-
210e34
,
-
210
,
1
,
34
)
{
print
"-210e34 is "
,
-
210e34
,
"
\n
"
;
}
if
!
close
(
0.E1
,
0
.E1
)
{
print
"0.E1 is "
,
0.E1
,
" should be "
,
0.E1
,
"
\n
"
;
return
1
;
}
if
!
close
(
+
10.e+2
,
+
10.e+2
)
{
print
"+10.e+2 is "
,
+
10.e+2
,
" should be "
,
+
10.e+2
,
"
\n
"
;
return
1
;
}
if
!
close
(
-
210.e-3
,
-
210
.e-3
)
{
print
"-210.e-3 is "
,
-
210.e-3
,
" should be "
,
-
210.e-3
,
"
\n
"
;
return
1
;
}
if
!
close
(
0.E1
,
0
,
1
,
1
)
{
print
"0.E1 is "
,
0.E1
,
"
\n
"
;
}
if
!
close
(
+
10.e+2
,
10
,
1
,
2
)
{
print
"+10.e+2 is "
,
+
10.e+2
,
"
\n
"
;
}
if
!
close
(
-
210.e-3
,
-
210
,
1
,
-
3
)
{
print
"-210.e-3 is "
,
-
210.e-3
,
"
\n
"
;
}
if
!
close
(
.0E1
,
.0E1
)
{
print
".0E1 is "
,
.0E1
,
" should be "
,
.0E1
,
"
\n
"
;
return
1
;
}
if
!
close
(
+
.01e2
,
+
.01e2
)
{
print
"+.01e2 is "
,
+
.01e2
,
" should be "
,
+
.01e2
,
"
\n
"
;
return
1
;
}
if
!
close
(
-
.012e3
,
-
.012e3
)
{
print
"-.012e3 is "
,
-
.012e3
,
" should be "
,
-
.012e3
,
"
\n
"
;
return
1
;
}
if
!
close
(
.0E1
,
0
,
1
,
1
)
{
print
".0E1 is "
,
.0E1
,
"
\n
"
;
}
if
!
close
(
+
.01e2
,
1
,
100
,
2
)
{
print
"+.01e2 is "
,
+
.01e2
,
"
\n
"
;
}
if
!
close
(
-
.012e3
,
-
12
,
1000
,
3
)
{
print
"-.012e3 is "
,
-
.012e3
,
"
\n
"
;
}
if
!
close
(
0.0E1
,
0
.0E1
)
{
print
"0.0E1 is "
,
0.0E1
,
" should be "
,
0.0E1
,
"
\n
"
;
return
1
;
}
if
!
close
(
+
10.01e2
,
+
10.01e2
)
{
print
"+10.01e2 is "
,
+
10.01e2
,
" should be "
,
+
10.01e2
,
"
\n
"
;
return
1
;
}
if
!
close
(
-
210.012e3
,
-
210
.012e3
)
{
print
"-210.012e3 is "
,
-
210.012e3
,
" should be "
,
-
210.012e3
,
"
\n
"
;
return
1
;
}
if
!
close
(
0.0E1
,
0
,
1
,
0
)
{
print
"0.0E1 is "
,
0.0E1
,
"
\n
"
;
}
if
!
close
(
+
10.01e2
,
1001
,
100
,
2
)
{
print
"+10.01e2 is "
,
+
10.01e2
,
"
\n
"
;
}
if
!
close
(
-
210.012e3
,
-
210
012
,
1000
,
3
)
{
print
"-210.012e3 is "
,
-
210.012e3
,
"
\n
"
;
}
if
!
close
(
0.E+12
,
0
.E+12
)
{
print
"0.E+12 is "
,
0.E+12
,
" should be "
,
0.E+12
,
"
\n
"
;
return
1
;
}
if
!
close
(
+
10.e23
,
+
10.e23
)
{
print
"+10.e23 is "
,
+
10.e23
,
" should be "
,
+
10.e23
,
"
\n
"
;
return
1
;
}
if
!
close
(
-
210.e3
4
,
-
210.e34
)
{
print
"-210.e34 is "
,
-
210.e34
,
" should be "
,
-
210.e34
,
"
\n
"
;
return
1
;
}
if
!
close
(
0.E+12
,
0
,
1
,
0
)
{
print
"0.E+12 is "
,
0.E+12
,
"
\n
"
;
}
if
!
close
(
+
10.e23
,
10
,
1
,
23
)
{
print
"+10.e23 is "
,
+
10.e23
,
"
\n
"
;
}
if
!
close
(
-
210.e3
3
,
-
210
,
1
,
33
)
{
print
"-210.e33 is "
,
-
210.e33
,
"
\n
"
;
}
if
!
close
(
.0E-12
,
.0E-12
)
{
print
".0E-12 is "
,
.0E-12
,
" should be "
,
.0E-12
,
"
\n
"
;
return
1
;
}
if
!
close
(
+
.01e23
,
+
.01e23
)
{
print
"+.01e23 is "
,
+
.01e23
,
" should be "
,
+
.01e23
,
"
\n
"
;
return
1
;
}
if
!
close
(
-
.012e34
,
-
.012e34
)
{
print
"-.012e34 is "
,
-
.012e34
,
" should be "
,
-
.012e34
,
"
\n
"
;
return
1
;
}
if
!
close
(
.0E-12
,
0
,
1
,
0
)
{
print
".0E-12 is "
,
.0E-12
,
"
\n
"
;
}
if
!
close
(
+
.01e23
,
1
,
100
,
23
)
{
print
"+.01e23 is "
,
+
.01e23
,
"
\n
"
;
}
if
!
close
(
-
.012e34
,
-
12
,
1000
,
34
)
{
print
"-.012e34 is "
,
-
.012e34
,
"
\n
"
;
}
if
!
close
(
0.0E12
,
0
.0E12
)
{
print
"0.0E12 is "
,
0.0E12
,
" should be "
,
0.0E12
,
"
\n
"
;
return
1
;
}
if
!
close
(
+
10.01e23
,
+
10.01e23
)
{
print
"+10.01e23 is "
,
+
10.01e23
,
" should be "
,
+
10.01e23
,
"
\n
"
;
return
1
;
}
if
!
close
(
-
210.012e3
4
,
-
210.012e34
)
{
print
"-210.012e34 is "
,
-
210.012e34
,
" should be "
,
-
210.012e34
,
"
\n
"
;
return
1
;
}
if
!
close
(
0.0E12
,
0
,
1
,
12
)
{
print
"0.0E12 is "
,
0.0E12
,
"
\n
"
;
}
if
!
close
(
+
10.01e23
,
1001
,
100
,
23
)
{
print
"+10.01e23 is "
,
+
10.01e23
,
"
\n
"
;
}
if
!
close
(
-
210.012e3
3
,
-
210012
,
1000
,
33
)
{
print
"-210.012e33 is "
,
-
210.012e33
,
"
\n
"
;
}
if
!
close
(
0.E123
,
0
.E123
)
{
print
"0.E123 is "
,
0.E123
,
" should be "
,
0.E123
,
"
\n
"
;
return
1
;
}
if
!
close
(
+
10.e+23
4
,
+
10.e+234
)
{
print
"+10.e+234 is "
,
+
10.e+234
,
" should be "
,
+
10.e+234
,
"
\n
"
;
return
1
;
}
// if !close(-210.e-345, -210.e-345) { print "-210.e-345 is ", -210.e-345, " should be ", -210.e-345, "\n"; return 1
; }
if
!
close
(
0.E123
,
0
,
1
,
123
)
{
print
"0.E123 is "
,
0.E123
,
"
\n
"
;
}
if
!
close
(
+
10.e+23
,
10
,
1
,
23
)
{
print
"+10.e+234 is "
,
+
10.e+234
,
"
\n
"
;
}
if
!
close
(
-
210.e-35
,
-
210
,
1
,
-
35
)
{
print
"-210.e-35 is "
,
-
210.e-35
,
"
\n
"
;
}
if
!
close
(
.0E123
,
.0E123
)
{
print
".0E123 is "
,
.0E123
,
" should be "
,
.0E123
,
"
\n
"
;
return
1
;
}
// if !close(+.01e234, +.01e234) { print "+.01e234 is ", +.01e234, " should be ", +.01e234, "\n"; return 1
; }
// if !close(-.012e345, -.012e345) { print "-.012e345 is ", -.012e345, " should be ", -.012e345, "\n"; return 1
; }
if
!
close
(
.0E123
,
0
,
1
,
123
)
{
print
".0E123 is "
,
.0E123
,
"
\n
"
;
}
if
!
close
(
+
.01e29
,
1
,
100
,
29
)
{
print
"+.01e29 is "
,
+
.01e29
,
"
\n
"
;
}
if
!
close
(
-
.012e29
,
-
12
,
1000
,
29
)
{
print
"-.012e29 is "
,
-
.012e29
,
"
\n
"
;
}
if
!
close
(
0.0E123
,
0
.0E123
)
{
print
"0.0E123 is "
,
0.0E123
,
" should be "
,
0.0E123
,
"
\n
"
;
return
1
;
}
// if !close(+10.01e234, +10.01e234) { print "+10.01e234 is ", +10.01e234, " should be ", +10.01e234, "\n"; return 1
; }
// if !close(-210.012e345, -210.012e345) { print "-210.012e345 is ", -210.012e345, " should be ", -210.012e345, "\n"; return 1
; }
if
!
close
(
0.0E123
,
0
,
1
,
123
)
{
print
"0.0E123 is "
,
0.0E123
,
"
\n
"
;
}
if
!
close
(
+
10.01e31
,
1001
,
100
,
31
)
{
print
"+10.01e31 is "
,
+
10.01e31
,
"
\n
"
;
}
if
!
close
(
-
210.012e19
,
-
210012
,
1000
,
19
)
{
print
"-210.012e19 is "
,
-
210.012e19
,
"
\n
"
;
}
}
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