The lack of decent floating point support seems to be a major shortcoming with the PIC programming tools. Last year I posted a query on this listserver, which resulted in an email reply from Microchip. (My answer is reprinted below, although they weren't able to help me at the time). I expect that the PIC is (or could be) often used to control an LCD with a readout of acquired analog measurements. The raw values read would be translated into user units by some algorithm(s) involving at least the 4 basic math functions and possible some transcendental functions as well, such as log, sine, square root, etc. App note AN575 seems to cover the basic math functions (although I've seen at least one posting questioning their accuracy, and I noticed a problem with an early version of the library with multiplication in certain numeric ranges). However at the moment there seems to be no support for the transcendental functions. I have an older version of the CCS C compiler which I like using (except for this problem) -- does anyone know if their latest version supports the FLOAT data type and math.h? Also I read here that the Avocet C compiler supports f/p; anyone have any experience with that? In the meantime I've been searching for ways to handle f/p on my own; one interesting (although older) reference from 1974 is _Floating Point Computation_ by Pat Sterbenz of the IBM Systems Research Institute. It doesn't give algorithms, but does cover a number of issues to be considered such as rounding, bias, common mistakes leading to loss of precision, etc. A more immediately useful book is _Scientific Analysis on the Pocket Calculator_ by Jon Smith (Software Research Corporation); John Wiley & Sons, 1975. Back then scientific calculators were pricey, and the book includes procedures for the 4-function calculator. The author covers a number of methods arranged such as series expansion chosen for rapid convergence and arranged for convenience on a caluculator in nested form: tan(x) = x(1+x*x/3(1+6*x*x/15(1+255*x*x/630))) He also gives polynomial equations such as tax(x) = x(1+x*x(a2+x*x(a4+x*x(a6+x*x(a8+x*x(a10+a12*x*x)))))) where a2 = 0.3333314036, a4 = 0.1333923995, etc. For optimizing the polynomial approach the book covers Chebyshev polynomials which have useful properties for this application including minimizing both error and computation steps. Does anyone know of a similar reference that could be optimized for the PIC? I don't expect to do floating point on a 16C57, but the 14-bit core family at least should have the computing resources. If the full-blown C function printf() is unfeasible at least there should be ecvt(), fcvt() and gcvt() or equivalents. Regards, Doug Manzer +------------------------- Copy of email sent to Microchip: +------------------------- My own immediate needs are these: 1. Some way to convert a binary f/p number (in your modified IEEE format) to readable message text for display on an LCD in floating point decimal. The typical use would be to acquire an a/d reading, processes it through some mathematical functions and then write the result to an LCD with layout like this (with all elements turned on): 8.8.8.8. Doing this with fixed point math is only feasible where the ranges of values are known in advance. However, my client at the moment expects to plug in various instruments into a base unit; the formulas and calibration constants for each sensor are arbitrary. For instance, the calculation for temperature involves a 3rd order polynomial; humidity requires a 5th order polynomial and a natural log calculation. Lookup tables would be difficult as there are at least 4 variables involved. It would be ideal to have some function such as printf() or sprintf(), or even some of the primitives for these functions. Obviously there's not enough room in the PIC's code space for the full sprintf(). Short of that, I think many developers working with floating point could use a function to convert a binary floating point number into decimal floating point with a format such as a BCD string plus a signed exponent, ie. a form of engineering notation. The exponent would be used to locate the decimal point somewhere in the LCD string. I started out with this on my own, taking the approach that for example 111.111 binary = 4 + 2 + 1 + 0.5 + 0.25 + 0.125. My algorithm would start at the decimal point and calculate (or look up) each power of two expressed as a BCD string and add it to a running total if the bit was 1 in that position. (I would have to do this in each direction if the number straddled the decimal point). However, I don't know if this is the most efficient method, and would appreciate your ideas on this. 2. Natural logarithm as well as other common transcendental functions such as sin() etc. It's been a while since I worked with evaluating a power series numerically, and none of the books at local libraries are much help. Unfortunately, both of the prominent C compilers for the PIC (CCS and Bytecraft's MPC) don't support a float data type or offer anything like math.lib. They're also lacking a way to format output such as sprintf(). 3. Some way to convert the user's keyboard input into a f/p quantity. Typically this would be done on a host computer such as an IBM-PC running a utility written in Borland C; the user would enter calibration constants as a decimal floating point string. The "old" AN575 contained a C program for converting a decimal string into the modified f/p format but the new AN575 is missing this program. Someone at Microchip told me that it wasn't updated for some reason --- is it safe to use the logic from that orignal C program? Any help appreciated; +-------------------------