# FLOATING Point Math for PICMicro

Status
Not open for further replies.

#### isabelino

##### Member level 1
Please: I need routines about cosine and sine , on Picbasic or PICC compiler. I need precision , more than 32bit floating point, because I need to calculate seconds. I working on Pic18F452 micro
Thanks .

#### Regnum

##### Full Member level 5
All the functions I've seen are 32-bit... maybe you should code it by yourself
Make a search for CORDIC algorithms

Regards.

#### isabelino

##### Member level 1
Please: I need routines about cosine and sine , on Picbasic or PICC compiler. I need precision , more than 32bit floating point, because I need to calculate seconds. I working on Pic18F452 micro . Cordic is good, but not is a solution because I need to calculate seconds.

#### SphinX

Salam,

You can use these codes with PICC with some modification.

Code:
////////////////////////////// Trig Functions //////////////////////////////
#undef PI_DIV_BY_TWO
#define PI_DIV_BY_TWO	1.570796326794896
#undef TWOBYPI
#define TWOBYPI 			0.6366197724
/////////////////////////////////////////////////////////////////////////////

Code:
////////////////////////////////////////////////////////////////////////////
//	float cos(float x)
////////////////////////////////////////////////////////////////////////////
// Description : returns the cosine value of the angle x, which is in radian
// Date : 9/20/2001
//
float cos(float x)
{
float y, t, t2 = 1.0;
float frac;
float p[4] = {
-0.499999993585,
0.041666636258,
-0.0013888361399,
0.00002476016134
};

if (x < 0) x = -x;                  // absolute value of input

frac = (x / PI_DIV_BY_TWO) - quad;  // fractional part of input

t = frac * PI_DIV_BY_TWO;
t = (1-frac) * PI_DIV_BY_TWO;
else // should be 3
t = (frac-1) * PI_DIV_BY_TWO;

y = 0.999999999781;
t = t * t;
for (i = 0; i <= 3; i++)
{
t2 = t2 * t;
y = y + p[i] * t2;
}

y = -y;  // correct sign

return (y);
}

and

Code:
////////////////////////////////////////////////////////////////////////////
//	float sin(float x)
////////////////////////////////////////////////////////////////////////////
// Description : returns the sine value of the angle x, which is in radian
// Date : 9/20/2001
//
float sin(float x)
{
return cos(x - PI_DIV_BY_TWO);
}

Bye

#### Fragrance

hi

here is code but you have to inculde in your code

Status
Not open for further replies.