[Mesa-dev] [PATCH] glsl: improve accuracy of atan()
Erik Faye-Lund
kusmabite at gmail.com
Mon Oct 6 08:03:49 PDT 2014
On Fri, Sep 26, 2014 at 6:11 PM, Erik Faye-Lund <kusmabite at gmail.com> wrote:
> Our current atan()-approximation is pretty inaccurate at 1.0, so
> let's try to improve the situation by doing a direct approximation
> without going through atan.
>
> This new implementation uses an 11th degree polynomial to approximate
> atan in the [-1..1] range, and the following identitiy to reduce the
> entire range to [-1..1]:
>
> atan(x) = 0.5 * pi * sign(x) - atan(1.0 / x)
>
> This range-reduction idea is taken from the paper "Fast computation
> of Arctangent Functions for Embedded Applications: A Comparative
> Analysis" (Ukil et al. 2011).
>
> The polynomial that approximates atan(x) is:
>
> x * 0.9999793128310355 - x^3 * 0.3326756418091246 +
> x^5 * 0.1938924977115610 - x^7 * 0.1173503194786851 +
> x^9 * 0.0536813784310406 - x^11 * 0.0121323213173444
>
> This polynomial was found with the following GNU Octave script:
>
> x = linspace(0, 1);
> y = atan(x);
> n = [1, 3, 5, 7, 9, 11];
> format long;
> polyfitc(x, y, n)
>
> The polyfitc function is not built-in, but too long to include here.
> It can be downloaded from the following URL:
>
> http://www.mathworks.com/matlabcentral/fileexchange/47851-constraint-polynomial-fit/content/polyfitc.m
>
> This fixes the following piglit test:
> shaders/glsl-const-folding-01
>
> Signed-off-by: Erik Faye-Lund <kusmabite at gmail.com>
> Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Ping?
More information about the mesa-dev
mailing list