Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2e4790ca
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,发现更多精彩内容 >>
提交
2e4790ca
编写于
5月 06, 2013
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'mozilla/incoming' into issue-5910-dyna-freeze
上级
0ef4e860
a5891beb
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
403 addition
and
363 deletion
+403
-363
src/libcore/cmp.rs
src/libcore/cmp.rs
+7
-0
src/libcore/num/f32.rs
src/libcore/num/f32.rs
+90
-74
src/libcore/num/f64.rs
src/libcore/num/f64.rs
+90
-75
src/libcore/num/float.rs
src/libcore/num/float.rs
+90
-74
src/libcore/num/num.rs
src/libcore/num/num.rs
+3
-2
src/libcore/prelude.rs
src/libcore/prelude.rs
+1
-1
src/librustc/metadata/encoder.rs
src/librustc/metadata/encoder.rs
+1
-0
src/libstd/cmp.rs
src/libstd/cmp.rs
+0
-102
src/libstd/std.rc
src/libstd/std.rc
+0
-1
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+36
-0
src/test/auxiliary/packed.rs
src/test/auxiliary/packed.rs
+5
-0
src/test/run-fail/assert-approx-eq-eps-macro-fail.rs
src/test/run-fail/assert-approx-eq-eps-macro-fail.rs
+14
-0
src/test/run-fail/assert-approx-eq-macro-fail.rs
src/test/run-fail/assert-approx-eq-macro-fail.rs
+14
-0
src/test/run-pass/assert-approx-eq-macro-success.rs
src/test/run-pass/assert-approx-eq-macro-success.rs
+16
-0
src/test/run-pass/intrinsics-math.rs
src/test/run-pass/intrinsics-math.rs
+26
-30
src/test/run-pass/packed-struct-size-xc.rs
src/test/run-pass/packed-struct-size-xc.rs
+8
-0
src/test/run-pass/trait-inheritance-num.rs
src/test/run-pass/trait-inheritance-num.rs
+1
-2
src/test/run-pass/trait-inheritance-num2.rs
src/test/run-pass/trait-inheritance-num2.rs
+1
-2
未找到文件。
src/libcore/cmp.rs
浏览文件 @
2e4790ca
...
...
@@ -66,6 +66,13 @@ fn equals(&self, other: &$t) -> bool { *self == *other }
totaleq_impl!
(
char
)
/// Trait for testing approximate equality
pub
trait
ApproxEq
<
Eps
>
{
fn
approx_epsilon
()
->
Eps
;
fn
approx_eq
(
&
self
,
other
:
&
Self
)
->
bool
;
fn
approx_eq_eps
(
&
self
,
other
:
&
Self
,
approx_epsilon
:
&
Eps
)
->
bool
;
}
#[deriving(Clone,
Eq)]
pub
enum
Ordering
{
Less
=
-
1
,
Equal
=
0
,
Greater
=
1
}
...
...
src/libcore/num/f32.rs
浏览文件 @
2e4790ca
...
...
@@ -210,6 +210,22 @@ fn eq(&self, other: &f32) -> bool { (*self) == (*other) }
fn
ne
(
&
self
,
other
:
&
f32
)
->
bool
{
(
*
self
)
!=
(
*
other
)
}
}
#[cfg(notest)]
impl
ApproxEq
<
f32
>
for
f32
{
#[inline(always)]
fn
approx_epsilon
()
->
f32
{
1.0e-6
}
#[inline(always)]
fn
approx_eq
(
&
self
,
other
:
&
f32
)
->
bool
{
self
.approx_eq_eps
(
other
,
&
ApproxEq
::
approx_epsilon
::
<
f32
,
f32
>
())
}
#[inline(always)]
fn
approx_eq_eps
(
&
self
,
other
:
&
f32
,
approx_epsilon
:
&
f32
)
->
bool
{
(
*
self
-
*
other
)
.abs
()
<
*
approx_epsilon
}
}
#[cfg(notest)]
impl
Ord
for
f32
{
#[inline(always)]
...
...
@@ -810,15 +826,6 @@ mod tests {
use
super
::
*
;
use
prelude
::
*
;
macro_rules!
assert_fuzzy_eq
(
(
$a:expr
,
$b:expr
)
=>
({
let
a
=
$a
,
b
=
$b
;
if
!
((
a
-
b
)
.abs
()
<
1.0e-6
)
{
fail!
(
fmt!
(
"The values were not approximately equal. Found: %? and %?"
,
a
,
b
));
}
})
)
#[test]
fn
test_num
()
{
num
::
test_num
(
10f32
,
2f32
);
...
...
@@ -848,91 +855,91 @@ fn test_clamp() {
#[test]
fn
test_floor
()
{
assert_
fuzzy
_eq!
(
1.0f32
.floor
(),
1.0f32
);
assert_
fuzzy
_eq!
(
1.3f32
.floor
(),
1.0f32
);
assert_
fuzzy
_eq!
(
1.5f32
.floor
(),
1.0f32
);
assert_
fuzzy
_eq!
(
1.7f32
.floor
(),
1.0f32
);
assert_
fuzzy
_eq!
(
0.0f32
.floor
(),
0.0f32
);
assert_
fuzzy
_eq!
((
-
0.0f32
)
.floor
(),
-
0.0f32
);
assert_
fuzzy
_eq!
((
-
1.0f32
)
.floor
(),
-
1.0f32
);
assert_
fuzzy
_eq!
((
-
1.3f32
)
.floor
(),
-
2.0f32
);
assert_
fuzzy
_eq!
((
-
1.5f32
)
.floor
(),
-
2.0f32
);
assert_
fuzzy
_eq!
((
-
1.7f32
)
.floor
(),
-
2.0f32
);
assert_
approx
_eq!
(
1.0f32
.floor
(),
1.0f32
);
assert_
approx
_eq!
(
1.3f32
.floor
(),
1.0f32
);
assert_
approx
_eq!
(
1.5f32
.floor
(),
1.0f32
);
assert_
approx
_eq!
(
1.7f32
.floor
(),
1.0f32
);
assert_
approx
_eq!
(
0.0f32
.floor
(),
0.0f32
);
assert_
approx
_eq!
((
-
0.0f32
)
.floor
(),
-
0.0f32
);
assert_
approx
_eq!
((
-
1.0f32
)
.floor
(),
-
1.0f32
);
assert_
approx
_eq!
((
-
1.3f32
)
.floor
(),
-
2.0f32
);
assert_
approx
_eq!
((
-
1.5f32
)
.floor
(),
-
2.0f32
);
assert_
approx
_eq!
((
-
1.7f32
)
.floor
(),
-
2.0f32
);
}
#[test]
fn
test_ceil
()
{
assert_
fuzzy
_eq!
(
1.0f32
.ceil
(),
1.0f32
);
assert_
fuzzy
_eq!
(
1.3f32
.ceil
(),
2.0f32
);
assert_
fuzzy
_eq!
(
1.5f32
.ceil
(),
2.0f32
);
assert_
fuzzy
_eq!
(
1.7f32
.ceil
(),
2.0f32
);
assert_
fuzzy
_eq!
(
0.0f32
.ceil
(),
0.0f32
);
assert_
fuzzy
_eq!
((
-
0.0f32
)
.ceil
(),
-
0.0f32
);
assert_
fuzzy
_eq!
((
-
1.0f32
)
.ceil
(),
-
1.0f32
);
assert_
fuzzy
_eq!
((
-
1.3f32
)
.ceil
(),
-
1.0f32
);
assert_
fuzzy
_eq!
((
-
1.5f32
)
.ceil
(),
-
1.0f32
);
assert_
fuzzy
_eq!
((
-
1.7f32
)
.ceil
(),
-
1.0f32
);
assert_
approx
_eq!
(
1.0f32
.ceil
(),
1.0f32
);
assert_
approx
_eq!
(
1.3f32
.ceil
(),
2.0f32
);
assert_
approx
_eq!
(
1.5f32
.ceil
(),
2.0f32
);
assert_
approx
_eq!
(
1.7f32
.ceil
(),
2.0f32
);
assert_
approx
_eq!
(
0.0f32
.ceil
(),
0.0f32
);
assert_
approx
_eq!
((
-
0.0f32
)
.ceil
(),
-
0.0f32
);
assert_
approx
_eq!
((
-
1.0f32
)
.ceil
(),
-
1.0f32
);
assert_
approx
_eq!
((
-
1.3f32
)
.ceil
(),
-
1.0f32
);
assert_
approx
_eq!
((
-
1.5f32
)
.ceil
(),
-
1.0f32
);
assert_
approx
_eq!
((
-
1.7f32
)
.ceil
(),
-
1.0f32
);
}
#[test]
fn
test_round
()
{
assert_
fuzzy
_eq!
(
1.0f32
.round
(),
1.0f32
);
assert_
fuzzy
_eq!
(
1.3f32
.round
(),
1.0f32
);
assert_
fuzzy
_eq!
(
1.5f32
.round
(),
2.0f32
);
assert_
fuzzy
_eq!
(
1.7f32
.round
(),
2.0f32
);
assert_
fuzzy
_eq!
(
0.0f32
.round
(),
0.0f32
);
assert_
fuzzy
_eq!
((
-
0.0f32
)
.round
(),
-
0.0f32
);
assert_
fuzzy
_eq!
((
-
1.0f32
)
.round
(),
-
1.0f32
);
assert_
fuzzy
_eq!
((
-
1.3f32
)
.round
(),
-
1.0f32
);
assert_
fuzzy
_eq!
((
-
1.5f32
)
.round
(),
-
2.0f32
);
assert_
fuzzy
_eq!
((
-
1.7f32
)
.round
(),
-
2.0f32
);
assert_
approx
_eq!
(
1.0f32
.round
(),
1.0f32
);
assert_
approx
_eq!
(
1.3f32
.round
(),
1.0f32
);
assert_
approx
_eq!
(
1.5f32
.round
(),
2.0f32
);
assert_
approx
_eq!
(
1.7f32
.round
(),
2.0f32
);
assert_
approx
_eq!
(
0.0f32
.round
(),
0.0f32
);
assert_
approx
_eq!
((
-
0.0f32
)
.round
(),
-
0.0f32
);
assert_
approx
_eq!
((
-
1.0f32
)
.round
(),
-
1.0f32
);
assert_
approx
_eq!
((
-
1.3f32
)
.round
(),
-
1.0f32
);
assert_
approx
_eq!
((
-
1.5f32
)
.round
(),
-
2.0f32
);
assert_
approx
_eq!
((
-
1.7f32
)
.round
(),
-
2.0f32
);
}
#[test]
fn
test_trunc
()
{
assert_
fuzzy
_eq!
(
1.0f32
.trunc
(),
1.0f32
);
assert_
fuzzy
_eq!
(
1.3f32
.trunc
(),
1.0f32
);
assert_
fuzzy
_eq!
(
1.5f32
.trunc
(),
1.0f32
);
assert_
fuzzy
_eq!
(
1.7f32
.trunc
(),
1.0f32
);
assert_
fuzzy
_eq!
(
0.0f32
.trunc
(),
0.0f32
);
assert_
fuzzy
_eq!
((
-
0.0f32
)
.trunc
(),
-
0.0f32
);
assert_
fuzzy
_eq!
((
-
1.0f32
)
.trunc
(),
-
1.0f32
);
assert_
fuzzy
_eq!
((
-
1.3f32
)
.trunc
(),
-
1.0f32
);
assert_
fuzzy
_eq!
((
-
1.5f32
)
.trunc
(),
-
1.0f32
);
assert_
fuzzy
_eq!
((
-
1.7f32
)
.trunc
(),
-
1.0f32
);
assert_
approx
_eq!
(
1.0f32
.trunc
(),
1.0f32
);
assert_
approx
_eq!
(
1.3f32
.trunc
(),
1.0f32
);
assert_
approx
_eq!
(
1.5f32
.trunc
(),
1.0f32
);
assert_
approx
_eq!
(
1.7f32
.trunc
(),
1.0f32
);
assert_
approx
_eq!
(
0.0f32
.trunc
(),
0.0f32
);
assert_
approx
_eq!
((
-
0.0f32
)
.trunc
(),
-
0.0f32
);
assert_
approx
_eq!
((
-
1.0f32
)
.trunc
(),
-
1.0f32
);
assert_
approx
_eq!
((
-
1.3f32
)
.trunc
(),
-
1.0f32
);
assert_
approx
_eq!
((
-
1.5f32
)
.trunc
(),
-
1.0f32
);
assert_
approx
_eq!
((
-
1.7f32
)
.trunc
(),
-
1.0f32
);
}
#[test]
fn
test_fract
()
{
assert_
fuzzy
_eq!
(
1.0f32
.fract
(),
0.0f32
);
assert_
fuzzy
_eq!
(
1.3f32
.fract
(),
0.3f32
);
assert_
fuzzy
_eq!
(
1.5f32
.fract
(),
0.5f32
);
assert_
fuzzy
_eq!
(
1.7f32
.fract
(),
0.7f32
);
assert_
fuzzy
_eq!
(
0.0f32
.fract
(),
0.0f32
);
assert_
fuzzy
_eq!
((
-
0.0f32
)
.fract
(),
-
0.0f32
);
assert_
fuzzy
_eq!
((
-
1.0f32
)
.fract
(),
-
0.0f32
);
assert_
fuzzy
_eq!
((
-
1.3f32
)
.fract
(),
-
0.3f32
);
assert_
fuzzy
_eq!
((
-
1.5f32
)
.fract
(),
-
0.5f32
);
assert_
fuzzy
_eq!
((
-
1.7f32
)
.fract
(),
-
0.7f32
);
assert_
approx
_eq!
(
1.0f32
.fract
(),
0.0f32
);
assert_
approx
_eq!
(
1.3f32
.fract
(),
0.3f32
);
assert_
approx
_eq!
(
1.5f32
.fract
(),
0.5f32
);
assert_
approx
_eq!
(
1.7f32
.fract
(),
0.7f32
);
assert_
approx
_eq!
(
0.0f32
.fract
(),
0.0f32
);
assert_
approx
_eq!
((
-
0.0f32
)
.fract
(),
-
0.0f32
);
assert_
approx
_eq!
((
-
1.0f32
)
.fract
(),
-
0.0f32
);
assert_
approx
_eq!
((
-
1.3f32
)
.fract
(),
-
0.3f32
);
assert_
approx
_eq!
((
-
1.5f32
)
.fract
(),
-
0.5f32
);
assert_
approx
_eq!
((
-
1.7f32
)
.fract
(),
-
0.7f32
);
}
#[test]
fn
test_real_consts
()
{
assert_
fuzzy
_eq!
(
Real
::
two_pi
::
<
f32
>
(),
2f32
*
Real
::
pi
::
<
f32
>
());
assert_
fuzzy
_eq!
(
Real
::
frac_pi_2
::
<
f32
>
(),
Real
::
pi
::
<
f32
>
()
/
2f32
);
assert_
fuzzy
_eq!
(
Real
::
frac_pi_3
::
<
f32
>
(),
Real
::
pi
::
<
f32
>
()
/
3f32
);
assert_
fuzzy
_eq!
(
Real
::
frac_pi_4
::
<
f32
>
(),
Real
::
pi
::
<
f32
>
()
/
4f32
);
assert_
fuzzy
_eq!
(
Real
::
frac_pi_6
::
<
f32
>
(),
Real
::
pi
::
<
f32
>
()
/
6f32
);
assert_
fuzzy
_eq!
(
Real
::
frac_pi_8
::
<
f32
>
(),
Real
::
pi
::
<
f32
>
()
/
8f32
);
assert_
fuzzy
_eq!
(
Real
::
frac_1_pi
::
<
f32
>
(),
1f32
/
Real
::
pi
::
<
f32
>
());
assert_
fuzzy
_eq!
(
Real
::
frac_2_pi
::
<
f32
>
(),
2f32
/
Real
::
pi
::
<
f32
>
());
assert_
fuzzy
_eq!
(
Real
::
frac_2_sqrtpi
::
<
f32
>
(),
2f32
/
Real
::
pi
::
<
f32
>
()
.sqrt
());
assert_
fuzzy
_eq!
(
Real
::
sqrt2
::
<
f32
>
(),
2f32
.sqrt
());
assert_
fuzzy
_eq!
(
Real
::
frac_1_sqrt2
::
<
f32
>
(),
1f32
/
2f32
.sqrt
());
assert_
fuzzy
_eq!
(
Real
::
log2_e
::
<
f32
>
(),
Real
::
e
::
<
f32
>
()
.log2
());
assert_
fuzzy
_eq!
(
Real
::
log10_e
::
<
f32
>
(),
Real
::
e
::
<
f32
>
()
.log10
());
assert_
fuzzy
_eq!
(
Real
::
log_2
::
<
f32
>
(),
2f32
.log
());
assert_
fuzzy
_eq!
(
Real
::
log_10
::
<
f32
>
(),
10f32
.log
());
assert_
approx
_eq!
(
Real
::
two_pi
::
<
f32
>
(),
2f32
*
Real
::
pi
::
<
f32
>
());
assert_
approx
_eq!
(
Real
::
frac_pi_2
::
<
f32
>
(),
Real
::
pi
::
<
f32
>
()
/
2f32
);
assert_
approx
_eq!
(
Real
::
frac_pi_3
::
<
f32
>
(),
Real
::
pi
::
<
f32
>
()
/
3f32
);
assert_
approx
_eq!
(
Real
::
frac_pi_4
::
<
f32
>
(),
Real
::
pi
::
<
f32
>
()
/
4f32
);
assert_
approx
_eq!
(
Real
::
frac_pi_6
::
<
f32
>
(),
Real
::
pi
::
<
f32
>
()
/
6f32
);
assert_
approx
_eq!
(
Real
::
frac_pi_8
::
<
f32
>
(),
Real
::
pi
::
<
f32
>
()
/
8f32
);
assert_
approx
_eq!
(
Real
::
frac_1_pi
::
<
f32
>
(),
1f32
/
Real
::
pi
::
<
f32
>
());
assert_
approx
_eq!
(
Real
::
frac_2_pi
::
<
f32
>
(),
2f32
/
Real
::
pi
::
<
f32
>
());
assert_
approx
_eq!
(
Real
::
frac_2_sqrtpi
::
<
f32
>
(),
2f32
/
Real
::
pi
::
<
f32
>
()
.sqrt
());
assert_
approx
_eq!
(
Real
::
sqrt2
::
<
f32
>
(),
2f32
.sqrt
());
assert_
approx
_eq!
(
Real
::
frac_1_sqrt2
::
<
f32
>
(),
1f32
/
2f32
.sqrt
());
assert_
approx
_eq!
(
Real
::
log2_e
::
<
f32
>
(),
Real
::
e
::
<
f32
>
()
.log2
());
assert_
approx
_eq!
(
Real
::
log10_e
::
<
f32
>
(),
Real
::
e
::
<
f32
>
()
.log10
());
assert_
approx
_eq!
(
Real
::
log_2
::
<
f32
>
(),
2f32
.log
());
assert_
approx
_eq!
(
Real
::
log_10
::
<
f32
>
(),
10f32
.log
());
}
#[test]
...
...
@@ -974,6 +981,15 @@ pub fn test_signed() {
assert
!
(
!
NaN
.is_negative
());
}
#[test]
fn
test_approx_eq
()
{
assert
!
(
1.0f32
.approx_eq
(
&
1f32
));
assert
!
(
0.9999999f32
.approx_eq
(
&
1f32
));
assert
!
(
1.000001f32
.approx_eq_eps
(
&
1f32
,
&
1.0e-5
));
assert
!
(
1.0000001f32
.approx_eq_eps
(
&
1f32
,
&
1.0e-6
));
assert
!
(
!
1.0000001f32
.approx_eq_eps
(
&
1f32
,
&
1.0e-7
));
}
#[test]
fn
test_primitive
()
{
assert_eq!
(
Primitive
::
bits
::
<
f32
>
(),
sys
::
size_of
::
<
f32
>
()
*
8
);
...
...
src/libcore/num/f64.rs
浏览文件 @
2e4790ca
...
...
@@ -233,6 +233,22 @@ fn eq(&self, other: &f64) -> bool { (*self) == (*other) }
fn
ne
(
&
self
,
other
:
&
f64
)
->
bool
{
(
*
self
)
!=
(
*
other
)
}
}
#[cfg(notest)]
impl
ApproxEq
<
f64
>
for
f64
{
#[inline(always)]
fn
approx_epsilon
()
->
f64
{
1.0e-6
}
#[inline(always)]
fn
approx_eq
(
&
self
,
other
:
&
f64
)
->
bool
{
self
.approx_eq_eps
(
other
,
&
ApproxEq
::
approx_epsilon
::
<
f64
,
f64
>
())
}
#[inline(always)]
fn
approx_eq_eps
(
&
self
,
other
:
&
f64
,
approx_epsilon
:
&
f64
)
->
bool
{
(
*
self
-
*
other
)
.abs
()
<
*
approx_epsilon
}
}
#[cfg(notest)]
impl
Ord
for
f64
{
#[inline(always)]
...
...
@@ -853,16 +869,6 @@ mod tests {
use
super
::
*
;
use
prelude
::
*
;
macro_rules!
assert_fuzzy_eq
(
(
$a:expr
,
$b:expr
)
=>
({
let
a
=
$a
,
b
=
$b
;
if
!
((
a
-
b
)
.abs
()
<
1.0e-6
)
{
fail!
(
fmt!
(
"The values were not approximately equal.
\
Found: %? and expected %?"
,
a
,
b
));
}
})
)
#[test]
fn
test_num
()
{
num
::
test_num
(
10f64
,
2f64
);
...
...
@@ -896,91 +902,91 @@ fn test_clamp() {
#[test]
fn
test_floor
()
{
assert_
fuzzy
_eq!
(
1.0f64
.floor
(),
1.0f64
);
assert_
fuzzy
_eq!
(
1.3f64
.floor
(),
1.0f64
);
assert_
fuzzy
_eq!
(
1.5f64
.floor
(),
1.0f64
);
assert_
fuzzy
_eq!
(
1.7f64
.floor
(),
1.0f64
);
assert_
fuzzy
_eq!
(
0.0f64
.floor
(),
0.0f64
);
assert_
fuzzy
_eq!
((
-
0.0f64
)
.floor
(),
-
0.0f64
);
assert_
fuzzy
_eq!
((
-
1.0f64
)
.floor
(),
-
1.0f64
);
assert_
fuzzy
_eq!
((
-
1.3f64
)
.floor
(),
-
2.0f64
);
assert_
fuzzy
_eq!
((
-
1.5f64
)
.floor
(),
-
2.0f64
);
assert_
fuzzy
_eq!
((
-
1.7f64
)
.floor
(),
-
2.0f64
);
assert_
approx
_eq!
(
1.0f64
.floor
(),
1.0f64
);
assert_
approx
_eq!
(
1.3f64
.floor
(),
1.0f64
);
assert_
approx
_eq!
(
1.5f64
.floor
(),
1.0f64
);
assert_
approx
_eq!
(
1.7f64
.floor
(),
1.0f64
);
assert_
approx
_eq!
(
0.0f64
.floor
(),
0.0f64
);
assert_
approx
_eq!
((
-
0.0f64
)
.floor
(),
-
0.0f64
);
assert_
approx
_eq!
((
-
1.0f64
)
.floor
(),
-
1.0f64
);
assert_
approx
_eq!
((
-
1.3f64
)
.floor
(),
-
2.0f64
);
assert_
approx
_eq!
((
-
1.5f64
)
.floor
(),
-
2.0f64
);
assert_
approx
_eq!
((
-
1.7f64
)
.floor
(),
-
2.0f64
);
}
#[test]
fn
test_ceil
()
{
assert_
fuzzy
_eq!
(
1.0f64
.ceil
(),
1.0f64
);
assert_
fuzzy
_eq!
(
1.3f64
.ceil
(),
2.0f64
);
assert_
fuzzy
_eq!
(
1.5f64
.ceil
(),
2.0f64
);
assert_
fuzzy
_eq!
(
1.7f64
.ceil
(),
2.0f64
);
assert_
fuzzy
_eq!
(
0.0f64
.ceil
(),
0.0f64
);
assert_
fuzzy
_eq!
((
-
0.0f64
)
.ceil
(),
-
0.0f64
);
assert_
fuzzy
_eq!
((
-
1.0f64
)
.ceil
(),
-
1.0f64
);
assert_
fuzzy
_eq!
((
-
1.3f64
)
.ceil
(),
-
1.0f64
);
assert_
fuzzy
_eq!
((
-
1.5f64
)
.ceil
(),
-
1.0f64
);
assert_
fuzzy
_eq!
((
-
1.7f64
)
.ceil
(),
-
1.0f64
);
assert_
approx
_eq!
(
1.0f64
.ceil
(),
1.0f64
);
assert_
approx
_eq!
(
1.3f64
.ceil
(),
2.0f64
);
assert_
approx
_eq!
(
1.5f64
.ceil
(),
2.0f64
);
assert_
approx
_eq!
(
1.7f64
.ceil
(),
2.0f64
);
assert_
approx
_eq!
(
0.0f64
.ceil
(),
0.0f64
);
assert_
approx
_eq!
((
-
0.0f64
)
.ceil
(),
-
0.0f64
);
assert_
approx
_eq!
((
-
1.0f64
)
.ceil
(),
-
1.0f64
);
assert_
approx
_eq!
((
-
1.3f64
)
.ceil
(),
-
1.0f64
);
assert_
approx
_eq!
((
-
1.5f64
)
.ceil
(),
-
1.0f64
);
assert_
approx
_eq!
((
-
1.7f64
)
.ceil
(),
-
1.0f64
);
}
#[test]
fn
test_round
()
{
assert_
fuzzy
_eq!
(
1.0f64
.round
(),
1.0f64
);
assert_
fuzzy
_eq!
(
1.3f64
.round
(),
1.0f64
);
assert_
fuzzy
_eq!
(
1.5f64
.round
(),
2.0f64
);
assert_
fuzzy
_eq!
(
1.7f64
.round
(),
2.0f64
);
assert_
fuzzy
_eq!
(
0.0f64
.round
(),
0.0f64
);
assert_
fuzzy
_eq!
((
-
0.0f64
)
.round
(),
-
0.0f64
);
assert_
fuzzy
_eq!
((
-
1.0f64
)
.round
(),
-
1.0f64
);
assert_
fuzzy
_eq!
((
-
1.3f64
)
.round
(),
-
1.0f64
);
assert_
fuzzy
_eq!
((
-
1.5f64
)
.round
(),
-
2.0f64
);
assert_
fuzzy
_eq!
((
-
1.7f64
)
.round
(),
-
2.0f64
);
assert_
approx
_eq!
(
1.0f64
.round
(),
1.0f64
);
assert_
approx
_eq!
(
1.3f64
.round
(),
1.0f64
);
assert_
approx
_eq!
(
1.5f64
.round
(),
2.0f64
);
assert_
approx
_eq!
(
1.7f64
.round
(),
2.0f64
);
assert_
approx
_eq!
(
0.0f64
.round
(),
0.0f64
);
assert_
approx
_eq!
((
-
0.0f64
)
.round
(),
-
0.0f64
);
assert_
approx
_eq!
((
-
1.0f64
)
.round
(),
-
1.0f64
);
assert_
approx
_eq!
((
-
1.3f64
)
.round
(),
-
1.0f64
);
assert_
approx
_eq!
((
-
1.5f64
)
.round
(),
-
2.0f64
);
assert_
approx
_eq!
((
-
1.7f64
)
.round
(),
-
2.0f64
);
}
#[test]
fn
test_trunc
()
{
assert_
fuzzy
_eq!
(
1.0f64
.trunc
(),
1.0f64
);
assert_
fuzzy
_eq!
(
1.3f64
.trunc
(),
1.0f64
);
assert_
fuzzy
_eq!
(
1.5f64
.trunc
(),
1.0f64
);
assert_
fuzzy
_eq!
(
1.7f64
.trunc
(),
1.0f64
);
assert_
fuzzy
_eq!
(
0.0f64
.trunc
(),
0.0f64
);
assert_
fuzzy
_eq!
((
-
0.0f64
)
.trunc
(),
-
0.0f64
);
assert_
fuzzy
_eq!
((
-
1.0f64
)
.trunc
(),
-
1.0f64
);
assert_
fuzzy
_eq!
((
-
1.3f64
)
.trunc
(),
-
1.0f64
);
assert_
fuzzy
_eq!
((
-
1.5f64
)
.trunc
(),
-
1.0f64
);
assert_
fuzzy
_eq!
((
-
1.7f64
)
.trunc
(),
-
1.0f64
);
assert_
approx
_eq!
(
1.0f64
.trunc
(),
1.0f64
);
assert_
approx
_eq!
(
1.3f64
.trunc
(),
1.0f64
);
assert_
approx
_eq!
(
1.5f64
.trunc
(),
1.0f64
);
assert_
approx
_eq!
(
1.7f64
.trunc
(),
1.0f64
);
assert_
approx
_eq!
(
0.0f64
.trunc
(),
0.0f64
);
assert_
approx
_eq!
((
-
0.0f64
)
.trunc
(),
-
0.0f64
);
assert_
approx
_eq!
((
-
1.0f64
)
.trunc
(),
-
1.0f64
);
assert_
approx
_eq!
((
-
1.3f64
)
.trunc
(),
-
1.0f64
);
assert_
approx
_eq!
((
-
1.5f64
)
.trunc
(),
-
1.0f64
);
assert_
approx
_eq!
((
-
1.7f64
)
.trunc
(),
-
1.0f64
);
}
#[test]
fn
test_fract
()
{
assert_
fuzzy
_eq!
(
1.0f64
.fract
(),
0.0f64
);
assert_
fuzzy
_eq!
(
1.3f64
.fract
(),
0.3f64
);
assert_
fuzzy
_eq!
(
1.5f64
.fract
(),
0.5f64
);
assert_
fuzzy
_eq!
(
1.7f64
.fract
(),
0.7f64
);
assert_
fuzzy
_eq!
(
0.0f64
.fract
(),
0.0f64
);
assert_
fuzzy
_eq!
((
-
0.0f64
)
.fract
(),
-
0.0f64
);
assert_
fuzzy
_eq!
((
-
1.0f64
)
.fract
(),
-
0.0f64
);
assert_
fuzzy
_eq!
((
-
1.3f64
)
.fract
(),
-
0.3f64
);
assert_
fuzzy
_eq!
((
-
1.5f64
)
.fract
(),
-
0.5f64
);
assert_
fuzzy
_eq!
((
-
1.7f64
)
.fract
(),
-
0.7f64
);
assert_
approx
_eq!
(
1.0f64
.fract
(),
0.0f64
);
assert_
approx
_eq!
(
1.3f64
.fract
(),
0.3f64
);
assert_
approx
_eq!
(
1.5f64
.fract
(),
0.5f64
);
assert_
approx
_eq!
(
1.7f64
.fract
(),
0.7f64
);
assert_
approx
_eq!
(
0.0f64
.fract
(),
0.0f64
);
assert_
approx
_eq!
((
-
0.0f64
)
.fract
(),
-
0.0f64
);
assert_
approx
_eq!
((
-
1.0f64
)
.fract
(),
-
0.0f64
);
assert_
approx
_eq!
((
-
1.3f64
)
.fract
(),
-
0.3f64
);
assert_
approx
_eq!
((
-
1.5f64
)
.fract
(),
-
0.5f64
);
assert_
approx
_eq!
((
-
1.7f64
)
.fract
(),
-
0.7f64
);
}
#[test]
fn
test_real_consts
()
{
assert_
fuzzy
_eq!
(
Real
::
two_pi
::
<
f64
>
(),
2.0
*
Real
::
pi
::
<
f64
>
());
assert_
fuzzy
_eq!
(
Real
::
frac_pi_2
::
<
f64
>
(),
Real
::
pi
::
<
f64
>
()
/
2f64
);
assert_
fuzzy
_eq!
(
Real
::
frac_pi_3
::
<
f64
>
(),
Real
::
pi
::
<
f64
>
()
/
3f64
);
assert_
fuzzy
_eq!
(
Real
::
frac_pi_4
::
<
f64
>
(),
Real
::
pi
::
<
f64
>
()
/
4f64
);
assert_
fuzzy
_eq!
(
Real
::
frac_pi_6
::
<
f64
>
(),
Real
::
pi
::
<
f64
>
()
/
6f64
);
assert_
fuzzy
_eq!
(
Real
::
frac_pi_8
::
<
f64
>
(),
Real
::
pi
::
<
f64
>
()
/
8f64
);
assert_
fuzzy
_eq!
(
Real
::
frac_1_pi
::
<
f64
>
(),
1f64
/
Real
::
pi
::
<
f64
>
());
assert_
fuzzy
_eq!
(
Real
::
frac_2_pi
::
<
f64
>
(),
2f64
/
Real
::
pi
::
<
f64
>
());
assert_
fuzzy
_eq!
(
Real
::
frac_2_sqrtpi
::
<
f64
>
(),
2f64
/
Real
::
pi
::
<
f64
>
()
.sqrt
());
assert_
fuzzy
_eq!
(
Real
::
sqrt2
::
<
f64
>
(),
2f64
.sqrt
());
assert_
fuzzy
_eq!
(
Real
::
frac_1_sqrt2
::
<
f64
>
(),
1f64
/
2f64
.sqrt
());
assert_
fuzzy
_eq!
(
Real
::
log2_e
::
<
f64
>
(),
Real
::
e
::
<
f64
>
()
.log2
());
assert_
fuzzy
_eq!
(
Real
::
log10_e
::
<
f64
>
(),
Real
::
e
::
<
f64
>
()
.log10
());
assert_
fuzzy
_eq!
(
Real
::
log_2
::
<
f64
>
(),
2f64
.log
());
assert_
fuzzy
_eq!
(
Real
::
log_10
::
<
f64
>
(),
10f64
.log
());
assert_
approx
_eq!
(
Real
::
two_pi
::
<
f64
>
(),
2.0
*
Real
::
pi
::
<
f64
>
());
assert_
approx
_eq!
(
Real
::
frac_pi_2
::
<
f64
>
(),
Real
::
pi
::
<
f64
>
()
/
2f64
);
assert_
approx
_eq!
(
Real
::
frac_pi_3
::
<
f64
>
(),
Real
::
pi
::
<
f64
>
()
/
3f64
);
assert_
approx
_eq!
(
Real
::
frac_pi_4
::
<
f64
>
(),
Real
::
pi
::
<
f64
>
()
/
4f64
);
assert_
approx
_eq!
(
Real
::
frac_pi_6
::
<
f64
>
(),
Real
::
pi
::
<
f64
>
()
/
6f64
);
assert_
approx
_eq!
(
Real
::
frac_pi_8
::
<
f64
>
(),
Real
::
pi
::
<
f64
>
()
/
8f64
);
assert_
approx
_eq!
(
Real
::
frac_1_pi
::
<
f64
>
(),
1f64
/
Real
::
pi
::
<
f64
>
());
assert_
approx
_eq!
(
Real
::
frac_2_pi
::
<
f64
>
(),
2f64
/
Real
::
pi
::
<
f64
>
());
assert_
approx
_eq!
(
Real
::
frac_2_sqrtpi
::
<
f64
>
(),
2f64
/
Real
::
pi
::
<
f64
>
()
.sqrt
());
assert_
approx
_eq!
(
Real
::
sqrt2
::
<
f64
>
(),
2f64
.sqrt
());
assert_
approx
_eq!
(
Real
::
frac_1_sqrt2
::
<
f64
>
(),
1f64
/
2f64
.sqrt
());
assert_
approx
_eq!
(
Real
::
log2_e
::
<
f64
>
(),
Real
::
e
::
<
f64
>
()
.log2
());
assert_
approx
_eq!
(
Real
::
log10_e
::
<
f64
>
(),
Real
::
e
::
<
f64
>
()
.log10
());
assert_
approx
_eq!
(
Real
::
log_2
::
<
f64
>
(),
2f64
.log
());
assert_
approx
_eq!
(
Real
::
log_10
::
<
f64
>
(),
10f64
.log
());
}
#[test]
...
...
@@ -1022,6 +1028,15 @@ pub fn test_signed() {
assert
!
(
!
NaN
.is_negative
());
}
#[test]
fn
test_approx_eq
()
{
assert
!
(
1.0f64
.approx_eq
(
&
1f64
));
assert
!
(
0.9999999f64
.approx_eq
(
&
1f64
));
assert
!
(
1.000001f64
.approx_eq_eps
(
&
1f64
,
&
1.0e-5
));
assert
!
(
1.0000001f64
.approx_eq_eps
(
&
1f64
,
&
1.0e-6
));
assert
!
(
!
1.0000001f64
.approx_eq_eps
(
&
1f64
,
&
1.0e-7
));
}
#[test]
fn
test_primitive
()
{
assert_eq!
(
Primitive
::
bits
::
<
f64
>
(),
sys
::
size_of
::
<
f64
>
()
*
8
);
...
...
src/libcore/num/float.rs
浏览文件 @
2e4790ca
...
...
@@ -371,6 +371,22 @@ fn eq(&self, other: &float) -> bool { (*self) == (*other) }
fn
ne
(
&
self
,
other
:
&
float
)
->
bool
{
(
*
self
)
!=
(
*
other
)
}
}
#[cfg(notest)]
impl
ApproxEq
<
float
>
for
float
{
#[inline(always)]
fn
approx_epsilon
()
->
float
{
1.0e-6
}
#[inline(always)]
fn
approx_eq
(
&
self
,
other
:
&
float
)
->
bool
{
self
.approx_eq_eps
(
other
,
&
ApproxEq
::
approx_epsilon
::
<
float
,
float
>
())
}
#[inline(always)]
fn
approx_eq_eps
(
&
self
,
other
:
&
float
,
approx_epsilon
:
&
float
)
->
bool
{
(
*
self
-
*
other
)
.abs
()
<
*
approx_epsilon
}
}
#[cfg(notest)]
impl
Ord
for
float
{
#[inline(always)]
...
...
@@ -821,15 +837,6 @@ mod tests {
use
super
::
*
;
use
prelude
::
*
;
macro_rules!
assert_fuzzy_eq
(
(
$a:expr
,
$b:expr
)
=>
({
let
a
=
$a
,
b
=
$b
;
if
!
((
a
-
b
)
.abs
()
<
1.0e-6
)
{
fail!
(
fmt!
(
"The values were not approximately equal. Found: %? and %?"
,
a
,
b
));
}
})
)
#[test]
fn
test_num
()
{
num
::
test_num
(
10
f
,
2
f
);
...
...
@@ -859,91 +866,91 @@ fn test_clamp() {
#[test]
fn
test_floor
()
{
assert_
fuzzy
_eq!
(
1.0
f
.floor
(),
1.0
f
);
assert_
fuzzy
_eq!
(
1.3
f
.floor
(),
1.0
f
);
assert_
fuzzy
_eq!
(
1.5
f
.floor
(),
1.0
f
);
assert_
fuzzy
_eq!
(
1.7
f
.floor
(),
1.0
f
);
assert_
fuzzy
_eq!
(
0.0
f
.floor
(),
0.0
f
);
assert_
fuzzy
_eq!
((
-
0.0
f
)
.floor
(),
-
0.0
f
);
assert_
fuzzy
_eq!
((
-
1.0
f
)
.floor
(),
-
1.0
f
);
assert_
fuzzy
_eq!
((
-
1.3
f
)
.floor
(),
-
2.0
f
);
assert_
fuzzy
_eq!
((
-
1.5
f
)
.floor
(),
-
2.0
f
);
assert_
fuzzy
_eq!
((
-
1.7
f
)
.floor
(),
-
2.0
f
);
assert_
approx
_eq!
(
1.0
f
.floor
(),
1.0
f
);
assert_
approx
_eq!
(
1.3
f
.floor
(),
1.0
f
);
assert_
approx
_eq!
(
1.5
f
.floor
(),
1.0
f
);
assert_
approx
_eq!
(
1.7
f
.floor
(),
1.0
f
);
assert_
approx
_eq!
(
0.0
f
.floor
(),
0.0
f
);
assert_
approx
_eq!
((
-
0.0
f
)
.floor
(),
-
0.0
f
);
assert_
approx
_eq!
((
-
1.0
f
)
.floor
(),
-
1.0
f
);
assert_
approx
_eq!
((
-
1.3
f
)
.floor
(),
-
2.0
f
);
assert_
approx
_eq!
((
-
1.5
f
)
.floor
(),
-
2.0
f
);
assert_
approx
_eq!
((
-
1.7
f
)
.floor
(),
-
2.0
f
);
}
#[test]
fn
test_ceil
()
{
assert_
fuzzy
_eq!
(
1.0
f
.ceil
(),
1.0
f
);
assert_
fuzzy
_eq!
(
1.3
f
.ceil
(),
2.0
f
);
assert_
fuzzy
_eq!
(
1.5
f
.ceil
(),
2.0
f
);
assert_
fuzzy
_eq!
(
1.7
f
.ceil
(),
2.0
f
);
assert_
fuzzy
_eq!
(
0.0
f
.ceil
(),
0.0
f
);
assert_
fuzzy
_eq!
((
-
0.0
f
)
.ceil
(),
-
0.0
f
);
assert_
fuzzy
_eq!
((
-
1.0
f
)
.ceil
(),
-
1.0
f
);
assert_
fuzzy
_eq!
((
-
1.3
f
)
.ceil
(),
-
1.0
f
);
assert_
fuzzy
_eq!
((
-
1.5
f
)
.ceil
(),
-
1.0
f
);
assert_
fuzzy
_eq!
((
-
1.7
f
)
.ceil
(),
-
1.0
f
);
assert_
approx
_eq!
(
1.0
f
.ceil
(),
1.0
f
);
assert_
approx
_eq!
(
1.3
f
.ceil
(),
2.0
f
);
assert_
approx
_eq!
(
1.5
f
.ceil
(),
2.0
f
);
assert_
approx
_eq!
(
1.7
f
.ceil
(),
2.0
f
);
assert_
approx
_eq!
(
0.0
f
.ceil
(),
0.0
f
);
assert_
approx
_eq!
((
-
0.0
f
)
.ceil
(),
-
0.0
f
);
assert_
approx
_eq!
((
-
1.0
f
)
.ceil
(),
-
1.0
f
);
assert_
approx
_eq!
((
-
1.3
f
)
.ceil
(),
-
1.0
f
);
assert_
approx
_eq!
((
-
1.5
f
)
.ceil
(),
-
1.0
f
);
assert_
approx
_eq!
((
-
1.7
f
)
.ceil
(),
-
1.0
f
);
}
#[test]
fn
test_round
()
{
assert_
fuzzy
_eq!
(
1.0
f
.round
(),
1.0
f
);
assert_
fuzzy
_eq!
(
1.3
f
.round
(),
1.0
f
);
assert_
fuzzy
_eq!
(
1.5
f
.round
(),
2.0
f
);
assert_
fuzzy
_eq!
(
1.7
f
.round
(),
2.0
f
);
assert_
fuzzy
_eq!
(
0.0
f
.round
(),
0.0
f
);
assert_
fuzzy
_eq!
((
-
0.0
f
)
.round
(),
-
0.0
f
);
assert_
fuzzy
_eq!
((
-
1.0
f
)
.round
(),
-
1.0
f
);
assert_
fuzzy
_eq!
((
-
1.3
f
)
.round
(),
-
1.0
f
);
assert_
fuzzy
_eq!
((
-
1.5
f
)
.round
(),
-
2.0
f
);
assert_
fuzzy
_eq!
((
-
1.7
f
)
.round
(),
-
2.0
f
);
assert_
approx
_eq!
(
1.0
f
.round
(),
1.0
f
);
assert_
approx
_eq!
(
1.3
f
.round
(),
1.0
f
);
assert_
approx
_eq!
(
1.5
f
.round
(),
2.0
f
);
assert_
approx
_eq!
(
1.7
f
.round
(),
2.0
f
);
assert_
approx
_eq!
(
0.0
f
.round
(),
0.0
f
);
assert_
approx
_eq!
((
-
0.0
f
)
.round
(),
-
0.0
f
);
assert_
approx
_eq!
((
-
1.0
f
)
.round
(),
-
1.0
f
);
assert_
approx
_eq!
((
-
1.3
f
)
.round
(),
-
1.0
f
);
assert_
approx
_eq!
((
-
1.5
f
)
.round
(),
-
2.0
f
);
assert_
approx
_eq!
((
-
1.7
f
)
.round
(),
-
2.0
f
);
}
#[test]
fn
test_trunc
()
{
assert_
fuzzy
_eq!
(
1.0
f
.trunc
(),
1.0
f
);
assert_
fuzzy
_eq!
(
1.3
f
.trunc
(),
1.0
f
);
assert_
fuzzy
_eq!
(
1.5
f
.trunc
(),
1.0
f
);
assert_
fuzzy
_eq!
(
1.7
f
.trunc
(),
1.0
f
);
assert_
fuzzy
_eq!
(
0.0
f
.trunc
(),
0.0
f
);
assert_
fuzzy
_eq!
((
-
0.0
f
)
.trunc
(),
-
0.0
f
);
assert_
fuzzy
_eq!
((
-
1.0
f
)
.trunc
(),
-
1.0
f
);
assert_
fuzzy
_eq!
((
-
1.3
f
)
.trunc
(),
-
1.0
f
);
assert_
fuzzy
_eq!
((
-
1.5
f
)
.trunc
(),
-
1.0
f
);
assert_
fuzzy
_eq!
((
-
1.7
f
)
.trunc
(),
-
1.0
f
);
assert_
approx
_eq!
(
1.0
f
.trunc
(),
1.0
f
);
assert_
approx
_eq!
(
1.3
f
.trunc
(),
1.0
f
);
assert_
approx
_eq!
(
1.5
f
.trunc
(),
1.0
f
);
assert_
approx
_eq!
(
1.7
f
.trunc
(),
1.0
f
);
assert_
approx
_eq!
(
0.0
f
.trunc
(),
0.0
f
);
assert_
approx
_eq!
((
-
0.0
f
)
.trunc
(),
-
0.0
f
);
assert_
approx
_eq!
((
-
1.0
f
)
.trunc
(),
-
1.0
f
);
assert_
approx
_eq!
((
-
1.3
f
)
.trunc
(),
-
1.0
f
);
assert_
approx
_eq!
((
-
1.5
f
)
.trunc
(),
-
1.0
f
);
assert_
approx
_eq!
((
-
1.7
f
)
.trunc
(),
-
1.0
f
);
}
#[test]
fn
test_fract
()
{
assert_
fuzzy
_eq!
(
1.0
f
.fract
(),
0.0
f
);
assert_
fuzzy
_eq!
(
1.3
f
.fract
(),
0.3
f
);
assert_
fuzzy
_eq!
(
1.5
f
.fract
(),
0.5
f
);
assert_
fuzzy
_eq!
(
1.7
f
.fract
(),
0.7
f
);
assert_
fuzzy
_eq!
(
0.0
f
.fract
(),
0.0
f
);
assert_
fuzzy
_eq!
((
-
0.0
f
)
.fract
(),
-
0.0
f
);
assert_
fuzzy
_eq!
((
-
1.0
f
)
.fract
(),
-
0.0
f
);
assert_
fuzzy
_eq!
((
-
1.3
f
)
.fract
(),
-
0.3
f
);
assert_
fuzzy
_eq!
((
-
1.5
f
)
.fract
(),
-
0.5
f
);
assert_
fuzzy
_eq!
((
-
1.7
f
)
.fract
(),
-
0.7
f
);
assert_
approx
_eq!
(
1.0
f
.fract
(),
0.0
f
);
assert_
approx
_eq!
(
1.3
f
.fract
(),
0.3
f
);
assert_
approx
_eq!
(
1.5
f
.fract
(),
0.5
f
);
assert_
approx
_eq!
(
1.7
f
.fract
(),
0.7
f
);
assert_
approx
_eq!
(
0.0
f
.fract
(),
0.0
f
);
assert_
approx
_eq!
((
-
0.0
f
)
.fract
(),
-
0.0
f
);
assert_
approx
_eq!
((
-
1.0
f
)
.fract
(),
-
0.0
f
);
assert_
approx
_eq!
((
-
1.3
f
)
.fract
(),
-
0.3
f
);
assert_
approx
_eq!
((
-
1.5
f
)
.fract
(),
-
0.5
f
);
assert_
approx
_eq!
((
-
1.7
f
)
.fract
(),
-
0.7
f
);
}
#[test]
fn
test_real_consts
()
{
assert_
fuzzy
_eq!
(
Real
::
two_pi
::
<
float
>
(),
2
f
*
Real
::
pi
::
<
float
>
());
assert_
fuzzy
_eq!
(
Real
::
frac_pi_2
::
<
float
>
(),
Real
::
pi
::
<
float
>
()
/
2
f
);
assert_
fuzzy
_eq!
(
Real
::
frac_pi_3
::
<
float
>
(),
Real
::
pi
::
<
float
>
()
/
3
f
);
assert_
fuzzy
_eq!
(
Real
::
frac_pi_4
::
<
float
>
(),
Real
::
pi
::
<
float
>
()
/
4
f
);
assert_
fuzzy
_eq!
(
Real
::
frac_pi_6
::
<
float
>
(),
Real
::
pi
::
<
float
>
()
/
6
f
);
assert_
fuzzy
_eq!
(
Real
::
frac_pi_8
::
<
float
>
(),
Real
::
pi
::
<
float
>
()
/
8
f
);
assert_
fuzzy
_eq!
(
Real
::
frac_1_pi
::
<
float
>
(),
1
f
/
Real
::
pi
::
<
float
>
());
assert_
fuzzy
_eq!
(
Real
::
frac_2_pi
::
<
float
>
(),
2
f
/
Real
::
pi
::
<
float
>
());
assert_
fuzzy
_eq!
(
Real
::
frac_2_sqrtpi
::
<
float
>
(),
2
f
/
Real
::
pi
::
<
float
>
()
.sqrt
());
assert_
fuzzy
_eq!
(
Real
::
sqrt2
::
<
float
>
(),
2
f
.sqrt
());
assert_
fuzzy
_eq!
(
Real
::
frac_1_sqrt2
::
<
float
>
(),
1
f
/
2
f
.sqrt
());
assert_
fuzzy
_eq!
(
Real
::
log2_e
::
<
float
>
(),
Real
::
e
::
<
float
>
()
.log2
());
assert_
fuzzy
_eq!
(
Real
::
log10_e
::
<
float
>
(),
Real
::
e
::
<
float
>
()
.log10
());
assert_
fuzzy
_eq!
(
Real
::
log_2
::
<
float
>
(),
2
f
.log
());
assert_
fuzzy
_eq!
(
Real
::
log_10
::
<
float
>
(),
10
f
.log
());
assert_
approx
_eq!
(
Real
::
two_pi
::
<
float
>
(),
2
f
*
Real
::
pi
::
<
float
>
());
assert_
approx
_eq!
(
Real
::
frac_pi_2
::
<
float
>
(),
Real
::
pi
::
<
float
>
()
/
2
f
);
assert_
approx
_eq!
(
Real
::
frac_pi_3
::
<
float
>
(),
Real
::
pi
::
<
float
>
()
/
3
f
);
assert_
approx
_eq!
(
Real
::
frac_pi_4
::
<
float
>
(),
Real
::
pi
::
<
float
>
()
/
4
f
);
assert_
approx
_eq!
(
Real
::
frac_pi_6
::
<
float
>
(),
Real
::
pi
::
<
float
>
()
/
6
f
);
assert_
approx
_eq!
(
Real
::
frac_pi_8
::
<
float
>
(),
Real
::
pi
::
<
float
>
()
/
8
f
);
assert_
approx
_eq!
(
Real
::
frac_1_pi
::
<
float
>
(),
1
f
/
Real
::
pi
::
<
float
>
());
assert_
approx
_eq!
(
Real
::
frac_2_pi
::
<
float
>
(),
2
f
/
Real
::
pi
::
<
float
>
());
assert_
approx
_eq!
(
Real
::
frac_2_sqrtpi
::
<
float
>
(),
2
f
/
Real
::
pi
::
<
float
>
()
.sqrt
());
assert_
approx
_eq!
(
Real
::
sqrt2
::
<
float
>
(),
2
f
.sqrt
());
assert_
approx
_eq!
(
Real
::
frac_1_sqrt2
::
<
float
>
(),
1
f
/
2
f
.sqrt
());
assert_
approx
_eq!
(
Real
::
log2_e
::
<
float
>
(),
Real
::
e
::
<
float
>
()
.log2
());
assert_
approx
_eq!
(
Real
::
log10_e
::
<
float
>
(),
Real
::
e
::
<
float
>
()
.log10
());
assert_
approx
_eq!
(
Real
::
log_2
::
<
float
>
(),
2
f
.log
());
assert_
approx
_eq!
(
Real
::
log_10
::
<
float
>
(),
10
f
.log
());
}
#[test]
...
...
@@ -985,6 +992,15 @@ fn test_signed() {
assert
!
(
!
NaN
.is_negative
());
}
#[test]
fn
test_approx_eq
()
{
assert
!
(
1.0
f
.approx_eq
(
&
1
f
));
assert
!
(
0.9999999
f
.approx_eq
(
&
1
f
));
assert
!
(
1.000001
f
.approx_eq_eps
(
&
1
f
,
&
1.0e-5
));
assert
!
(
1.0000001
f
.approx_eq_eps
(
&
1
f
,
&
1.0e-6
));
assert
!
(
!
1.0000001
f
.approx_eq_eps
(
&
1
f
,
&
1.0e-7
));
}
#[test]
fn
test_primitive
()
{
assert_eq!
(
Primitive
::
bits
::
<
float
>
(),
sys
::
size_of
::
<
float
>
()
*
8
);
...
...
src/libcore/num/num.rs
浏览文件 @
2e4790ca
...
...
@@ -9,7 +9,7 @@
// except according to those terms.
//! An interface for numeric types
use
cmp
::{
Eq
,
Ord
};
use
cmp
::{
Eq
,
ApproxEq
,
Ord
};
use
ops
::{
Add
,
Sub
,
Mul
,
Div
,
Rem
,
Neg
};
use
ops
::{
Not
,
BitAnd
,
BitOr
,
BitXor
,
Shl
,
Shr
};
use
option
::
Option
;
...
...
@@ -240,7 +240,8 @@ pub trait Int: Integer
///
pub
trait
Float
:
Real
+
Signed
+
Primitive
{
+
Primitive
+
ApproxEq
<
Self
>
{
// FIXME (#5527): These should be associated constants
fn
NaN
()
->
Self
;
fn
infinity
()
->
Self
;
...
...
src/libcore/prelude.rs
浏览文件 @
2e4790ca
...
...
@@ -28,7 +28,7 @@
/* Reexported types and traits */
pub
use
clone
::
Clone
;
pub
use
cmp
::{
Eq
,
Ord
,
TotalEq
,
TotalOrd
,
Ordering
,
Less
,
Equal
,
Greater
,
Equiv
};
pub
use
cmp
::{
Eq
,
ApproxEq
,
Ord
,
TotalEq
,
TotalOrd
,
Ordering
,
Less
,
Equal
,
Greater
,
Equiv
};
pub
use
container
::{
Container
,
Mutable
,
Map
,
Set
};
pub
use
hash
::
Hash
;
pub
use
old_iter
::{
BaseIter
,
ReverseIter
,
MutableIter
,
ExtendedIter
,
EqIter
};
...
...
src/librustc/metadata/encoder.rs
浏览文件 @
2e4790ca
...
...
@@ -819,6 +819,7 @@ fn add_to_index_(item: @item, ebml_w: &writer::Encoder,
}
encode_name
(
ecx
,
ebml_w
,
item
.ident
);
encode_attributes
(
ebml_w
,
item
.attrs
);
encode_path
(
ecx
,
ebml_w
,
path
,
ast_map
::
path_name
(
item
.ident
));
encode_region_param
(
ecx
,
ebml_w
,
item
);
...
...
src/libstd/cmp.rs
已删除
100644 → 0
浏览文件 @
0ef4e860
// Copyright 2012-2013 The Rust Project Developers. See the
// COPYRIGHT file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Additional general-purpose comparison functionality.
use
core
::
f32
;
use
core
::
f64
;
use
core
::
float
;
pub
static
FUZZY_EPSILON
:
float
=
1.0e-6
;
pub
trait
FuzzyEq
<
Eps
>
{
fn
fuzzy_eq
(
&
self
,
other
:
&
Self
)
->
bool
;
fn
fuzzy_eq_eps
(
&
self
,
other
:
&
Self
,
epsilon
:
&
Eps
)
->
bool
;
}
impl
FuzzyEq
<
float
>
for
float
{
fn
fuzzy_eq
(
&
self
,
other
:
&
float
)
->
bool
{
self
.fuzzy_eq_eps
(
other
,
&
FUZZY_EPSILON
)
}
fn
fuzzy_eq_eps
(
&
self
,
other
:
&
float
,
epsilon
:
&
float
)
->
bool
{
float
::
abs
(
*
self
-
*
other
)
<
*
epsilon
}
}
impl
FuzzyEq
<
f32
>
for
f32
{
fn
fuzzy_eq
(
&
self
,
other
:
&
f32
)
->
bool
{
self
.fuzzy_eq_eps
(
other
,
&
(
FUZZY_EPSILON
as
f32
))
}
fn
fuzzy_eq_eps
(
&
self
,
other
:
&
f32
,
epsilon
:
&
f32
)
->
bool
{
f32
::
abs
(
*
self
-
*
other
)
<
*
epsilon
}
}
impl
FuzzyEq
<
f64
>
for
f64
{
fn
fuzzy_eq
(
&
self
,
other
:
&
f64
)
->
bool
{
self
.fuzzy_eq_eps
(
other
,
&
(
FUZZY_EPSILON
as
f64
))
}
fn
fuzzy_eq_eps
(
&
self
,
other
:
&
f64
,
epsilon
:
&
f64
)
->
bool
{
f64
::
abs
(
*
self
-
*
other
)
<
*
epsilon
}
}
#[test]
fn
test_fuzzy_equals
()
{
assert
!
((
&
1.0
f
)
.fuzzy_eq
(
&
1.0
));
assert
!
((
&
1.0f32
)
.fuzzy_eq
(
&
1.0f32
));
assert
!
((
&
1.0f64
)
.fuzzy_eq
(
&
1.0f64
));
}
#[test]
fn
test_fuzzy_eq_eps
()
{
assert
!
((
&
1.2
f
)
.fuzzy_eq_eps
(
&
0.9
,
&
0.5
));
assert
!
(
!
(
&
1.5
f
)
.fuzzy_eq_eps
(
&
0.9
,
&
0.5
));
}
#[cfg(test)]
mod
test_complex
{
use
cmp
::
*
;
struct
Complex
{
r
:
float
,
i
:
float
}
impl
FuzzyEq
<
float
>
for
Complex
{
fn
fuzzy_eq
(
&
self
,
other
:
&
Complex
)
->
bool
{
self
.fuzzy_eq_eps
(
other
,
&
FUZZY_EPSILON
)
}
fn
fuzzy_eq_eps
(
&
self
,
other
:
&
Complex
,
epsilon
:
&
float
)
->
bool
{
self
.r
.fuzzy_eq_eps
(
&
other
.r
,
epsilon
)
&&
self
.i
.fuzzy_eq_eps
(
&
other
.i
,
epsilon
)
}
}
#[test]
fn
test_fuzzy_equals
()
{
let
a
=
Complex
{
r
:
0.9
,
i
:
0.9
};
let
b
=
Complex
{
r
:
0.9
,
i
:
0.9
};
assert
!
((
a
.fuzzy_eq
(
&
b
)));
}
#[test]
fn
test_fuzzy_eq_eps
()
{
let
other
=
Complex
{
r
:
0.9
,
i
:
0.9
};
assert
!
((
&
Complex
{
r
:
0.9
,
i
:
1.2
})
.fuzzy_eq_eps
(
&
other
,
&
0.5
));
assert
!
((
&
Complex
{
r
:
1.2
,
i
:
0.9
})
.fuzzy_eq_eps
(
&
other
,
&
0.5
));
assert
!
(
!
(
&
Complex
{
r
:
0.9
,
i
:
1.5
})
.fuzzy_eq_eps
(
&
other
,
&
0.5
));
assert
!
(
!
(
&
Complex
{
r
:
1.5
,
i
:
0.9
})
.fuzzy_eq_eps
(
&
other
,
&
0.5
));
}
}
src/libstd/std.rc
浏览文件 @
2e4790ca
...
...
@@ -93,7 +93,6 @@ pub mod term;
pub mod time;
pub mod arena;
pub mod par;
pub mod cmp;
pub mod base64;
pub mod rl;
pub mod workcache;
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
2e4790ca
...
...
@@ -486,6 +486,42 @@ pub fn core_macros() -> ~str {
)
)
macro_rules! assert_approx_eq (
($given:expr , $expected:expr) => (
{
use core::cmp::ApproxEq;
let given_val = $given;
let expected_val = $expected;
// check both directions of equality....
if !(
given_val.approx_eq(&expected_val) &&
expected_val.approx_eq(&given_val)
) {
fail!(
\"
left: %? does not approximately equal right: %?
\"
,
given_val, expected_val);
}
}
);
($given:expr , $expected:expr , $epsilon:expr) => (
{
use core::cmp::ApproxEq;
let given_val = $given;
let expected_val = $expected;
let epsilon_val = $epsilon;
// check both directions of equality....
if !(
given_val.approx_eq_eps(&expected_val, &epsilon_val) &&
expected_val.approx_eq_eps(&given_val, &epsilon_val)
) {
fail!(
\"
left: %? does not approximately equal right: %? with epsilon: %?
\"
,
given_val, expected_val, epsilon_val);
}
}
)
)
macro_rules! condition (
{ $c:ident: $in:ty -> $out:ty; } => {
...
...
src/test/auxiliary/packed.rs
0 → 100644
浏览文件 @
2e4790ca
#[packed]
struct
S
{
a
:
u8
,
b
:
u32
}
src/test/run-fail/assert-approx-eq-eps-macro-fail.rs
0 → 100644
浏览文件 @
2e4790ca
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:left: 1.0000001 does not approximately equal right: 1 with epsilon: 0.0000001
pub
fn
main
()
{
assert_approx_eq!
(
1.0000001
f
,
1.0
f
,
1.0e-7
);
}
src/test/run-fail/assert-approx-eq-macro-fail.rs
0 → 100644
浏览文件 @
2e4790ca
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:left: 1.00001 does not approximately equal right: 1
pub
fn
main
()
{
assert_approx_eq!
(
1.00001
f
,
1.0
f
);
}
src/test/run-pass/assert-approx-eq-macro-success.rs
0 → 100644
浏览文件 @
2e4790ca
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub
fn
main
()
{
assert_approx_eq!
(
1.0
f
,
1.0
f
);
assert_approx_eq!
(
1.0000001
f
,
1.0
f
);
assert_approx_eq!
(
1.0000001
f
,
1.0
f
,
1.0e-6
);
assert_approx_eq!
(
1.000001
f
,
1.0
f
,
1.0e-5
);
}
src/test/run-pass/intrinsics-math.rs
浏览文件 @
2e4790ca
...
...
@@ -10,10 +10,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern
mod
std
;
use
std
::
cmp
::
FuzzyEq
;
mod
rusti
{
#[abi
=
"rust-intrinsic"
]
pub
extern
"rust-intrinsic"
{
...
...
@@ -54,44 +50,44 @@ pub fn main() {
unsafe
{
use
rusti
::
*
;
assert
!
((
sqrtf32
(
64f32
)
.
fuzzy
_eq
(
&
8f32
)));
assert
!
((
sqrtf64
(
64f64
)
.
fuzzy
_eq
(
&
8f64
)));
assert
!
((
sqrtf32
(
64f32
)
.
approx
_eq
(
&
8f32
)));
assert
!
((
sqrtf64
(
64f64
)
.
approx
_eq
(
&
8f64
)));
assert
!
((
powif32
(
25f32
,
-
2i32
)
.
fuzzy
_eq
(
&
0.0016f32
)));
assert
!
((
powif64
(
23.2f64
,
2i32
)
.
fuzzy
_eq
(
&
538.24f64
)));
assert
!
((
powif32
(
25f32
,
-
2i32
)
.
approx
_eq
(
&
0.0016f32
)));
assert
!
((
powif64
(
23.2f64
,
2i32
)
.
approx
_eq
(
&
538.24f64
)));
assert
!
((
sinf32
(
0f32
)
.
fuzzy
_eq
(
&
0f32
)));
assert
!
((
sinf64
(
f64
::
consts
::
pi
/
2f64
)
.
fuzzy
_eq
(
&
1f64
)));
assert
!
((
sinf32
(
0f32
)
.
approx
_eq
(
&
0f32
)));
assert
!
((
sinf64
(
f64
::
consts
::
pi
/
2f64
)
.
approx
_eq
(
&
1f64
)));
assert
!
((
cosf32
(
0f32
)
.
fuzzy
_eq
(
&
1f32
)));
assert
!
((
cosf64
(
f64
::
consts
::
pi
*
2f64
)
.
fuzzy
_eq
(
&
1f64
)));
assert
!
((
cosf32
(
0f32
)
.
approx
_eq
(
&
1f32
)));
assert
!
((
cosf64
(
f64
::
consts
::
pi
*
2f64
)
.
approx
_eq
(
&
1f64
)));
assert
!
((
powf32
(
25f32
,
-
2f32
)
.
fuzzy
_eq
(
&
0.0016f32
)));
assert
!
((
powf64
(
400f64
,
0.5f64
)
.
fuzzy
_eq
(
&
20f64
)));
assert
!
((
powf32
(
25f32
,
-
2f32
)
.
approx
_eq
(
&
0.0016f32
)));
assert
!
((
powf64
(
400f64
,
0.5f64
)
.
approx
_eq
(
&
20f64
)));
assert
!
((
fabsf32
(
expf32
(
1f32
)
-
f32
::
consts
::
e
)
.
fuzzy
_eq
(
&
0f32
)));
assert
!
((
expf64
(
1f64
)
.
fuzzy
_eq
(
&
f64
::
consts
::
e
)));
assert
!
((
fabsf32
(
expf32
(
1f32
)
-
f32
::
consts
::
e
)
.
approx
_eq
(
&
0f32
)));
assert
!
((
expf64
(
1f64
)
.
approx
_eq
(
&
f64
::
consts
::
e
)));
assert
!
((
exp2f32
(
10f32
)
.
fuzzy
_eq
(
&
1024f32
)));
assert
!
((
exp2f64
(
50f64
)
.
fuzzy
_eq
(
&
1125899906842624f64
)));
assert
!
((
exp2f32
(
10f32
)
.
approx
_eq
(
&
1024f32
)));
assert
!
((
exp2f64
(
50f64
)
.
approx
_eq
(
&
1125899906842624f64
)));
assert
!
((
fabsf32
(
logf32
(
f32
::
consts
::
e
)
-
1f32
)
.
fuzzy
_eq
(
&
0f32
)));
assert
!
((
logf64
(
1f64
)
.
fuzzy
_eq
(
&
0f64
)));
assert
!
((
fabsf32
(
logf32
(
f32
::
consts
::
e
)
-
1f32
)
.
approx
_eq
(
&
0f32
)));
assert
!
((
logf64
(
1f64
)
.
approx
_eq
(
&
0f64
)));
assert
!
((
log10f32
(
10f32
)
.
fuzzy
_eq
(
&
1f32
)));
assert
!
((
log10f64
(
f64
::
consts
::
e
)
.
fuzzy
_eq
(
&
f64
::
consts
::
log10_e
)));
assert
!
((
log10f32
(
10f32
)
.
approx
_eq
(
&
1f32
)));
assert
!
((
log10f64
(
f64
::
consts
::
e
)
.
approx
_eq
(
&
f64
::
consts
::
log10_e
)));
assert
!
((
log2f32
(
8f32
)
.
fuzzy
_eq
(
&
3f32
)));
assert
!
((
log2f64
(
f64
::
consts
::
e
)
.
fuzzy
_eq
(
&
f64
::
consts
::
log2_e
)));
assert
!
((
log2f32
(
8f32
)
.
approx
_eq
(
&
3f32
)));
assert
!
((
log2f64
(
f64
::
consts
::
e
)
.
approx
_eq
(
&
f64
::
consts
::
log2_e
)));
assert
!
((
fmaf32
(
1.0f32
,
2.0f32
,
5.0f32
)
.
fuzzy
_eq
(
&
7.0f32
)));
assert
!
((
fmaf64
(
0.0f64
,
-
2.0f64
,
f64
::
consts
::
e
)
.
fuzzy
_eq
(
&
f64
::
consts
::
e
)));
assert
!
((
fmaf32
(
1.0f32
,
2.0f32
,
5.0f32
)
.
approx
_eq
(
&
7.0f32
)));
assert
!
((
fmaf64
(
0.0f64
,
-
2.0f64
,
f64
::
consts
::
e
)
.
approx
_eq
(
&
f64
::
consts
::
e
)));
assert
!
((
fabsf32
(
-
1.0f32
)
.
fuzzy
_eq
(
&
1.0f32
)));
assert
!
((
fabsf64
(
34.2f64
)
.
fuzzy
_eq
(
&
34.2f64
)));
assert
!
((
fabsf32
(
-
1.0f32
)
.
approx
_eq
(
&
1.0f32
)));
assert
!
((
fabsf64
(
34.2f64
)
.
approx
_eq
(
&
34.2f64
)));
assert
!
((
floorf32
(
3.8f32
)
.
fuzzy
_eq
(
&
3.0f32
)));
assert
!
((
floorf64
(
-
1.1f64
)
.
fuzzy
_eq
(
&-
2.0f64
)));
assert
!
((
floorf32
(
3.8f32
)
.
approx
_eq
(
&
3.0f32
)));
assert
!
((
floorf64
(
-
1.1f64
)
.
approx
_eq
(
&-
2.0f64
)));
// Causes linker error
// undefined reference to llvm.ceil.f32/64
...
...
src/test/run-pass/packed-struct-size-xc.rs
0 → 100644
浏览文件 @
2e4790ca
// xfail-fast
// aux-build:packed.rs
extern
mod
packed
;
fn
main
()
{
assert_eq!
(
sys
::
size_of
::
<
packed
::
S
>
(),
5
);
}
src/test/run-pass/trait-inheritance-num.rs
浏览文件 @
2e4790ca
...
...
@@ -14,11 +14,10 @@
use
core
::
cmp
::{
Eq
,
Ord
};
use
core
::
num
::
NumCast
::
from
;
use
std
::
cmp
::
FuzzyEq
;
pub
trait
NumExt
:
Num
+
NumCast
+
Eq
+
Ord
{}
pub
trait
FloatExt
:
NumExt
+
Fuzzy
Eq
<
Self
>
{}
pub
trait
FloatExt
:
NumExt
+
Approx
Eq
<
Self
>
{}
fn
greater_than_one
<
T
:
NumExt
>
(
n
:
&
T
)
->
bool
{
*
n
>
from
(
1
)
}
fn
greater_than_one_float
<
T
:
FloatExt
>
(
n
:
&
T
)
->
bool
{
*
n
>
from
(
1
)
}
...
...
src/test/run-pass/trait-inheritance-num2.rs
浏览文件 @
2e4790ca
...
...
@@ -16,7 +16,6 @@
use
core
::
cmp
::{
Eq
,
Ord
};
use
core
::
num
::
NumCast
::
from
;
use
std
::
cmp
::
FuzzyEq
;
pub
trait
TypeExt
{}
...
...
@@ -94,7 +93,7 @@ impl IntegerExt for i64 {}
impl
IntegerExt
for
int
{}
pub
trait
FloatExt
:
NumExt
+
Fuzzy
Eq
<
Self
>
{}
pub
trait
FloatExt
:
NumExt
+
Approx
Eq
<
Self
>
{}
impl
FloatExt
for
f32
{}
impl
FloatExt
for
f64
{}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录