60 lines
812 B
C
Executable File
60 lines
812 B
C
Executable File
#include "hwo/fixpoint.h"
|
|
|
|
uint8_t _fp_buffer[32];
|
|
|
|
fixpoint_t fp_atan(fixpoint_t tan)
|
|
{
|
|
// TODO: Implement fp_atan() function, not needed for the moment.
|
|
return 0;
|
|
};
|
|
|
|
|
|
uint8_t* fp_toa(fixpoint_t value,int pre,int dec)
|
|
{
|
|
return fp_toa_r(_fp_buffer,value,pre,dec);
|
|
};
|
|
|
|
uint8_t* fp_toa_r(uint8_t* buffer,fixpoint_t value,int pre,int dec)
|
|
{
|
|
int v;
|
|
fixpoint_t d = fp_make(10000);
|
|
int i,di = 0;
|
|
uint8_t* p = buffer;
|
|
|
|
if (value & 0x80000000)
|
|
{
|
|
*(p++) = '-';
|
|
value = 0 - value;
|
|
} else
|
|
*(p++) = ' ';
|
|
|
|
for (i = 0;i<(5+dec);i++)
|
|
{
|
|
if (i == 5)
|
|
*(p++) = ',';
|
|
|
|
v = value / d;
|
|
value %= d;
|
|
di += v;
|
|
|
|
if (i >= (5-pre))
|
|
{
|
|
if (
|
|
(v != 0) ||
|
|
(di != 0) ||
|
|
(i >= 4)
|
|
)
|
|
*(p++) = (0x30 + v);
|
|
else
|
|
*(p++) = ' ';
|
|
};
|
|
|
|
d /= 10;
|
|
};
|
|
|
|
*p = 0x00;
|
|
|
|
return buffer;
|
|
};
|
|
|