To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 3269
3268  |  3270
Subject: 
math.h
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Tue, 6 May 2003 23:07:53 GMT
Viewed: 
2845 times
  
Hello all,

I've written some math usefull library ! here is my work. It's not
really optimized and I'm afraid cause I see the memory place down ...

If someone want help me ...

Have fun

nanobapt

/*test.c*/

#include <math.h>
#include <conio.h>

int main()
{
lcd_int(sin(PI)*1000);

return 0;
}

-----

/*math.h*/

#define PI 3.1415

/*
*puiss(2, 3) == 2^3
*/

extern float puiss(float nb, int deg);

/*
*factor(5) == 5!
*be aware taht the RCX can't calculate foctor like 20! :)
*/

extern int factor(int n);

/*
*Precision is not really good but enought for the RCX
*/

extern float sin(float x);
extern float cos(float x);

----
#include <math.h>

float puiss(float nb, int deg)
{
int i;
float total=1;

for(i=0; i<deg; i++)
{
total=total*nb;
}

return total;
}

int factor(int n)
{
int i;
int total=1;

for(i=1; i<=n; i++)
total=total*i;

return total;
}

float sin(float x)
{
int i;
float total=0;

for(i=0; i<3; i++)
total=total+( puiss(-1, i)*(puiss(x, 2*i+1)))/factor(2*i+1);


return total;
}

float cos(float x)
{
return (1-2*puiss(sin(x/2), 2));
}



Message has 1 Reply:
  Re: math.h
 
Oh note : you need to compile with -lfloat your kernel if you want to include it into kernel just add -lfloat to $LIBS in the Makefile.kernel nanobapt (21 years ago, 6-May-03, to lugnet.robotics.rcx.legos)

2 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR