Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
16405386
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
16405386
编写于
12月 28, 2011
作者:
S
Stefan Plantikow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: added support for bessel functions
上级
a72b1413
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
104 addition
and
92 deletion
+104
-92
src/libcore/bessel.rs
src/libcore/bessel.rs
+10
-0
src/libcore/cmath.rs
src/libcore/cmath.rs
+12
-15
src/libcore/core.rc
src/libcore/core.rc
+2
-1
src/libcore/f32.rs
src/libcore/f32.rs
+39
-37
src/libcore/f64.rs
src/libcore/f64.rs
+38
-37
src/libcore/float.rs
src/libcore/float.rs
+3
-2
未找到文件。
src/libcore/bessel.rs
0 → 100644
浏览文件 @
16405386
// PORT import module that is based on cmath::c_double here
// (cant do better via libm; bessel functions only exist for c_double)
// code that wants to use bessel functions should use
// values of type bessel::t and cast from/to float/f32/f64
// when working with them at the peril of precision loss
// for platform neutrality
import
f64
::
*
;
src/libcore/cmath.rs
浏览文件 @
16405386
export
c_double
;
export
c_float
;
export
bessel
;
import
ctypes
::
c_int
;
import
ctypes
::
c_float
;
...
...
@@ -57,6 +56,16 @@
pure
fn
tanh
(
n
:
c_double
)
->
c_double
;
pure
fn
tgamma
(
n
:
c_double
)
->
c_double
;
pure
fn
trunc
(
n
:
c_double
)
->
c_double
;
// These are commonly only available for doubles
pure
fn
j0
(
n
:
c_double
)
->
c_double
;
pure
fn
j1
(
n
:
c_double
)
->
c_double
;
pure
fn
jn
(
i
:
c_int
,
n
:
c_double
)
->
c_double
;
pure
fn
y0
(
n
:
c_double
)
->
c_double
;
pure
fn
y1
(
n
:
c_double
)
->
c_double
;
pure
fn
yn
(
i
:
c_int
,
n
:
c_double
)
->
c_double
;
}
#[link_name
=
"m"
]
...
...
@@ -83,7 +92,7 @@
#[link_name=
"fabsf"
]
pure
fn
abs
(
n
:
c_float
)
->
c_float
;
#[link_name=
"fdimf"
]
pure
fn
sub_pos
(
a
:
c_float
,
b
:
c_float
)
->
c_float
;
#[link_name=
"floorf"
]
pure
fn
floor
(
n
:
c_float
)
->
c_float
;
#[link_name=
"frexpf"
]
pure
fn
frexp
(
n
:
c_
double
,
#[link_name=
"frexpf"
]
pure
fn
frexp
(
n
:
c_
float
,
&
value
:
c_int
)
->
c_float
;
#[link_name=
"fmaf"
]
pure
fn
mul_add
(
a
:
c_float
,
b
:
c_float
,
c
:
c_float
)
->
c_float
;
...
...
@@ -97,7 +106,7 @@
&
sign
:
c_int
)
->
c_float
;
#[link_name=
"logf"
]
pure
fn
ln
(
n
:
c_float
)
->
c_float
;
#[link_name=
"logbf"
]
pure
fn
logb
(
n
:
c_float
)
->
c_float
;
#[link_name=
"log1p
"
]
pure
fn
ln1p
(
n
:
c_double
)
->
c_double
;
#[link_name=
"log1p
f"
]
pure
fn
ln1p
(
n
:
c_float
)
->
c_float
;
#[link_name=
"log2f"
]
pure
fn
log2
(
n
:
c_float
)
->
c_float
;
#[link_name=
"log10f"
]
pure
fn
log10
(
n
:
c_float
)
->
c_float
;
#[link_name=
"ilogbf"
]
pure
fn
ilogb
(
n
:
c_float
)
->
c_int
;
...
...
@@ -116,18 +125,6 @@
#[link_name=
"truncf"
]
pure
fn
trunc
(
n
:
c_float
)
->
c_float
;
}
#[link_name
=
"m"
]
#[abi
=
"cdecl"
]
native
mod
bessel
{
pure
fn
j0
(
n
:
c_double
)
->
c_double
;
pure
fn
j1
(
n
:
c_double
)
->
c_double
;
pure
fn
jn
(
i
:
c_int
,
n
:
c_double
)
->
c_double
;
pure
fn
y0
(
n
:
c_double
)
->
c_double
;
pure
fn
y1
(
n
:
c_double
)
->
c_double
;
pure
fn
yn
(
i
:
c_int
,
n
:
c_double
)
->
c_double
;
}
//
// Local Variables:
// mode: rust
...
...
src/libcore/core.rc
浏览文件 @
16405386
...
...
@@ -7,7 +7,7 @@
#[license = "BSD"];
#[crate_type = "lib"];
export box, char, float, f32, f64, int, str, ptr;
export box, char, float,
bessel,
f32, f64, int, str, ptr;
export uint, u8, u32, u64, vec, bool;
export either, option, result;
export ctypes, sys, unsafe, comm, task;
...
...
@@ -18,6 +18,7 @@ export extfmt;
mod box;
mod char;
mod float;
mod bessel;
mod f32;
mod f64;
mod int;
...
...
src/libcore/f32.rs
浏览文件 @
16405386
...
...
@@ -3,20 +3,43 @@
Floating point operations and constants for `f32`
*/
// PORT
import
cmath
::
c_float
::
*
;
type
t
=
f32
;
// These are not defined inside consts:: for consistency with
// the integer types
// PORT check per architecture
const
radix
:
uint
=
2u
;
const
mantissa_digits
:
uint
=
24u
;
const
digits
:
uint
=
6u
;
const
epsilon
:
f32
=
1.19209290e-07_f32
;
const
min_value
:
f32
=
1.17549435e-38_f32
;
const
max_value
:
f32
=
3.40282347e+38_f32
;
const
min_exp
:
int
=
-
125
;
const
max_exp
:
int
=
128
;
const
min_10_exp
:
int
=
-
37
;
const
max_10_exp
:
int
=
38
;
/* Const: NaN */
const
NaN
:
f32
=
0.0
f32
/
0.0
f32
;
const
NaN
:
f32
=
0.0
_f32
/
0.0_
f32
;
/* Const: infinity */
const
infinity
:
f32
=
1.0
f32
/
0.0
f32
;
const
infinity
:
f32
=
1.0
_f32
/
0.0_
f32
;
/* Const: neg_infinity */
const
neg_infinity
:
f32
=
-
1.0
f32
/
0.0
f32
;
const
neg_infinity
:
f32
=
-
1.0
_f32
/
0.0_
f32
;
/* Predicate: isNaN */
pure
fn
isNaN
(
f
:
f32
)
->
bool
{
f
!=
f
}
...
...
@@ -98,114 +121,93 @@ mod consts {
Archimedes' constant
*/
const
pi
:
f32
=
3.14159265358979323846264338327950288f32
;
const
pi
:
f32
=
3.14159265358979323846264338327950288
_
f32
;
/*
Const: frac_pi_2
pi/2.0
*/
const
frac_pi_2
:
f32
=
1.57079632679489661923132169163975144f32
;
const
frac_pi_2
:
f32
=
1.57079632679489661923132169163975144
_
f32
;
/*
Const: frac_pi_4
pi/4.0
*/
const
frac_pi_4
:
f32
=
0.785398163397448309615660845819875721f32
;
const
frac_pi_4
:
f32
=
0.785398163397448309615660845819875721
_
f32
;
/*
Const: frac_1_pi
1.0/pi
*/
const
frac_1_pi
:
f32
=
0.318309886183790671537767526745028724f32
;
const
frac_1_pi
:
f32
=
0.318309886183790671537767526745028724
_
f32
;
/*
Const: frac_2_pi
2.0/pi
*/
const
frac_2_pi
:
f32
=
0.636619772367581343075535053490057448f32
;
const
frac_2_pi
:
f32
=
0.636619772367581343075535053490057448
_
f32
;
/*
Const: frac_2_sqrtpi
2.0/sqrt(pi)
*/
const
frac_2_sqrtpi
:
f32
=
1.12837916709551257389615890312154517f32
;
const
frac_2_sqrtpi
:
f32
=
1.12837916709551257389615890312154517
_
f32
;
/*
Const: sqrt2
sqrt(2.0)
*/
const
sqrt2
:
f32
=
1.41421356237309504880168872420969808f32
;
const
sqrt2
:
f32
=
1.41421356237309504880168872420969808
_
f32
;
/*
Const: frac_1_sqrt2
1.0/sqrt(2.0)
*/
const
frac_1_sqrt2
:
f32
=
0.707106781186547524400844362104849039f32
;
const
frac_1_sqrt2
:
f32
=
0.707106781186547524400844362104849039
_
f32
;
/*
Const: e
Euler's number
*/
const
e
:
f32
=
2.71828182845904523536028747135266250f32
;
const
e
:
f32
=
2.71828182845904523536028747135266250
_
f32
;
/*
Const: log2_e
log2(e)
*/
const
log2_e
:
f32
=
1.44269504088896340735992468100189214f32
;
const
log2_e
:
f32
=
1.44269504088896340735992468100189214
_
f32
;
/*
Const: log10_e
log10(e)
*/
const
log10_e
:
f32
=
0.434294481903251827651128918916605082f32
;
const
log10_e
:
f32
=
0.434294481903251827651128918916605082
_
f32
;
/*
Const: ln_2
ln(2.0)
*/
const
ln_2
:
f32
=
0.693147180559945309417232121458176568f32
;
const
ln_2
:
f32
=
0.693147180559945309417232121458176568
_
f32
;
/*
Const: ln_10
ln(10.0)
*/
const
ln_10
:
f32
=
2.30258509299404568401799145468436421f32
;
const
ln_10
:
f32
=
2.30258509299404568401799145468436421
_
f32
;
}
// These are not defined inside consts:: for consistency with
// the integer types
// PORT check per architecture
const
radix
:
uint
=
2u
;
const
mantissa_digits
:
uint
=
24u
;
const
digits
:
uint
=
6u
;
const
epsilon
:
f32
=
1.19209290e-07f32
;
const
min_value
:
f32
=
1.17549435e-38f32
;
const
max_value
:
f32
=
3.40282347e+38f32
;
const
min_exp
:
int
=
-
125
;
const
max_exp
:
int
=
128
;
const
min_10_exp
:
int
=
-
37
;
const
max_10_exp
:
int
=
38
;
//
// Local Variables:
// mode: rust
...
...
src/libcore/f64.rs
浏览文件 @
16405386
...
...
@@ -10,14 +10,36 @@
type
t
=
f64
;
// These are not defined inside consts:: for consistency with
// the integer types
// PORT check per architecture
const
radix
:
uint
=
2u
;
const
mantissa_digits
:
uint
=
53u
;
const
digits
:
uint
=
15u
;
const
epsilon
:
f64
=
2.2204460492503131e-16_f64
;
const
min_value
:
f64
=
2.2250738585072014e-308_f64
;
const
max_value
:
f64
=
1.7976931348623157e+308_f64
;
const
min_exp
:
int
=
-
1021
;
const
max_exp
:
int
=
1024
;
const
min_10_exp
:
int
=
-
307
;
const
max_10_exp
:
int
=
308
;
/* Const: NaN */
const
NaN
:
f64
=
0.0
f64
/
0.0
f64
;
const
NaN
:
f64
=
0.0
_f64
/
0.0_
f64
;
/* Const: infinity */
const
infinity
:
f64
=
1.0
f64
/
0.0
f64
;
const
infinity
:
f64
=
1.0
_f64
/
0.0_
f64
;
/* Const: neg_infinity */
const
neg_infinity
:
f64
=
-
1.0
f64
/
0.0
f64
;
const
neg_infinity
:
f64
=
-
1.0
_f64
/
0.0_
f64
;
/* Predicate: isNaN */
pure
fn
isNaN
(
f
:
f64
)
->
bool
{
f
!=
f
}
...
...
@@ -99,114 +121,93 @@ mod consts {
Archimedes' constant
*/
const
pi
:
f64
=
3.14159265358979323846264338327950288f64
;
const
pi
:
f64
=
3.14159265358979323846264338327950288
_
f64
;
/*
Const: frac_pi_2
pi/2.0
*/
const
frac_pi_2
:
f64
=
1.57079632679489661923132169163975144f64
;
const
frac_pi_2
:
f64
=
1.57079632679489661923132169163975144
_
f64
;
/*
Const: frac_pi_4
pi/4.0
*/
const
frac_pi_4
:
f64
=
0.785398163397448309615660845819875721f64
;
const
frac_pi_4
:
f64
=
0.785398163397448309615660845819875721
_
f64
;
/*
Const: frac_1_pi
1.0/pi
*/
const
frac_1_pi
:
f64
=
0.318309886183790671537767526745028724f64
;
const
frac_1_pi
:
f64
=
0.318309886183790671537767526745028724
_
f64
;
/*
Const: frac_2_pi
2.0/pi
*/
const
frac_2_pi
:
f64
=
0.636619772367581343075535053490057448f64
;
const
frac_2_pi
:
f64
=
0.636619772367581343075535053490057448
_
f64
;
/*
Const: frac_2_sqrtpi
2.0/sqrt(pi)
*/
const
frac_2_sqrtpi
:
f64
=
1.12837916709551257389615890312154517f64
;
const
frac_2_sqrtpi
:
f64
=
1.12837916709551257389615890312154517
_
f64
;
/*
Const: sqrt2
sqrt(2.0)
*/
const
sqrt2
:
f64
=
1.41421356237309504880168872420969808f64
;
const
sqrt2
:
f64
=
1.41421356237309504880168872420969808
_
f64
;
/*
Const: frac_1_sqrt2
1.0/sqrt(2.0)
*/
const
frac_1_sqrt2
:
f64
=
0.707106781186547524400844362104849039f64
;
const
frac_1_sqrt2
:
f64
=
0.707106781186547524400844362104849039
_
f64
;
/*
Const: e
Euler's number
*/
const
e
:
f64
=
2.71828182845904523536028747135266250f64
;
const
e
:
f64
=
2.71828182845904523536028747135266250
_
f64
;
/*
Const: log2_e
log2(e)
*/
const
log2_e
:
f64
=
1.44269504088896340735992468100189214f64
;
const
log2_e
:
f64
=
1.44269504088896340735992468100189214
_
f64
;
/*
Const: log10_e
log10(e)
*/
const
log10_e
:
f64
=
0.434294481903251827651128918916605082f64
;
const
log10_e
:
f64
=
0.434294481903251827651128918916605082
_
f64
;
/*
Const: ln_2
ln(2.0)
*/
const
ln_2
:
f64
=
0.693147180559945309417232121458176568f64
;
const
ln_2
:
f64
=
0.693147180559945309417232121458176568
_
f64
;
/*
Const: ln_10
ln(10.0)
*/
const
ln_10
:
f64
=
2.30258509299404568401799145468436421f64
;
const
ln_10
:
f64
=
2.30258509299404568401799145468436421
_
f64
;
}
// These are not defined inside consts:: for consistency with
// the integer types
// PORT check per architecture
const
radix
:
uint
=
2u
;
const
mantissa_digits
:
uint
=
53u
;
const
digits
:
uint
=
15u
;
const
epsilon
:
f64
=
2.2204460492503131e-16f64
;
const
min_value
:
f64
=
2.2250738585072014e-308f64
;
const
max_value
:
f64
=
1.7976931348623157e+308f64
;
const
min_exp
:
int
=
-
1021
;
const
max_exp
:
int
=
1024
;
const
min_10_exp
:
int
=
-
307
;
const
max_10_exp
:
int
=
308
;
//
// Local Variables:
// mode: rust
...
...
src/libcore/float.rs
浏览文件 @
16405386
...
...
@@ -2,7 +2,7 @@
Module: float
*/
// PORT
T
his must match in width according to architecture
// PORT
t
his must match in width according to architecture
import
m_float
=
f64
;
import
m_float
::
*
;
...
...
@@ -25,11 +25,12 @@
exact - Whether to enforce the exact number of significant digits
*/
fn
to_str_common
(
num
:
float
,
digits
:
uint
,
exact
:
bool
)
->
str
{
if
isNaN
(
num
)
{
ret
"NaN"
;
}
let
(
num
,
accum
)
=
num
<
0.0
?
(
-
num
,
"-"
)
:
(
num
,
""
);
let
trunc
=
num
as
uint
;
let
frac
=
num
-
(
trunc
as
float
);
accum
+=
uint
::
str
(
trunc
);
if
frac
==
0.0
||
digits
==
0u
{
ret
accum
;
}
if
frac
<
epsilon
||
digits
==
0u
{
ret
accum
;
}
accum
+=
"."
;
let
i
=
digits
;
let
epsilon
=
1
.
/
pow_uint_to_uint_as_float
(
10u
,
i
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录