This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Trigonometric functions
- From: Mischa Baars <mjbaars1977 at gmail dot com>
- To: libc-alpha at sourceware dot org
- Date: Thu, 10 Jan 2013 05:30:34 +0100
- Subject: Re: Trigonometric functions
- References: <5cca9c63.dd7d.13b3d54bf37.Coremail.luo_huan_na@126.com> <50B3CFE8.1020803@cyberfiber.org> <50ED6BFB.2080604@cyberfiber.org>
It seems I forgot just this one file, one can now tell for certain that
the functions sine and cosine can indeed be used for rotation and
scaling on the complex plane.
Good luck!
Mischa.
On 01/09/2013 02:09 PM, Mischa Baars wrote:
Hi all,
Thank you for the 2.17 distribution, which is finally compilable
without any problems. People are now better able to help you!
I have attached two files.
The first example was one already placed on the mailing list earlier,
now again with a few typing errors corrected.
The second example compensates for the hardware errors as indicated in
the first example.
However, only three of the trigonometric functions are included, i.e.
the ones used in rotations in the two-dimensional or complex plane.
Should you need any other function, than I hope this example will be
helpful enough to get you started.
For processors without transcendental instruction set, I'm currently
working on an improvement of the functions already included in the
glibc distribution. I will get back to this.
I will be happy to answer any of your questions.
Regards,
Mischa.
#include <stdlib.h>
#include <stdio.h>
#include <cpu_types.h>
#include <npx_types.h>
// external declaration
extern sr11 npx_sr11_sine(sr11 a); // a in [ -1, +1 ]
extern dr11 npx_dr11_sine(dr11 a);
extern er11 npx_er11_sine(er11 a);
extern sr11 npx_sr11_cosine(sr11 a); // a in [ -1, +1 ]
extern dr11 npx_dr11_cosine(dr11 a);
extern er11 npx_er11_cosine(er11 a);
// internal alias
#define sins(a) npx_sr11_sine(a)
#define sind(a) npx_dr11_sine(a)
#define sine(a) npx_er11_sine(a)
#define coss(a) npx_sr11_cosine(a)
#define cosd(a) npx_dr11_cosine(a)
#define cose(a) npx_er11_cosine(a)
int main()
{
qz11 i;
qz11 n = 4 * 3 + 1; // four quadrants each in three segments
sr11 x0, y0, a0, r0;
dr11 x1, y1, a1, r1;
er11 x2, y2, a2, r2;
printf("computing: r^2 = cos(a)^2 + sin(a)^2, a in fraction of [ -pi, +pi ]\n");
printf("\n");
for (i = -1; i < (n + 1); i++)
{
a0 = (sr11) (2 * i) / (n - 1) - 1;
a1 = (dr11) (2 * i) / (n - 1) - 1;
a2 = (er11) (2 * i) / (n - 1) - 1;
x0 = coss(a0);
x1 = cosd(a1);
x2 = cose(a2);
y0 = sins(a0);
y1 = sind(a1);
y2 = sine(a2);
r0 = x0 * x0 + y0 * y0;
r1 = x1 * x1 + y1 * y1;
r2 = x2 * x2 + y2 * y2;
printf("%0+5d: [ a .. a | x .. x | y .. y | r .. r ]: [ %+11.4e %+11.4le %+11.4Le | %+11.4e %+11.4le %+11.4Le | %+11.4e %+11.4le %+11.4Le | %+11.4e %+11.4le %+11.4Le ]\n",
i, a0, a1, a2, x0, x1, x2, y0, y1, y2, r0, r1, r2);
}
printf("\n");
return EXIT_SUCCESS;
}