It is a long-established best practice in function approximation by polynomials (and rational functions) to use minimax approximations which are optimal under the infinity norm.
Thanks for the advises, I have never worked in function approximation so they are really useful. Could you pass me (if it does not involve much work) the coefficients for the degree 6 polynomial for the cospi function? I have the following values:
// cos(pi*x) polynomial approximation for x in [-0.5,0.5]
half2 x2 = __hmul2(x, x);
half2 c = __float2half2_rn(-1.229339658587166);
c = __hfma2(x2, c, __float2half2_rn(+4.043619929856572f));
c = __hfma2(x2, c, __float2half2_rn(-4.934120365987677f));
c = __hfma2(x2, c, __float2half2_rn(+0.999995282317910));
but they do not have into account the 16-bit precision. I will not need more custom functions, so implementing the optimization algorithm on my own is a bit out of reach at this time.
Thanks in advance, I hope it does not involve too much work for you if you already have the optimization program. If it does, do not worry about it, the least-squares approximation works quite fine for my application.
My program says the mimimax approximation to cospi() on [-0.5,0.5] has the following coefficients
-0.9700234895824713
+3.9169476808775876
-4.9166376735951411
+0.9995068053686622
Note that this doesn’t account for limited precision for storing the coefficients and during evaluation. That would require additional tweaks. The fpminimax command of the free Sollya tool accounts for the storage limitations but not the limited precision in the arithmetic operators.
Thank you very much! By the way, I have to write a paper about how my whole library works, do you know if there is any paper I must cite about all this stuff? I have been reading this one [1508.03211] Computing accurate Horner form approximations to special functions in finite precision arithmetic by T. Myklebust. Is there any paper (or something similar) of yours that I should cite to recognise your work?
The general rule of citations is that you cite material that you actually used in your work. Beyond citing published works, there is long-standing tradition of citing “personal communication with [person]”, and more recently citing online sources ([URL], [date retrieved]) has become acceptable in most if not all fields.
The way I have previously been credited by paper writers for assistance provided in these forums was by having my name included in the “Acknowledgements” sections of their paper. Authors have referred to me either by my user name here and on Stackoverflow (njuffa) or by my real name (Norbert Juffa) if they were aware of it.
If I recall correctly, I haven’t been a co-author on any publication for twenty years or so.