Blade Math Lib数学库

BBase.cpp基础函数文件内容

#include "BMath2.h"
const char*	GetVerID()
{
	return "2.0";
}

B_FLOAT       GetRandom()
{
    // 0-1
	B_FLOAT v = sin(B_FLOAT(clock()));

	if(v<0.000000f)
		v+=1.0f;

	return v;

}

long GetTime()
{
	return clock();
}

B_FLOAT BSqrt(B_FLOAT a)
{
    return sqrt(a);
}

B_FLOAT BPower(B_FLOAT a,int n)
{
	B_FLOAT t = 1.000000f;

	while(n>0)
	{
		t = t*a;
		n--;
	}

	return t;
}

B_FLOAT* BAdd4(B_FLOAT* d,B_FLOAT* a,B_FLOAT* b)
{
    d[0] = a[0] + b[0] ;
    d[1] = a[1] + b[1] ;
    d[2] = a[2] + b[2] ;
    d[3] = a[3] + b[3] ;
	return d;
}

B_FLOAT* BSub4(B_FLOAT* d,B_FLOAT* a,B_FLOAT* b)
{
	d[0] = a[0] - b[0] ;
    d[1] = a[1] - b[1] ;
    d[2] = a[2] - b[2] ;
    d[3] = a[3] - b[3] ;
	return d;
}

B_FLOAT* BMul4(B_FLOAT* d,B_FLOAT* a,B_FLOAT b)
{
	d[0] = a[0] * b ;
    d[1] = a[1] * b ;
    d[2] = a[2] * b ;
    d[3] = a[3] * b ;
	return d;
}

B_FLOAT* BDiv4(B_FLOAT* d,B_FLOAT* a,B_FLOAT b)
{
	d[0] = a[0] / b ;
    d[1] = a[1] / b ;
    d[2] = a[2] / b ;
    d[3] = a[3] / b ;
	return d;
}

B_FLOAT* BSqrt4(B_FLOAT* d,B_FLOAT* a)
{
	d[0] = sqrt(a[0]);
	d[1] = sqrt(a[1]);
	d[2] = sqrt(a[2]);
	d[3] = sqrt(a[3]);

	return d;
}

B_FLOAT		BSin(B_FLOAT val)
{
	return sin(val);
}

B_FLOAT		BCos(B_FLOAT val)
{
	return cos(val);
}

B_FLOAT BRound(B_FLOAT v)
{
	double i=0;

	B_FLOAT c = modf(v*10,&i);

	if(c>=0.5f)
		v = floor(v*10.0f)+1.0f;
	else
		v = floor(v*10.0f);

	return v/10.0f;
}
滚动到顶部