Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2ec85135
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2ec85135
编写于
10月 11, 2011
作者:
D
David Rajchenbach-Teller
提交者:
Marijn Haverbeke
10月 11, 2011
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Move] Moved str_to_float, float_to_str from compiler to lib
上级
33167f7d
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
51 addition
and
40 deletion
+51
-40
src/comp/driver/rustc.rs
src/comp/driver/rustc.rs
+1
-1
src/comp/middle/typeck.rs
src/comp/middle/typeck.rs
+2
-2
src/comp/util/common.rs
src/comp/util/common.rs
+3
-37
src/lib/float.rs
src/lib/float.rs
+44
-0
src/lib/std.rc
src/lib/std.rc
+1
-0
未找到文件。
src/comp/driver/rustc.rs
浏览文件 @
2ec85135
...
@@ -94,7 +94,7 @@ fn time<@T>(do_it: bool, what: str, thunk: fn() -> T) -> T {
...
@@ -94,7 +94,7 @@ fn time<@T>(do_it: bool, what: str, thunk: fn() -> T) -> T {
let
rv
=
thunk
();
let
rv
=
thunk
();
let
end
=
std
::
time
::
precise_time_s
();
let
end
=
std
::
time
::
precise_time_s
();
log_err
#
fmt
[
"time: %s took %s s"
,
what
,
log_err
#
fmt
[
"time: %s took %s s"
,
what
,
common
::
float_to_str
(
end
-
start
,
3u
)];
std
::
float
::
float_to_str
(
end
-
start
,
3u
)];
ret
rv
;
ret
rv
;
}
}
...
...
src/comp/middle/typeck.rs
浏览文件 @
2ec85135
...
@@ -1303,8 +1303,8 @@ fn valid_range_bounds(l1: @ast::lit, l2: @ast::lit) -> bool {
...
@@ -1303,8 +1303,8 @@ fn valid_range_bounds(l1: @ast::lit, l2: @ast::lit) -> bool {
alt
l1
.node
{
alt
l1
.node
{
ast
::
lit_float
(
s1
)
|
ast
::
lit_mach_float
(
_
,
s1
)
{
ast
::
lit_float
(
s1
)
|
ast
::
lit_mach_float
(
_
,
s1
)
{
let
s2
=
lit_as_float
(
l2
);
let
s2
=
lit_as_float
(
l2
);
let
f1
=
util
::
common
::
str_to_float
(
s1
);
let
f1
=
std
::
float
::
str_to_float
(
s1
);
let
f2
=
util
::
common
::
str_to_float
(
s2
);
let
f2
=
std
::
float
::
str_to_float
(
s2
);
ret
*
util
::
common
::
min
(
f1
,
f2
)
==
f1
ret
*
util
::
common
::
min
(
f1
,
f2
)
==
f1
}
}
ast
::
lit_uint
(
_
)
|
ast
::
lit_char
(
_
)
{
ast
::
lit_uint
(
_
)
|
ast
::
lit_char
(
_
)
{
...
...
src/comp/util/common.rs
浏览文件 @
2ec85135
...
@@ -156,8 +156,8 @@ fn lit_in_range(l: @ast::lit, m1: @ast::lit, m2: @ast::lit) -> bool {
...
@@ -156,8 +156,8 @@ fn lit_in_range(l: @ast::lit, m1: @ast::lit, m2: @ast::lit) -> bool {
frange
(
f1
,
f2
)
{
frange
(
f1
,
f2
)
{
alt
l
.node
{
alt
l
.node
{
ast
::
lit_float
(
f3
)
|
ast
::
lit_mach_float
(
_
,
f3
)
{
ast
::
lit_float
(
f3
)
|
ast
::
lit_mach_float
(
_
,
f3
)
{
str_to_float
(
f3
)
>=
*
min
(
f1
,
f2
)
&&
st
d
::
float
::
st
r_to_float
(
f3
)
>=
*
min
(
f1
,
f2
)
&&
str_to_float
(
f3
)
<=
*
max
(
f1
,
f2
)
st
d
::
float
::
st
r_to_float
(
f3
)
<=
*
max
(
f1
,
f2
)
}
}
_
{
fail
}
_
{
fail
}
}
}
...
@@ -232,7 +232,7 @@ fn lits_to_range(l: @ast::lit, r: @ast::lit) -> range {
...
@@ -232,7 +232,7 @@ fn lits_to_range(l: @ast::lit, r: @ast::lit) -> range {
}
}
ast
::
lit_float
(
f1
)
|
ast
::
lit_mach_float
(
_
,
f1
)
{
ast
::
lit_float
(
f1
)
|
ast
::
lit_mach_float
(
_
,
f1
)
{
alt
r
.node
{
ast
::
lit_float
(
f2
)
|
ast
::
lit_mach_float
(
_
,
f2
)
{
alt
r
.node
{
ast
::
lit_float
(
f2
)
|
ast
::
lit_mach_float
(
_
,
f2
)
{
frange
(
st
r_to_float
(
f1
),
str_to_float
(
f2
))
frange
(
st
d
::
float
::
str_to_float
(
f1
),
std
::
float
::
str_to_float
(
f2
))
}
}
_
{
fail
}
}
_
{
fail
}
}
}
}
...
@@ -293,41 +293,7 @@ fn is_main_name(path: [ast::ident]) -> bool {
...
@@ -293,41 +293,7 @@ fn is_main_name(path: [ast::ident]) -> bool {
str
::
eq
(
option
::
get
(
std
::
vec
::
last
(
path
)),
"main"
)
str
::
eq
(
option
::
get
(
std
::
vec
::
last
(
path
)),
"main"
)
}
}
// FIXME mode this to std::float when editing the stdlib no longer
// requires a snapshot
fn
float_to_str
(
num
:
float
,
digits
:
uint
)
->
str
{
let
accum
=
if
num
<
0.0
{
num
=
-
num
;
"-"
}
else
{
""
};
let
trunc
=
num
as
uint
;
let
frac
=
num
-
(
trunc
as
float
);
accum
+=
uint
::
str
(
trunc
);
if
frac
==
0.0
||
digits
==
0u
{
ret
accum
;
}
accum
+=
"."
;
while
digits
>
0u
&&
frac
>
0.0
{
frac
*=
10.0
;
let
digit
=
frac
as
uint
;
accum
+=
uint
::
str
(
digit
);
frac
-=
digit
as
float
;
digits
-=
1u
;
}
ret
accum
;
}
fn
str_to_float
(
num
:
str
)
->
float
{
let
digits
=
str
::
split
(
num
,
'.'
as
u8
);
let
total
=
int
::
from_str
(
digits
[
0
])
as
float
;
fn
dec_val
(
c
:
char
)
->
int
{
ret
(
c
as
int
)
-
(
'0'
as
int
);
}
let
right
=
digits
[
1
];
let
len
=
str
::
char_len
(
digits
[
1
]);
let
i
=
1u
;
while
(
i
<
len
)
{
total
+=
dec_val
(
str
::
pop_char
(
right
))
as
float
/
(
int
::
pow
(
10
,
i
)
as
float
);
i
+=
1u
;
}
ret
total
;
}
//
//
// Local Variables:
// Local Variables:
...
...
src/lib/float.rs
0 → 100644
浏览文件 @
2ec85135
fn
float_to_str
(
num
:
float
,
digits
:
uint
)
->
str
{
let
accum
=
if
num
<
0.0
{
num
=
-
num
;
"-"
}
else
{
""
};
let
trunc
=
num
as
uint
;
let
frac
=
num
-
(
trunc
as
float
);
accum
+=
uint
::
str
(
trunc
);
if
frac
==
0.0
||
digits
==
0u
{
ret
accum
;
}
accum
+=
"."
;
while
digits
>
0u
&&
frac
>
0.0
{
frac
*=
10.0
;
let
digit
=
frac
as
uint
;
accum
+=
uint
::
str
(
digit
);
frac
-=
digit
as
float
;
digits
-=
1u
;
}
ret
accum
;
}
fn
str_to_float
(
num
:
str
)
->
float
{
let
digits
=
str
::
split
(
num
,
'.'
as
u8
);
let
total
=
int
::
from_str
(
digits
[
0
])
as
float
;
fn
dec_val
(
c
:
char
)
->
int
{
ret
(
c
as
int
)
-
(
'0'
as
int
);
}
let
right
=
digits
[
1
];
let
len
=
str
::
char_len
(
digits
[
1
]);
let
i
=
1u
;
while
(
i
<
len
)
{
total
+=
dec_val
(
str
::
pop_char
(
right
))
as
float
/
(
int
::
pow
(
10
,
i
)
as
float
);
i
+=
1u
;
}
ret
total
;
}
//
// Local Variables:
// mode: rust
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:
//
src/lib/std.rc
浏览文件 @
2ec85135
...
@@ -16,6 +16,7 @@ mod u8;
...
@@ -16,6 +16,7 @@ mod u8;
mod u64;
mod u64;
mod vec;
mod vec;
mod str;
mod str;
mod float;
// General io and system-services modules.
// General io and system-services modules.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录