I'm looking to submit a patch to the D programming language standard library that will allow much of std.math to be evaluated at compile time using the compile-time function evaluation facilities of the language. Compile-time function evaluation has several limitations, the most important ones being:
Several std.math functions violate these and compile-time versions need to be written. Where can I get information on good algorithms for computing things such as logarithms, exponents, powers, and trig functions? I prefer just high level descriptions of algorithms to actual code, for two reasons:
To avoid legal ambiguity and the need to make my code look "different enough" from the source to make sure I own the copyright.
I want simple, portable algorithms. I don't care about micro-optimization as long as they're at least asymptotically efficient.
Edit: D's compile time function evaluation model allows floating point results computed at compile time to differ from those computed at runtime anyhow, so I don't care if my compile-time algorithms don't give exactly the same result as the runtime version as long as they aren't less accurate to a practically significant extent.
C mathematical operations are a group of functions in the standard library of the C programming language implementing basic mathematical functions. All functions use floating-point numbers in one manner or another.
The math. h header defines various mathematical functions and one macro.
No. A function is a block of code in a computer program. An algorithm is an abstract concept that describes how to solve a problem. unfortunately there is no formal and precise definition of algorithm.
John Hart Computer Approximations 1968 by John Wiley & Sons.
The calculations ideally should match precisely what they would if done at runtime. That can be tricky. For many functions, no series converges quickly over the full domain, so algoritms paste together various methods.
Also, there are various floating point formats. Most platforms (I think) now use IEEE 754. When I wrote a compiler ca. 1985, I had to deal with cross-platform floating point formats. It was very tedious to get it right, because you have to piece the numbers together bit by bit, being sure that you get precisely the value that would be calculated on the target machine. I don't know if you have to deal with that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With