From: Jan-Benedict G. <jb...@us...> - 2005-11-09 23:24:30
|
Update of /cvsroot/linux-vax/toolchain/patches In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15355/patches Added Files: uclibc-000013-libm-1.patch Log Message: - Use our own libm instead of the IEEE one from uClibc. --- NEW FILE: uclibc-000013-libm-1.patch --- diff -Nupr src-uclibc-fresh/libm-vax/cos.c src-uclibc-hacked/libm-vax/cos.c --- src-uclibc-fresh/libm-vax/cos.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/cos.c 2005-11-09 23:09:38.000000000 +0100 @@ -0,0 +1,9 @@ + +extern long double cosl (long double x); + +double +cos (double x) +{ + return cosl (x); +} + diff -Nupr src-uclibc-fresh/libm-vax/cosf.c src-uclibc-hacked/libm-vax/cosf.c --- src-uclibc-fresh/libm-vax/cosf.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/cosf.c 2005-11-09 23:09:38.000000000 +0100 @@ -0,0 +1,9 @@ + +extern double cos (double x); + +float +cosf (float x) +{ + return cos (x); +} + diff -Nupr src-uclibc-fresh/libm-vax/cosl.c src-uclibc-hacked/libm-vax/cosl.c --- src-uclibc-fresh/libm-vax/cosl.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/cosl.c 2005-11-09 23:09:38.000000000 +0100 @@ -0,0 +1,55 @@ +/* http://en.wikipedia.org/wiki/Pi */ +#define __VAX_PI 3.14159265358979323846264338327950288419716939937510L + +static long double +taylor_cosl (long double x, int i) +{ + long double divisor = 1.0; + long double dividend = 1.0; + int n; + + for (n = 0; n < i; n++) { + divisor *= x; + dividend *= (n + 1); + } + + if (i % 4 == 2) + divisor *= -1.0; + + return divisor / dividend; +} + +long double +cosl (long double x) +{ + long double result = 0.0; + int n_pi; + int i; + + /* sin(-x) = -sin(x) */ + if (x < 0.0) + return cosl (-x); + + /* left-shift x to be in [0..2pi[ */ + n_pi = x / __VAX_PI; + if (n_pi >= 2) + x -= (n_pi/2*2) * __VAX_PI; + + /* [pi..2pi[ is negatively mapped to [0..pi[ */ + if (x >= __VAX_PI) + return -cosl (x - __VAX_PI); + + /* Mirror [pi/2..pi] -> [pi/2..0] */ + if (x >= __VAX_PI/2.0) + return -cosl (__VAX_PI - x); + + /* + * The remaining part which is not solved recursively is in + * the range of [0..pi/2] and will be approximated by a polynom. + */ + for (i = 0; i < 30; i += 2) + result += taylor_cosl (x, i); + + return result; +} + diff -Nupr src-uclibc-fresh/libm-vax/Makefile src-uclibc-hacked/libm-vax/Makefile --- src-uclibc-fresh/libm-vax/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/Makefile 2005-11-09 23:09:38.000000000 +0100 @@ -0,0 +1,22 @@ +TARGET=vax-linux-uclibc- +AR=$(TARGET)ar +CC=$(TARGET)gcc +CFLAGS= + +OBJ=sinl.o sin.o sinf.o cosl.o cos.o cosf.o + +all: libm.a test + +libm.a: $(OBJ) + $(AR) -rc libm.a $(OBJ) + +test: libm.a test.o + $(CC) -fno-builtin -Wall -W -Werror -pedantic -std=c99 -o test test.o libm.a + +.c.o: + $(CC) $(CFLAGS) -fno-builtin -Wall -W -Werror -pedantic -std=c99 -c $*.c + +celan: clean +clean: + -rm -f *.o *.a test + diff -Nupr src-uclibc-fresh/libm-vax/sin.c src-uclibc-hacked/libm-vax/sin.c --- src-uclibc-fresh/libm-vax/sin.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/sin.c 2005-11-09 23:09:38.000000000 +0100 @@ -0,0 +1,9 @@ + +extern long double sinl (long double x); + +double +sin (double x) +{ + return sinl (x); +} + diff -Nupr src-uclibc-fresh/libm-vax/sinf.c src-uclibc-hacked/libm-vax/sinf.c --- src-uclibc-fresh/libm-vax/sinf.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/sinf.c 2005-11-09 23:09:38.000000000 +0100 @@ -0,0 +1,9 @@ + +extern double sin (double x); + +float +sinf (float x) +{ + return sin (x); +} + diff -Nupr src-uclibc-fresh/libm-vax/sinl.c src-uclibc-hacked/libm-vax/sinl.c --- src-uclibc-fresh/libm-vax/sinl.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/sinl.c 2005-11-09 23:09:38.000000000 +0100 @@ -0,0 +1,55 @@ +/* http://en.wikipedia.org/wiki/Pi */ +#define __VAX_PI 3.14159265358979323846264338327950288419716939937510L + +static long double +taylor_sinl (long double x, int i) +{ + long double divisor = 1.0; + long double dividend = 1.0; + int n; + + for (n = 0; n < i; n++) { + divisor *= x; + dividend *= (n + 1); + } + + if (i % 4 == 3) + divisor *= -1.0; + + return divisor / dividend; +} + +long double +sinl (long double x) +{ + long double result = 0.0; + int n_pi; + int i; + + /* sin(-x) = -sin(x) */ + if (x < 0.0) + return -sinl (-x); + + /* left-shift x to be in [0..2pi[ */ + n_pi = x / __VAX_PI; + if (n_pi >= 2) + x -= (n_pi/2*2) * __VAX_PI; + + /* [pi..2pi[ is negatively mapped to [0..pi[ */ + if (x >= __VAX_PI) + return -sinl (x - __VAX_PI); + + /* Mirror [pi/2..pi] -> [pi/2..0] */ + if (x >= __VAX_PI/2.0) + return sinl (__VAX_PI - x); + + /* + * The remaining part which is not solved recursively is in + * the range of [0..pi/2] and will be approximated by a polynom. + */ + for (i = 1; i < 30; i += 2) + result += taylor_sinl (x, i); + + return result; +} + diff -Nupr src-uclibc-fresh/libm-vax/test.c src-uclibc-hacked/libm-vax/test.c --- src-uclibc-fresh/libm-vax/test.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/test.c 2005-11-09 23:09:38.000000000 +0100 @@ -0,0 +1,21 @@ +#include <stdio.h> + +extern double sin (double x); +extern double cos (double x); + +int +main (void) +{ + int i; + + printf ("scale=20\n"); + + for (i = -10000; i <= 10000; i++) { + double x = i / 1000.0; + printf ("%20.18lf-s(%20.18lf)\n", sin (x), x); + printf ("%20.18lf-c(%20.18lf)\n", cos (x), x); + } + + return 0; +} + |