Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f4bedded
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,发现更多精彩内容 >>
提交
f4bedded
编写于
11月 09, 2013
作者:
J
Jay Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update docs for Fractional, Algebraic, Round, and Trigonometric traits.
上级
c0b7972f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
89 addition
and
0 deletion
+89
-0
src/libstd/num/mod.rs
src/libstd/num/mod.rs
+89
-0
未找到文件。
src/libstd/num/mod.rs
浏览文件 @
f4bedded
...
...
@@ -136,26 +136,87 @@ pub trait Integer: Num
/// Calculates the Lowest Common Multiple (LCM) of the number and `other`.
#[inline(always)]
pub
fn
lcm
<
T
:
Integer
>
(
x
:
T
,
y
:
T
)
->
T
{
x
.lcm
(
&
y
)
}
/// A collection of rounding operations.
pub
trait
Round
{
/// Return the largest integer less than or equal to a number.
///
/// # Example
///
/// ```rust
/// assert_approx_eq!(1.3f32.floor(), 1.0);
/// assert_approx_eq!((-1.3f32).floor(), -2.0);
/// ```
fn
floor
(
&
self
)
->
Self
;
/// Return the smallest integer greater than or equal to a number.
///
/// # Example
///
/// ```rust
/// assert_approx_eq!(1.3f32.ceil(), 2.0);
/// assert_approx_eq!((-1.3f32).ceil(), -1.0);
/// ```
fn
ceil
(
&
self
)
->
Self
;
/// Return the nearest integer to a number. Round half-way cases away from
/// `0.0`.
///
/// # Example
///
/// ```rust
/// assert_approx_eq!(1.3f32.round(), 1.0);
/// assert_approx_eq!((-1.3f32).round(), -1.0);
/// assert_approx_eq!(1.5f32.round(), 2.0);
/// assert_approx_eq!((-1.5f32).round(), -2.0);
/// ```
fn
round
(
&
self
)
->
Self
;
/// Return the integer part of a number.
///
/// # Example
///
/// ```rust
/// assert_approx_eq!(1.3f32.round(), 1.0);
/// assert_approx_eq!((-1.3f32).round(), -1.0);
/// assert_approx_eq!(1.5f32.round(), 1.0);
/// assert_approx_eq!((-1.5f32).round(), -1.0);
/// ```
fn
trunc
(
&
self
)
->
Self
;
/// Return the fractional part of a number.
///
/// # Example
///
/// ```rust
/// assert_approx_eq!(1.3f32.round(), 0.3);
/// assert_approx_eq!((-1.3f32).round(), -0.3);
/// assert_approx_eq!(1.5f32.round(), 0.5);
/// assert_approx_eq!((-1.5f32).round(), -0.5);
/// ```
fn
fract
(
&
self
)
->
Self
;
}
/// Trait for common fractional operations.
pub
trait
Fractional
:
Num
+
Orderable
+
Round
+
Div
<
Self
,
Self
>
{
/// Take the reciprocal (inverse) of a number, `1/x`.
fn
recip
(
&
self
)
->
Self
;
}
/// A collection of algebraic operations.
pub
trait
Algebraic
{
/// Raise a number to a power.
fn
pow
(
&
self
,
n
:
&
Self
)
->
Self
;
/// Take the squre root of a number.
fn
sqrt
(
&
self
)
->
Self
;
/// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`.
fn
rsqrt
(
&
self
)
->
Self
;
/// Take the cubic root of a number.
fn
cbrt
(
&
self
)
->
Self
;
/// Calculate the length of the hypotenuse of a right-angle triangle given
/// legs of length `x` and `y`.
fn
hypot
(
&
self
,
other
:
&
Self
)
->
Self
;
}
...
...
@@ -178,16 +239,44 @@ pub trait Algebraic {
/// `y`.
#[inline(always)]
pub
fn
hypot
<
T
:
Algebraic
>
(
x
:
T
,
y
:
T
)
->
T
{
x
.hypot
(
&
y
)
}
/// A trait for trigonometric functions.
pub
trait
Trigonometric
{
/// Computes the sine of a number (in radians).
fn
sin
(
&
self
)
->
Self
;
/// Computes the cosine of a number (in radians).
fn
cos
(
&
self
)
->
Self
;
/// Computes the tangent of a number (in radians).
fn
tan
(
&
self
)
->
Self
;
/// Computes the arcsine of a number. Return value is in radians in
/// the range [-pi/2, pi/2] or NaN if the number is outside the range
/// [-1, 1].
fn
asin
(
&
self
)
->
Self
;
/// Computes the arccosine of a number. Return value is in radians in
/// the range [0, pi] or NaN if the number is outside the range
/// [-1, 1].
fn
acos
(
&
self
)
->
Self
;
/// Computes the arctangent of a number. Return value is in radians in the
/// range [-pi/2, pi/2];
fn
atan
(
&
self
)
->
Self
;
/// Computes the four quadrant arctangent of a number, `y`, and another
/// number `x`. Return value is in radians in the range [-pi, pi];
///
/// # Example
///
/// ```rust
/// let y = 3f32.sqrt();
/// let x = 1f32;
/// let pi_3 = 1.04719758f32;
/// assert_approx_eq!(y.atan2(&x), pi_3);
/// let neg_2_pi_3 = -2.09439516f32;
/// assert_approx_eq!((-y).atan2(&(-x)), neg_2_pi_3);
/// ```
fn
atan2
(
&
self
,
other
:
&
Self
)
->
Self
;
/// Simultaneously computes the sine and cosine of the number, `x`. Returns
/// `(sin(x), cos(x))`.
fn
sin_cos
(
&
self
)
->
(
Self
,
Self
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录