Quote:
If I find some routines for trigonometric functions, they may be added.
Trouble is, currently Atalan supports just integers (no floating point numbers), so this would be of limited use directly.
Floating-point is not needed nearly as much as we all initially tend to think. Scaled-integer math is far more efficient and works fine for trig, log, square-root, and other functions. I started a topic on it
here (really more of a series of articles that people could comment on and ask questions since it's a forum) but like so many other projects, I never finished it.
For 16-bit precision, sin & cos can be calculated accurately with just use the first four terms of the infinite series, with the coefficients tweaked slightly to compensate for the fact that you're not using more terms. You just calculate them for the first 45°, and from that you can get the rest of the circle. The output will usually be accurate to all 16 bits, and the worst error I've found in my testing is 1 lsb high. For scaling, the input angle is represented by $10000 being the whole circle, so for example 90° is 4000H, 45° is $2000, 1 radian is $28BE etc., giving you .0055° resolution, and the wrap-around is perfect (ie, 359°+2°=1° and so on). The output of -1 to +1 is scaled by $7FFF if you want maximum resolution, giving a range of -$7FFF to +$7FFF so the granularity is .0000305 if you're stopping at 16 bits.
For TAN, you just return both SIN and COS since otherwise you have the problem that TAN has this nasty habit of going to ±infinity at ±90°.
Arctan can be interpolated accurately from a surprisingly small table. It works much better than X(1+BX²)/(1+CX²)-DX^^6, not to mention the infinite series which does not converge anywhere nearly as quickly as it does for sin & cos! A table of 16 16-bit numbers, with linear interpolation, gives a maximum error of <.02° if the table entries are tweaked slighly to minimize the maximum error instead of just putting in the straight arctan's. Doubling the size of the table makes the accuracy skyrocket. Without digging up my notes, I can't remember if it makes it four times or eight times as accurate, but the point is that you don't need a big table. Again, you start with just the first 45°, and get the rest from that. Resolution is about .007° worst case (near 0°). This again is if you're stopping at 16 bits of scaled-integer representation.
Logs and antilogs can be interpolated from relatively small tables too if you do them in base 2 (not e, not 10, etc.) and convert from there.
Of course if you have a couple of megabytes for big tables, you can have all the values pre-calculated and just look them up quickly and get every last bit accurate. I have these tables calculated and sitting in Intel hex files but have not used them yet. [
Edit, June 2012: They are now published at
http://WilsonMinesCo.com/16bitMathTables/index.html ]
Obviously I did not mention all the functions, but the above should be convincing enough that lack of floating-point is hardly a handicap. Floating-point burdens the processor with the job of keeping track of the decimal point during run time. Fixed-point and scaled-integer math puts the burden on the programmer during programming time (which isn't as bad as it sounds, you'll find with experience) and lets the computer be much more efficent at run time.