Thread: math.h library
View Single Post
  #14   Spotlight this post!  
Unread 26-12-2003, 14:41
Joshua Lynn Joshua Lynn is offline
Registered User
FRC #0423 (SEC Mechanical Mayhem)
Team Role: Engineer
 
Join Date: Jan 2003
Rookie Year: 1999
Location: Elkins Park, PA
Posts: 16
Joshua Lynn is on a distinguished road
Re: math.h library

I am currently working on a math library for trig functions and a few other floating point operations like floor, ceiling, and sqrt. I hope to have them available by Jan 10.

These functions are based on other open source numerical methods. The trick is the need to be converted from their double data type operations to float data type in the format used by the PIC which is not IEEE 754.

The solutions are all based on various forms of approximation.

For those who want to try it themselves here is an iterative way to calculate the sqrt:

y=sqrt(x)

y0 = x/2
y1 = (y0 + x/y0)/2
yn = (yn + x/yn-1)/2

Iterate through the solution n times until you have the desired level of precision. For low values of x the convergence is good for n=10. For larger values the first guess should be adjusted to reflect the order of magnitude of x. If x =10^6 start with an initial value 10^3 or (Order of Magnitude)/2. The closer the first division is to the answer the sooner the number will converge.

So far I have worked out
SQRT
SIN
COS
TAN
SEC
CSC
COT
Floor
Ceiling
ABS

I will have at least one of the following trig functions
ATAN
ASIN
ACOS

I may be able to get them all but I have a bit more research to do.

Additionally, I have found other methods to calculate
ln
Log
MOD
x^y --Used for larger values of y it is more efficient

Stay tuned for more.