View Single Post
Old 18 April 2015, 03:54   #27
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,797
Quote:
Originally Posted by cla View Post
But since the last public available m68k version of GCC is 2.95.3 which (for good reasons) does not support c99 math I don't see how it is possible. The only solution to the c99 problem would be either some kind of hack or to buy a commercial product like StormC4, and then people wont be able to build the application themselves anyway.
A better solution than C99 math is to use a library which is portable, offers more precision and more functions than C99. One example is Mapm, which does arbitrary precision floating point math. It's quite slow, however. Another is Cephes, which has a large number of functions, and offers numerous fixed precision sizes, up to 384 bit. This is much faster than Mapm for, say, 100 decimal digits of precision (Cephes uses base 2, Mapm uses base 100). Cephes is also extremely easy to use (Mapm is more involved). Beware of it's sloooooooow factorial function, though. The gamma function is much faster (I use a table).

Both of these are extremely portable, and compile properly with SASC 6.58. Cephes is quite old, though, and has some pre-C89 crud in it (old style function prototypes which SASC doesn't like). It's also very easy to use only a subset of the Cephes files, and not compile the complete libraries.

I'm currently using Cephes' 384 bit floats with Lua 5.3.0, and it works great.

Cephes: https://github.com/jeremybarnes/cephes

Another alternative is to simply implement the math functions that are in C99 but that are missing in C89 yourself. For example, log2(x) is as easy as doing log(x) / log(2), where you can make log(2) a constant (you do log for any base by doing log(x) / log(base)).

Another example is acosh. You can do that by doing log(x + (x ^ 2 - 1) ^ 0.5).

Most of these will be very easy, and can be easily found by googling. Try googling 'mathworks asinh' to get the formula for asinh.

For a calculator there is absolutely no need to be stuck with C99 if you don't truly need it

Last edited by Thorham; 18 April 2015 at 04:07.
Thorham is offline  
 
Page generated in 0.04445 seconds with 11 queries