I’ve looked around in the new code and compiler docs and such and IO have yet to see any mention of new math libraries, or math libraries at all.

Any hints on where the math libraries are and any documentation?

I’ve looked around in the new code and compiler docs and such and IO have yet to see any mention of new math libraries, or math libraries at all.

Any hints on where the math libraries are and any documentation?

They’re in the /h folder of the new compiler. There’s a very nice math.h file, as well as an stdio.h file. Now I don’t have to use my Maclauren approximations for trig functions!

What functions are they? Do they take Int16 inputs/outputs? It would make a lot of the calculations for autonomous navigation easier if we don’t have to roll our own trig functions.

Joe J.

They are (straight from math.h):

float fabs (float x); (absolute value)

float ldexp (float x, int n); (computes x*2^n)

float exp (float f); (e^f)

float sqrt (float x);

float asin (float x);

float acos (float x);

float atan2 (float y, float x);

float atan (float x);

float sin (float x);

float cos (float x);

float tan (float x);

float sinh (float x);

float cosh (float x);

float tanh (float x);

float frexp (float x, int *pexp); (splits into the fractional part of a float, which is returned, and the exponent which is stored in the pointer)

float log10 (float x);

float log (float x);

float pow (float x, float y);

float ceil (float x);

float floor (float x);

float modf (float x, float *ipart); (performs the modulus function on x, returns the result and stores the fraction in the pointer. Look in the manual for more explanation)

float fmod (float x, float y); (the remainder for x%y)

unsigned long ieeetomchp (float v); (mchptoieee in reverse)

Unfortunately, thay all take floating point inputs and return floats. Its not hard to typecast though. And I, myself, am glad to have a math.h library at my disposal rather than using my own functions, even if it is for 32-bit floats.

If you’ve already installed the compiler, the manual should be in c:\mcc18\docs\ (or whatever-your-install-directory-is\docs). It has plenty of documentation available. There are also many functions to access deeper features of the chip that took some tricky coding before.

-Tony K

Quick question: I looked up the difference between *cos* and *cosh* and it says that *cosh* was the hyperbolic cosine. What is a hyperbolic cosine and when would it be helpful to use it? (wow i think I’ve ended every post I’ve done here with a confused face…)

http://math.jccc.net:8180/webMathematica/MSP/mmartin/cosh

http://www.omatrix.com/manual/cosh.htm

It involves some calc, see if you can figure it out with that link.

**“This page cannot be displayed”**

For any team reluctant to use the floating-point trig functions in the provided math library (floating-point math is extremely slow because it’s simulated by the compiler), there are some quicker integer-math trig libraries available, this being one of them.

The hyperbolic cosine cosh(*x*) = (e^*x* + e^-*x*)/2

It is very useful when evaluating certain integrals, but not really used outside of advanced calculus. A good description is here.