!!求C语言的 数学函数库源代码 可使用的分数范围是:0-14

[复制链接]
2805|4
 楼主| Periodic 发表于 2012-1-31 08:42 | 显示全部楼层 |阅读模式
数学函数库math.h
数学函数库math.C
potter 发表于 2012-1-31 10:02 | 显示全部楼层
才给14分啊,给个minilib 的 math.c 吧

#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
#define M_PI 3.141592653589793238462643
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;
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| Periodic 发表于 2012-1-31 19:14 | 显示全部楼层
本帖最后由 Periodic 于 2012-1-31 19:46 编辑

少了点  我只有这点分了:L

要是能找到 这个库的 源代码  就强悍了  IQmathLib.lib
yuxiang2008 发表于 2012-1-31 23:43 | 显示全部楼层
自己用google搜索下,不就知道了……
 楼主| Periodic 发表于 2012-2-17 10:34 | 显示全部楼层
google  百度 无结果
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

670

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部