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
41b9617b
Commit
41b9617b
authored
Jul 09, 2008
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix ldexp, frexp, and make math package compile and test correctly
SVN=126423
parent
45288543
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
17 additions
and
18 deletions
+17
-18
sys.go
src/cmd/gc/sys.go
+2
-2
sysimport.c
src/cmd/gc/sysimport.c
+0
-0
fmt.go
src/lib/fmt.go
+1
-1
exp.go
src/lib/math/exp.go
+1
-1
fmod.go
src/lib/math/fmod.go
+3
-3
log.go
src/lib/math/log.go
+1
-1
main.go
src/lib/math/main.go
+2
-3
sqrt.go
src/lib/math/sqrt.go
+1
-1
runtime.c
src/runtime/runtime.c
+6
-6
No files found.
src/cmd/gc/sys.go
View file @
41b9617b
...
...
@@ -28,8 +28,8 @@ func envc() int32;
func
argv
(
int32
)
string
;
func
envv
(
int32
)
string
;
func
frexp
(
float64
)
(
int32
,
float64
);
// break fp into exp,fract
func
ldexp
(
int32
,
float64
)
float64
;
// make fp from exp,fract
func
frexp
(
float64
)
(
float64
,
int32
);
// break fp into exp,fract
func
ldexp
(
float64
,
int32
)
float64
;
// make fp from exp,fract
func
modf
(
float64
)
(
float64
,
float64
);
// break fp into double.double
func
isInf
(
float64
,
int32
)
bool
;
// test for infinity
func
isNaN
(
float64
)
bool
;
// test for not-a-number
...
...
src/cmd/gc/sysimport.c
View file @
41b9617b
This diff is collapsed.
Click to expand it.
src/lib/fmt.go
View file @
41b9617b
...
...
@@ -358,7 +358,7 @@ func unpack(a double) (negative bool, exp int, num double) {
}
// find g,e such that a = g*10^e.
// guess 10-exponent using 2-exponent, then fine tune.
e2
,
g
:=
sys
.
frexp
(
a
);
g
,
e2
:=
sys
.
frexp
(
a
);
e
:=
int
(
e2
*
.301029995663981
);
g
=
a
*
pow10
(
-
e
);
for
g
<
1
{
...
...
src/lib/math/exp.go
View file @
41b9617b
...
...
@@ -49,5 +49,5 @@ exp(arg double) double
xsq
=
fract
*
fract
;
temp1
=
((
p2
*
xsq
+
p1
)
*
xsq
+
p0
)
*
fract
;
temp2
=
((
xsq
+
q2
)
*
xsq
+
q1
)
*
xsq
+
q0
;
return
sys
.
ldexp
(
ent
,
sqrt2
*
(
temp2
+
temp1
)
/
(
temp2
-
temp1
)
);
return
sys
.
ldexp
(
sqrt2
*
(
temp2
+
temp1
)
/
(
temp2
-
temp1
),
ent
);
}
src/lib/math/fmod.go
View file @
41b9617b
...
...
@@ -24,7 +24,7 @@ fmod(x, y double) double
y
=
-
y
;
}
y
exp
,
yfr
=
sys
.
frexp
(
y
);
y
fr
,
yexp
=
sys
.
frexp
(
y
);
sign
=
false
;
if
x
<
0
{
r
=
-
x
;
...
...
@@ -34,11 +34,11 @@ fmod(x, y double) double
}
for
r
>=
y
{
r
exp
,
rfr
=
sys
.
frexp
(
r
);
r
fr
,
rexp
=
sys
.
frexp
(
r
);
if
rfr
<
yfr
{
rexp
=
rexp
-
1
;
}
r
=
r
-
sys
.
ldexp
(
rexp
-
yexp
,
y
);
r
=
r
-
sys
.
ldexp
(
y
,
rexp
-
yexp
);
}
if
sign
{
r
=
-
r
;
...
...
src/lib/math/log.go
View file @
41b9617b
...
...
@@ -39,7 +39,7 @@ log(arg double) double
return
sys
.
NaN
();
}
exp
,
x
=
sys
.
frexp
(
arg
);
x
,
exp
=
sys
.
frexp
(
arg
);
for
x
<
0.5
{
x
=
x
*
2
;
exp
=
exp
-
1
;
...
...
src/lib/math/main.go
View file @
41b9617b
...
...
@@ -61,15 +61,14 @@ main()
ck
(
exp
[
i
],
math
.
exp
(
f
));
ck
(
floor
[
i
],
math
.
floor
(
f
));
ck
(
log
[
i
],
math
.
log
(
math
.
fabs
(
f
)));
math
.
pow
(
10
,
f
);
ck
(
pow
[
i
],
math
.
pow
(
10
,
f
));
ck
(
sin
[
i
],
math
.
sin
(
f
));
ck
(
sinh
[
i
],
math
.
sinh
(
f
));
ck
(
sqrt
[
i
],
math
.
sqrt
(
math
.
fabs
(
f
)));
ck
(
tan
[
i
],
math
.
tan
(
f
));
ck
(
tanh
[
i
],
math
.
tanh
(
f
));
//
ck(math.fabs(tanh[i]*math.sqrt(2)),
//
math.hypot(tanh[i], tanh[i]));
ck
(
math
.
fabs
(
tanh
[
i
]
*
math
.
sqrt
(
2
)),
math
.
hypot
(
tanh
[
i
],
tanh
[
i
]));
}
}
...
...
src/lib/math/sqrt.go
View file @
41b9617b
...
...
@@ -30,7 +30,7 @@ sqrt(arg double) double
return
0
;
}
exp
,
x
=
sys
.
frexp
(
arg
);
x
,
exp
=
sys
.
frexp
(
arg
);
for
x
<
0.5
{
x
=
x
*
2
;
exp
=
exp
-
1
;
...
...
src/runtime/runtime.c
View file @
41b9617b
...
...
@@ -402,15 +402,15 @@ modf(float64 d, float64 *ip)
* Keep the top 11+e bits; clear the rest.
*/
if
(
e
<=
64
-
11
)
x
&=
~
((
uint64
)
1
<<
(
64
-
11
-
e
))
-
1
;
x
&=
~
((
(
uint64
)
1
<<
(
64LL
-
11LL
-
e
))
-
1
)
;
dd
=
*
(
float64
*
)
&
x
;
*
ip
=
dd
;
return
d
-
dd
;
}
// func frexp(float64) (
int32, float64
); // break fp into exp,fract
// func frexp(float64) (
float64, int32
); // break fp into exp,fract
void
sys
·
frexp
(
float64
din
,
int32
iou
,
float64
d
ou
)
sys
·
frexp
(
float64
din
,
float64
dou
,
int32
i
ou
)
{
dou
=
frexp
(
din
,
&
iou
);
FLUSH
(
&
dou
);
...
...
@@ -426,10 +426,10 @@ sys·ldexp(float64 din, int32 ein, float64 dou)
//func modf(float64) (float64, float64); // break fp into double+double
float64
sys
·
modf
(
float64
din
,
float64
dou1
,
float64
dou2
)
sys
·
modf
(
float64
din
,
float64
integer
,
float64
fraction
)
{
dou1
=
modf
(
din
,
&
dou2
);
FLUSH
(
&
dou2
);
fraction
=
modf
(
din
,
&
integer
);
FLUSH
(
&
fraction
);
}
//func isinf(float64, int32 sign) bool; // test for infinity
...
...
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