示例#1
0
int norm(int type,Float& y)
{ // convert y to 1st quadrant angle, and return sign
    int s=PLUS;
    Float pi,w,t;
    if (y.sign()<0)
    {
        y.negate();
        if (type!=COS) s=-s;
    }
    pi=fpi();
    w=pi/2;
    if (fcomp(y,w)<=0) return s;
    w=2*pi;
    if (fcomp(y,w)>0)
    { // reduce mod 2.pi
        t=y/w;
        t=trunc(t);
        t*=w;
        y-=t;
    }
    if (fcomp(y,pi)>0) 
    {
        y-=pi;
        if (type!=TAN) s=(-s);
    }
    w=pi/2;
    if (fcomp(y,w)>0)
    {
        y=pi-y;
        if (type!=SIN) s=(-s);
    }
    return s;
}
示例#2
0
int fcomp(const Float& a,const Float& b)
{
    Big x,y;
    int sa,sb;

    sa=a.sign();
    sb=b.sign();

    if (sa>sb) return 1;
    if (sa<sb) return -1;
    if (sa==0 && sb==0) return 0;

    if (a.e>b.e) return sa;
    if (a.e<b.e) return -sa;
    x=a.m; y=b.m;

    x.shift(precision-length(x));  // make them precision length
    y.shift(precision-length(y));

    if (x>y) return 1;
    if (x<y) return -1;

    return 0;
}