Här skall vi kika på hur man skulle kunna konvertera vårt projekt mot labbdatorn MD407.
MyMath.h
#ifndef MYMATH_H
#define MYMATH_H
#define RAND_MAX 32767
static unsigned int next = 1;
static inline unsigned int rand(void)
{
next = next * 1103515245 + 12345;
return (unsigned int)(next/65536) % 32768;
}
static inline void srand(unsigned int seed) { next = seed; }
static inline int strlen(const char* str)
{
const char *s;
for (s = str; *s; s++)
;
return (s - str);
}
static inline float fabs(float v) { return (v >= 0) ? v : -v; }
static inline float floor(float v) { return (int)v; }
static inline float fmod(float x, float y)
{
float i, f;
if (y == 0.0)
return 0.0;
i = floor(x/y);
f = x - i*y;
if ((x < 0.0) != (y < 0.0))
f = f-y;
return f;
}
static inline float sqrt(float x){
float xhalf = 0.5f * x;
int i = *(int*)&x; // store floating-point bits in integer
i = 0x5f3759df - (i >> 1); // initial guess for Newton's method
x = *(float*)&i; // convert new bits into float
x = x*(1.5f - xhalf*x*x); // One round of Newton's method
return 1.0f/x;
}
#endif // MYMATH_H
|