Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Mr_Pangza
rt-thread
提交
7a8dfb6d
R
rt-thread
项目概览
Mr_Pangza
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
2
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7a8dfb6d
编写于
1月 13, 2013
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11 from grissiom/remove-newlib-math
remove math code for newlib
上级
64bf67cc
9168e18e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
8 addition
and
261 deletion
+8
-261
components/libc/newlib/SConscript
components/libc/newlib/SConscript
+8
-1
components/libc/newlib/math.c
components/libc/newlib/math.c
+0
-260
未找到文件。
components/libc/newlib/SConscript
浏览文件 @
7a8dfb6d
...
...
@@ -11,6 +11,13 @@ cwd = GetCurrentDir()
src
=
Glob
(
'*.c'
)
CPPPATH
=
[
cwd
]
group
=
DefineGroup
(
'newlib'
,
src
,
depend
=
[
'RT_USING_NEWLIB'
],
CPPPATH
=
CPPPATH
)
# link with libm in default.
# libm is a frequently used lib. Newlib is compiled with -ffunction-sections in
# recent GCC tool chains. The linker would just link in the functions that have
# been referenced. So setting this won't result in bigger text size.
LIBS
=
[
'm'
]
group
=
DefineGroup
(
'newlib'
,
src
,
depend
=
[
'RT_USING_NEWLIB'
],
CPPPATH
=
CPPPATH
,
LIBS
=
LIBS
)
Return
(
'group'
)
components/libc/newlib/math.c
已删除
100644 → 0
浏览文件 @
64bf67cc
#include <math.h>
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS CRT
* FILE: lib/crt/math/cos.c
* PURPOSE: Generic C Implementation of cos
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
*/
#define PRECISION 9
static
double
cos_off_tbl
[]
=
{
0
.
0
,
-
M_PI
/
2
.,
0
,
-
M_PI
/
2
.};
static
double
cos_sign_tbl
[]
=
{
1
,
-
1
,
-
1
,
1
};
static
double
sin_off_tbl
[]
=
{
0
.
0
,
-
M_PI
/
2
.,
0
,
-
M_PI
/
2
.};
static
double
sin_sign_tbl
[]
=
{
1
,
-
1
,
-
1
,
1
};
double
sin
(
double
x
)
{
int
quadrant
;
double
x2
,
result
;
/* Calculate the quadrant */
quadrant
=
x
*
(
2
.
/
M_PI
);
/* Get offset inside quadrant */
x
=
x
-
quadrant
*
(
M_PI
/
2
.);
/* Normalize quadrant to [0..3] */
quadrant
=
(
quadrant
-
1
)
&
0x3
;
/* Fixup value for the generic function */
x
+=
sin_off_tbl
[
quadrant
];
/* Calculate the negative of the square of x */
x2
=
-
(
x
*
x
);
/* This is an unrolled taylor series using <PRECISION> iterations
* Example with 4 iterations:
* result = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8!
* To save multiplications and to keep the precision high, it's performed
* like this:
* result = 1 - x^2 * (1/2! - x^2 * (1/4! - x^2 * (1/6! - x^2 * (1/8!))))
*/
/* Start with 0, compiler will optimize this away */
result
=
0
;
#if (PRECISION >= 10)
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
*
7
*
8
*
9
*
10
*
11
*
12
*
13
*
14
*
15
*
16
*
17
*
18
*
19
*
20
);
result
*=
x2
;
#endif
#if (PRECISION >= 9)
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
*
7
*
8
*
9
*
10
*
11
*
12
*
13
*
14
*
15
*
16
*
17
*
18
);
result
*=
x2
;
#endif
#if (PRECISION >= 8)
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
*
7
*
8
*
9
*
10
*
11
*
12
*
13
*
14
*
15
*
16
);
result
*=
x2
;
#endif
#if (PRECISION >= 7)
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
*
7
*
8
*
9
*
10
*
11
*
12
*
13
*
14
);
result
*=
x2
;
#endif
#if (PRECISION >= 6)
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
*
7
*
8
*
9
*
10
*
11
*
12
);
result
*=
x2
;
#endif
#if (PRECISION >= 5)
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
*
7
*
8
*
9
*
10
);
result
*=
x2
;
#endif
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
*
7
*
8
);
result
*=
x2
;
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
);
result
*=
x2
;
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
);
result
*=
x2
;
result
+=
1
.
/
(
1
.
*
2
);
result
*=
x2
;
result
+=
1
;
/* Apply correct sign */
result
*=
sin_sign_tbl
[
quadrant
];
return
result
;
}
double
cos
(
double
x
)
{
int
quadrant
;
double
x2
,
result
;
/* Calculate the quadrant */
quadrant
=
x
*
(
2
.
/
M_PI
);
/* Get offset inside quadrant */
x
=
x
-
quadrant
*
(
M_PI
/
2
.);
/* Normalize quadrant to [0..3] */
quadrant
=
quadrant
&
0x3
;
/* Fixup value for the generic function */
x
+=
cos_off_tbl
[
quadrant
];
/* Calculate the negative of the square of x */
x2
=
-
(
x
*
x
);
/* This is an unrolled taylor series using <PRECISION> iterations
* Example with 4 iterations:
* result = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8!
* To save multiplications and to keep the precision high, it's performed
* like this:
* result = 1 - x^2 * (1/2! - x^2 * (1/4! - x^2 * (1/6! - x^2 * (1/8!))))
*/
/* Start with 0, compiler will optimize this away */
result
=
0
;
#if (PRECISION >= 10)
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
*
7
*
8
*
9
*
10
*
11
*
12
*
13
*
14
*
15
*
16
*
17
*
18
*
19
*
20
);
result
*=
x2
;
#endif
#if (PRECISION >= 9)
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
*
7
*
8
*
9
*
10
*
11
*
12
*
13
*
14
*
15
*
16
*
17
*
18
);
result
*=
x2
;
#endif
#if (PRECISION >= 8)
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
*
7
*
8
*
9
*
10
*
11
*
12
*
13
*
14
*
15
*
16
);
result
*=
x2
;
#endif
#if (PRECISION >= 7)
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
*
7
*
8
*
9
*
10
*
11
*
12
*
13
*
14
);
result
*=
x2
;
#endif
#if (PRECISION >= 6)
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
*
7
*
8
*
9
*
10
*
11
*
12
);
result
*=
x2
;
#endif
#if (PRECISION >= 5)
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
*
7
*
8
*
9
*
10
);
result
*=
x2
;
#endif
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
*
7
*
8
);
result
*=
x2
;
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
*
5
*
6
);
result
*=
x2
;
result
+=
1
.
/
(
1
.
*
2
*
3
*
4
);
result
*=
x2
;
result
+=
1
.
/
(
1
.
*
2
);
result
*=
x2
;
result
+=
1
;
/* Apply correct sign */
result
*=
cos_sign_tbl
[
quadrant
];
return
result
;
}
static
const
int
N
=
100
;
double
coef
(
int
n
)
{
double
t
;
if
(
n
==
0
)
{
return
0
;
}
t
=
1
.
0
/
n
;
if
(
n
%
2
==
0
)
{
t
=
-
t
;
}
return
t
;
}
double
horner
(
double
x
)
{
double
u
=
coef
(
N
);
int
i
;
for
(
i
=
N
-
1
;
i
>=
0
;
i
--
)
{
u
=
u
*
x
+
coef
(
i
);
}
return
u
;
}
double
sqrt
(
double
b
)
{
double
x
=
1
;
int
step
=
0
;
while
((
x
*
x
-
b
<-
0
.
000000000000001
||
x
*
x
-
b
>
0
.
000000000000001
)
&&
step
<
50
)
{
x
=
(
b
/
x
+
x
)
/
2
.
0
;
step
++
;
}
return
x
;
}
double
ln
(
double
x
)
{
int
i
;
if
(
x
>
1
.
5
)
{
for
(
i
=
0
;
x
>
1
.
25
;
i
++
)
{
x
=
sqrt
(
x
);
}
return
(
1
<<
i
)
*
horner
(
x
-
1
);
}
else
if
(
x
<
0
.
7
&&
x
>
0
)
{
for
(
i
=
0
;
x
<
0
.
7
;
i
++
)
{
x
=
sqrt
(
x
);
}
return
(
1
<<
i
)
*
horner
(
x
-
1
);
}
else
if
(
x
>
0
)
{
return
horner
(
x
-
1
);
}
}
double
exp
(
double
x
)
{
double
sum
=
1
;
int
i
;
for
(
i
=
N
;
i
>
0
;
i
--
)
{
sum
/=
i
;
sum
*=
x
;
sum
+=
1
;
}
return
sum
;
}
double
pow
(
double
m
,
double
n
)
{
return
exp
(
n
*
ln
(
m
));
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录