|
/****************************************************************************/
/* */
/* 数学函数库测试 基本运算 */
/* */
/* 2014年09月03日 */
/* */
/****************************************************************************/
// 注意:sp 后缀的函数是单精度浮点运算
// dp 后缀的函数是双精度浮点运算
// 部分函数并没有默认被编译到库中
// Mathlib 跟 FastRTS 的主要区别是 Mathlib 是浮点运算对浮点 DSP 指令优化
// FastRTS 是浮点运算对定点 DSP 指令优化
#include <stdio.h> // C 语言标准输入输出函数库
#include <math.h> // C 数学函数库
#include <mathf.h> // C 数学函数库 浮点
#include "mathlib.h" // DSP 数学函数库
/****************************************************************************/
/* */
/* 宏定义 */
/* */
/****************************************************************************/
// 软件断点
#define SW_BREAKPOINT asm(" SWBP 0 ");
/****************************************************************************/
/* */
/* 全局变量 */
/* */
/****************************************************************************/
/****************************************************************************/
/* */
/* 函数声明 */
/* */
/****************************************************************************/
/****************************************************************************/
/* */
/* 主函数 */
/* */
/****************************************************************************/
int main(void)
{
printf("\n");
// 除法
printf("除法 单精度 2/3 = %f / 3/2 = %f \n", divsp(2, 3), divsp(3, 2));
printf("除法 双精度 2/3 = %f / 3/2 = %f \n", divsp(2, 3), divsp(3, 2));
// 返回小于或者等于指定表达式的最大整数
printf("返回小于或者等于指定表达式的最大整数 RTS 库 %f \n", floorf(1.5));
// 返回大于或者等于指定表达式的最小整数
printf("返回大于或者等于指定表达式的最小整数 RTS 库 %f \n", ceilf(1.5));
// 绝对值
printf("绝对值 RTS 库 1.5 %f / -1.5 %f \n", fabsf(1.5), fabsf(-1.5));
// 余数
printf("余数 RTS 库 4.5 %% 3 %f \n", fmodf(4.5, 3));
// 幂
printf("幂 单精度 2^3 = %f / 2^1.5 = %f \n", powsp(2, 3), powsp(2, 1.5));
printf("幂 双精度 2^3 = %f / 2^1.5 = %f \n", powdp(2, 3), powdp(2, 1.5));
printf("幂 RTS 库 2^3 = %f / 2^1.5 = %f \n", powf(2, 3), powf(2, 1.5));
// 倒数
printf("倒数 单精度 0.5 %f \n", recipsp(0.5));
printf("倒数 双精度 0.5 %f \n", recipsp(0.5));
// 开方
printf("开方 单精度 3^2 + 4^2 %f \n", sqrtsp(3 * 3 + 4 *4));
printf("开方 双精度 3^2 + 4^2 %f \n", sqrtdp(3 * 3 + 4 *4));
printf("开方 RTS 库 3^2 + 4^2 %f \n", sqrtf(3 * 3 + 4 *4));
// 开方 倒数
printf("开方 倒数 单精度 3^2 + 4^2 %f \n", rsqrtsp(3 * 3 + 4 *4));
printf("开方 倒数 双精度 3^2 + 4^2 %f \n", rsqrtdp(3 * 3 + 4 *4));
// 对数
printf("对数 以2为底 单精度 4 %f \n", log2sp(4));
printf("对数 以2为底 双精度 4 %f \n", log2dp(4));
printf("对数 以2为底 RTS 库 4 %f \n", log2f(4));
printf("对数 以e为底 单精度 e^2 %f \n", logsp(2.71828 * 2.71828));
printf("对数 以e为底 双精度 e^2 %f \n", logdp(2.71828 * 2.71828));
printf("对数 以10为底 单精度 100 %f \n", log10sp(100));
printf("对数 以10为底 双精度 100 %f \n", log10dp(100));
printf("对数 以10为底 RTS 库 100 %f \n", log10f(100));
// 指数
printf("指数 以2为底 单精度 4 %f \n", exp2sp(4));
printf("指数 以2为底 双精度 4 %f \n", exp2dp(4));
printf("指数 以2为底 RTS 库 4 %f \n", exp2f(4));
printf("指数 以e为底 单精度 4 %f \n", expsp(2));
printf("指数 以e为底 双精度 4 %f \n", expdp(2));
printf("指数 以10为底 单精度 4 %f \n", exp10sp(4));
printf("指数 以10为底 双精度 4 %f \n", exp10dp(4));
printf("指数 以10为底 RTS 库 4 %f \n", exp10f(4));
// 三角函数 参数弧度
// π = 6arcsin(1/2)
printf("正弦 单精度 sin(π/6) %f \n", sinsp(6 * asin(0.5) / 6));
printf("正弦 双精度 sin(π/6) %f \n", sindp(6 * asin(0.5) / 6));
printf("正弦 RTS 库 sin(π/6) %f \n", sinf(6 * asin(0.5) / 6));
printf("余弦 单精度 cos(π/3) %f \n", cossp(6 * asin(0.5) / 3));
printf("余弦 双精度 cos(π/3) %f \n", cosdp(6 * asin(0.5) / 3));
printf("余弦 RTS 库 cos(π/3) %f \n", cosf(6 * asin(0.5) / 3));
printf("正切 RTS 库 tan(π/4) %f \n", tanf(6 * asin(0.5) / 4));
// 双曲函数 参数弧度
// π = 6arcsin(1/2)
printf("双曲函数 单精度 恒等式 cosh(x)^2 - sinh(x)^2 = 1 %f \n", pow(coshf(6 * asin(0.5) / 6), 2) - pow(sinhf(6 * asin(0.5) / 6), 2));
printf("注意:部分函数并没有默认被编译到数学函数库");
// 断点
SW_BREAKPOINT;
}
|
|