From: Jan-Benedict G. <jb...@us...> - 2005-11-16 11:55:31
|
Update of /cvsroot/linux-vax/toolchain/patches In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20445 Added Files: uclibc-000014-libm-2-abs.patch uclibc-000015-libm-3-centralize_constants.patch uclibc-000016-libm-4-tan.patch uclibc-000017-libm-5-asin.patch uclibc-000018-libm-6-cleanup.patch uclibc-000019-libm-7-acos.patch uclibc-000020-libm-8-fix-internal_exp.patch uclibc-000021-libm-9-better_tests.patch Log Message: - Some more libm functions. - DO NOT RELY ON THEM!!! - They mostly seem to work, though. - The arcus functions need a touchup: they're precise IFF the input value is near zero, but they get horribly unprecise if the input value tends towards 1... Maybe I'd add another Taylor series based on 0.9 or something. --- NEW FILE: uclibc-000019-libm-7-acos.patch --- diff -Nurp src-uclibc-fresh/libm-vax/acos.c src-uclibc-hacked/libm-vax/acos.c --- src-uclibc-fresh/libm-vax/acos.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/acos.c 2005-11-13 15:55:47.000000000 +0100 @@ -0,0 +1,9 @@ + +extern long double acosl (long double value); + +double +acos (double value) +{ + return acosl (value); +} + diff -Nurp src-uclibc-fresh/libm-vax/acosf.c src-uclibc-hacked/libm-vax/acosf.c --- src-uclibc-fresh/libm-vax/acosf.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/acosf.c 2005-11-13 15:56:17.000000000 +0100 @@ -0,0 +1,9 @@ + +extern long double acosl (long double value); + +float +acosf (float value) +{ + return acosl (value); +} + diff -Nurp src-uclibc-fresh/libm-vax/acosl.c src-uclibc-hacked/libm-vax/acosl.c --- src-uclibc-fresh/libm-vax/acosl.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/acosl.c 2005-11-13 15:54:58.000000000 +0100 @@ -0,0 +1,32 @@ +#include "_foo_libmath.h" + +extern long double fabsl (long double value); + +static long double +taylor_acosl (long double value, long long k) +{ + return _internal_binominal_r_over_n (-0.5L, k) + * _exp_ld_ll_ll (-1, k) + * _exp_ld_ld_ll (value, 2 * k + 1) + / (long double) (2 * k + 1); +} + +long double +acosl (long double value) +{ + long double taylor_sum = _FOO_PI_LD / 2.0L; + long long n; + + if (fabsl (value) > 1.0L) return 0.0L; /* FIXME: return NaN and raise FP exception */ + if (value == -1.0L) return _FOO_PI_LD; + if (value == 0.0L) return _FOO_PI_LD / 2.0L; + if (value == 1.0L) return 0.0L; + if (value == -_FOO_SQRT_2_LD / 2.0L) return 3.0L * _FOO_PI_LD / 4.0L; + if (value == _FOO_SQRT_2_LD / 2.0L) return _FOO_PI_LD / 4.0L; + + for (n = 0; n < ACOS_NUM_TAYLOR; n++) + taylor_sum -= taylor_acosl (value, n); + + return taylor_sum; +} + diff -Nurp src-uclibc-fresh/libm-vax/_foo_libmath.h src-uclibc-hacked/libm-vax/_foo_libmath.h --- src-uclibc-fresh/libm-vax/_foo_libmath.h 2005-11-13 15:40:21.000000000 +0100 +++ src-uclibc-hacked/libm-vax/_foo_libmath.h 2005-11-13 15:56:57.000000000 +0100 @@ -9,6 +9,7 @@ #define SIN_NUM_TAYLOR 30 #define COS_NUM_TAYLOR 30 #define ASIN_NUM_TAYLOR 30 +#define ACOS_NUM_TAYLOR 30 @@ -23,6 +24,10 @@ #define _FOO_PI_D 3.14159265358979323846264338327950288419716939937510 #define _FOO_PI_F 3.14159265358979323846264338327950288419716939937510F +/* http://de.wikipedia.org/wiki/Wurzel_aus_2#Nachkommastellen_der_Wurzel_2 */ +#define _FOO_SQRT_2_LD 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727L +#define _FOO_SQRT_2_D 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727 +#define _FOO_SQRT_2_F 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727F /* * diff -Nurp src-uclibc-fresh/libm-vax/Makefile src-uclibc-hacked/libm-vax/Makefile --- src-uclibc-fresh/libm-vax/Makefile 2005-11-13 15:26:02.000000000 +0100 +++ src-uclibc-hacked/libm-vax/Makefile 2005-11-13 15:56:29.000000000 +0100 @@ -8,6 +8,7 @@ OBJ= sinf.o sin.o sinl.o \ fabsf.o fabs.o fabsl.o \ tanf.o tan.o tanl.o \ asinf.o asin.o asinl.o \ + acosf.o acos.o acosl.o \ _internal_facultaet.o \ _internal_exp.o \ _internal_binominal_r_over_n.o --- NEW FILE: uclibc-000015-libm-3-centralize_constants.patch --- diff -Nurp src-uclibc-fresh/libm-vax/cosl.c src-uclibc-hacked/libm-vax/cosl.c --- src-uclibc-fresh/libm-vax/cosl.c 2005-11-12 20:40:15.000000000 +0100 +++ src-uclibc-hacked/libm-vax/cosl.c 2005-11-12 21:22:50.000000000 +0100 @@ -1,11 +1,10 @@ -/* http://en.wikipedia.org/wiki/Pi */ -#define __VAX_PI 3.14159265358979323846264338327950288419716939937510L +#include "_foo_libmath.h" static long double taylor_cosl (long double x, int i) { - long double divisor = 1.0; - long double dividend = 1.0; + long double divisor = 1.0L; + long double dividend = 1.0L; int n; for (n = 0; n < i; n++) { @@ -14,7 +13,7 @@ taylor_cosl (long double x, int i) } if (i % 4 == 2) - divisor *= -1.0; + divisor *= -1.0L; return divisor / dividend; } @@ -22,32 +21,32 @@ taylor_cosl (long double x, int i) long double cosl (long double x) { - long double result = 0.0; + long double result = 0.0L; int n_pi; int i; /* sin(-x) = -sin(x) */ - if (x < 0.0) + if (x < 0.0L) return cosl (-x); /* left-shift x to be in [0..2pi[ */ - n_pi = x / __VAX_PI; + n_pi = x / _FOO_PI_LD; if (n_pi >= 2) - x -= (n_pi/2*2) * __VAX_PI; + x -= (n_pi/2*2) * _FOO_PI_LD; /* [pi..2pi[ is negatively mapped to [0..pi[ */ - if (x >= __VAX_PI) - return -cosl (x - __VAX_PI); + if (x >= _FOO_PI_LD) + return -cosl (x - _FOO_PI_LD); /* Mirror [pi/2..pi] -> [pi/2..0] */ - if (x >= __VAX_PI/2.0) - return -cosl (__VAX_PI - x); + if (x >= _FOO_PI_LD/2.0L) + return -cosl (_FOO_PI_LD - 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) + for (i = 0; i < SIN_COS_NUM_TAYLOR; i += 2) result += taylor_cosl (x, i); return result; diff -Nurp src-uclibc-fresh/libm-vax/_foo_libmath.h src-uclibc-hacked/libm-vax/_foo_libmath.h --- src-uclibc-fresh/libm-vax/_foo_libmath.h 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/_foo_libmath.h 2005-11-12 21:21:54.000000000 +0100 @@ -0,0 +1,24 @@ +#ifndef _FOO_LIBMATH_H +#define _FOO_LIBMATH_H + +/* + * + * Tuning parameters + * + */ +#define SIN_COS_NUM_TAYLOR 30 + + + +/* + * + * Some constants, for INTERNAL USE ONLY!!! + * + */ + +/* http://en.wikipedia.org/wiki/Pi */ +#define _FOO_PI_LD 3.14159265358979323846264338327950288419716939937510L +#define _FOO_PI_D 3.14159265358979323846264338327950288419716939937510 +#define _FOO_PI_F 3.14159265358979323846264338327950288419716939937510F + +#endif /* _FOO_LIBMATH_H */ diff -Nurp src-uclibc-fresh/libm-vax/sinl.c src-uclibc-hacked/libm-vax/sinl.c --- src-uclibc-fresh/libm-vax/sinl.c 2005-11-12 20:40:15.000000000 +0100 +++ src-uclibc-hacked/libm-vax/sinl.c 2005-11-12 21:22:04.000000000 +0100 @@ -1,11 +1,10 @@ -/* http://en.wikipedia.org/wiki/Pi */ -#define __VAX_PI 3.14159265358979323846264338327950288419716939937510L +#include "_foo_libmath.h" static long double taylor_sinl (long double x, int i) { - long double divisor = 1.0; - long double dividend = 1.0; + long double divisor = 1.0L; + long double dividend = 1.0L; int n; for (n = 0; n < i; n++) { @@ -14,7 +13,7 @@ taylor_sinl (long double x, int i) } if (i % 4 == 3) - divisor *= -1.0; + divisor *= -1.0L; return divisor / dividend; } @@ -22,32 +21,32 @@ taylor_sinl (long double x, int i) long double sinl (long double x) { - long double result = 0.0; + long double result = 0.0L; int n_pi; int i; /* sin(-x) = -sin(x) */ - if (x < 0.0) + if (x < 0.0L) return -sinl (-x); /* left-shift x to be in [0..2pi[ */ - n_pi = x / __VAX_PI; + n_pi = x / _FOO_PI_LD; if (n_pi >= 2) - x -= (n_pi/2*2) * __VAX_PI; + x -= (n_pi/2*2) * _FOO_PI_LD; /* [pi..2pi[ is negatively mapped to [0..pi[ */ - if (x >= __VAX_PI) - return -sinl (x - __VAX_PI); + if (x >= _FOO_PI_LD) + return -sinl (x - _FOO_PI_LD); /* Mirror [pi/2..pi] -> [pi/2..0] */ - if (x >= __VAX_PI/2.0) - return sinl (__VAX_PI - x); + if (x >= _FOO_PI_LD/2.0L) + return sinl (_FOO_PI_LD - 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) + for (i = 1; i < SIN_COS_NUM_TAYLOR; i += 2) result += taylor_sinl (x, i); return result; --- NEW FILE: uclibc-000017-libm-5-asin.patch --- diff -Nurp src-uclibc-fresh/libm-vax/asin.c src-uclibc-hacked/libm-vax/asin.c --- src-uclibc-fresh/libm-vax/asin.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/asin.c 2005-11-13 15:22:07.000000000 +0100 @@ -0,0 +1,9 @@ + +extern long double asinl (long double value); + +double +asin (double value) +{ + return asinl (value); +} + diff -Nurp src-uclibc-fresh/libm-vax/asinf.c src-uclibc-hacked/libm-vax/asinf.c --- src-uclibc-fresh/libm-vax/asinf.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/asinf.c 2005-11-13 15:22:36.000000000 +0100 @@ -0,0 +1,9 @@ + +extern long double asinl (long double value); + +float +asinf (float value) +{ + return asinl (value); +} + diff -Nurp src-uclibc-fresh/libm-vax/asinl.c src-uclibc-hacked/libm-vax/asinl.c --- src-uclibc-fresh/libm-vax/asinl.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/asinl.c 2005-11-13 15:18:33.000000000 +0100 @@ -0,0 +1,31 @@ +#include "_foo_libmath.h" + +extern long double fabsl (long double value); + +/* http://de.wikipedia.org/wiki/Arcussinus */ +static long double +taylor_asinl (long double value, long long k) +{ + return _internal_binominal_r_over_n (-0.5L, k) + * _exp_ld_ll_ll (-1, k) + * _exp_ld_ld_ll (value, 2 * k + 1) + / (long double) (2 * k + 1); +} + +long double +asinl (long double value) +{ + long double taylor_sum = 0.0L; + long long n; + + if (fabsl (value) > 1.0L) return 0.0L; /* FIXME: return NaN and raise FP exception */ + if (value == 0.0L) return 0.0L; + if (value == 1.0L) return _FOO_PI_LD/2.0L; + if (value == -1.0L) return -_FOO_PI_LD/2.0L; + + for (n = 0; n < ASIN_NUM_TAYLOR; n++) + taylor_sum += taylor_asinl (value, n); + + return taylor_sum; +} + diff -Nurp src-uclibc-fresh/libm-vax/_foo_libmath.h src-uclibc-hacked/libm-vax/_foo_libmath.h --- src-uclibc-fresh/libm-vax/_foo_libmath.h 2005-11-12 21:25:04.000000000 +0100 +++ src-uclibc-hacked/libm-vax/_foo_libmath.h 2005-11-13 14:22:32.000000000 +0100 @@ -7,6 +7,7 @@ * */ #define SIN_COS_NUM_TAYLOR 30 +#define ASIN_NUM_TAYLOR 30 @@ -21,4 +22,17 @@ #define _FOO_PI_D 3.14159265358979323846264338327950288419716939937510 #define _FOO_PI_F 3.14159265358979323846264338327950288419716939937510F + +/* + * + * Internal helper functions + * + */ +extern long double _internal_binominal_r_over_n (long double r, unsigned long long n); +extern long long _exp_ll_ll_ll (long long base, long long expo); +extern long double _exp_ld_ll_ll (long long base, long long expo); +extern long double _exp_ld_ld_ll (long double base, long long expo); +/* _internal_facultaet.c */ +extern long double _internal_facultaet_ld (unsigned long long value); + #endif /* _FOO_LIBMATH_H */ diff -Nurp src-uclibc-fresh/libm-vax/_internal_binominal_r_over_n.c src-uclibc-hacked/libm-vax/_internal_binominal_r_over_n.c --- src-uclibc-fresh/libm-vax/_internal_binominal_r_over_n.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/_internal_binominal_r_over_n.c 2005-11-13 15:20:47.000000000 +0100 @@ -0,0 +1,21 @@ +#include "_foo_libmath.h" + +/* + * ( r ) r * (r - 1) * ... * (r - k + 1) + * ( ) = --------------------------------- + * ( k ) k! + */ +long double +_internal_binominal_r_over_n (long double r, unsigned long long k) +{ + unsigned long long n; + long double product = 1.0L; + + if (k == 0) return 1.0L; + + for (n = 0; n < k; n++) + product *= r - (long double) n; + + return product / _internal_facultaet_ld (k); +} + diff -Nurp src-uclibc-fresh/libm-vax/_internal_exp.c src-uclibc-hacked/libm-vax/_internal_exp.c --- src-uclibc-fresh/libm-vax/_internal_exp.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/_internal_exp.c 2005-11-13 15:20:59.000000000 +0100 @@ -0,0 +1,44 @@ +#include "_foo_libmath.h" + +long long +_exp_ll_ll_ll (long long base, long long expo) +{ + long long intl_exp; + long long product = 1LL; + + if (expo == 0LL) return 0LL; + + for (intl_exp = 0; intl_exp < expo; intl_exp++) + product *= base; + + return product; +} + +long double +_exp_ld_ll_ll (long long base, long long expo) +{ + long long intl_exp; + long double product = 1.0L; + + if (expo == 0LL) return 1.0L; + + for (intl_exp = 0; intl_exp < expo; intl_exp++) + product *= base; + + return product; +} + +long double +_exp_ld_ld_ll (long double base, long long expo) +{ + long long intl_exp; + long double product = 1.0L; + + if (expo == 0LL) return 0.0L; + + for (intl_exp = 0; intl_exp < expo; intl_exp++) + product *= base; + + return product; +} + diff -Nurp src-uclibc-fresh/libm-vax/_internal_facultaet.c src-uclibc-hacked/libm-vax/_internal_facultaet.c --- src-uclibc-fresh/libm-vax/_internal_facultaet.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/_internal_facultaet.c 2005-11-12 22:47:47.000000000 +0100 @@ -0,0 +1,25 @@ + +unsigned long long +_internal_facultaet_ull (unsigned long long value) +{ + unsigned long long n; + unsigned long long facultaet = 1LL; + + for (n = 1LL; n <= value; n++) + facultaet *= n; + + return facultaet; +} + +long double +_internal_facultaet_ld (unsigned long long value) +{ + unsigned long long n; + long double facultaet = 1.0L; + + for (n = 1LL; n <= value; n++) + facultaet *= (long double) n; + + return facultaet; +} + diff -Nurp src-uclibc-fresh/libm-vax/Makefile src-uclibc-hacked/libm-vax/Makefile --- src-uclibc-fresh/libm-vax/Makefile 2005-11-12 21:56:04.000000000 +0100 +++ src-uclibc-hacked/libm-vax/Makefile 2005-11-13 15:22:54.000000000 +0100 @@ -6,7 +6,11 @@ CFLAGS= OBJ= sinf.o sin.o sinl.o \ cosf.o cos.o cosl.o \ fabsf.o fabs.o fabsl.o \ - tanf.o tan.o tanl.o + tanf.o tan.o tanl.o \ + asinf.o asin.o asinl.o \ + _internal_facultaet.o \ + _internal_exp.o \ + _internal_binominal_r_over_n.o all: libm.a test diff -Nurp src-uclibc-fresh/libm-vax/test.c src-uclibc-hacked/libm-vax/test.c --- src-uclibc-fresh/libm-vax/test.c 2005-11-12 20:40:15.000000000 +0100 +++ src-uclibc-hacked/libm-vax/test.c 2005-11-13 15:20:03.000000000 +0100 @@ -2,19 +2,26 @@ extern double sin (double x); extern double cos (double x); +extern long double asinl (long double x); + +extern long double +_internal_binominal_r_over_n (long double r, unsigned long long k); int main (void) { - int i; - - printf ("scale=20\n"); + long double x; - 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); - } + x = 0.7L; + printf ("asinl(%llf)=%llf\n", x, asinl (x)); + //printf ("asinl(%lf)=%20.18lf)\n", i, asinl (i)); +#if 0 + long double r = 0.5L; + unsigned long long k = 4; + + printf ("_internal_binominal_r_over_n (%llf, %lld) = %llf\n", + r, k, _internal_binominal_r_over_n (r, k)); +#endif return 0; } --- NEW FILE: uclibc-000020-libm-8-fix-internal_exp.patch --- diff -Nurp src-uclibc-fresh/libm-vax/_internal_exp.c src-uclibc-hacked/libm-vax/_internal_exp.c --- src-uclibc-fresh/libm-vax/_internal_exp.c 2005-11-13 16:34:07.000000000 +0100 +++ src-uclibc-hacked/libm-vax/_internal_exp.c 2005-11-13 18:36:27.000000000 +0100 @@ -6,7 +6,7 @@ _exp_ll_ll_ll (long long base, long long long long intl_exp; long long product = 1LL; - if (expo == 0LL) return 0LL; + if (expo == 0LL) return 1LL; for (intl_exp = 0; intl_exp < expo; intl_exp++) product *= base; @@ -34,7 +34,7 @@ _exp_ld_ld_ll (long double base, long lo long long intl_exp; long double product = 1.0L; - if (expo == 0LL) return 0.0L; + if (expo == 0LL) return 1.0L; for (intl_exp = 0; intl_exp < expo; intl_exp++) product *= base; --- NEW FILE: uclibc-000014-libm-2-abs.patch --- diff -Nurp src-uclibc-fresh/libm-vax/fabs.c src-uclibc-hacked/libm-vax/fabs.c --- src-uclibc-fresh/libm-vax/fabs.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/fabs.c 2005-11-12 20:46:53.000000000 +0100 @@ -0,0 +1,10 @@ + +double +fabs (double value) +{ + if (value < 0.0) + return -value; + else + return value; +} + diff -Nurp src-uclibc-fresh/libm-vax/fabsf.c src-uclibc-hacked/libm-vax/fabsf.c --- src-uclibc-fresh/libm-vax/fabsf.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/fabsf.c 2005-11-12 20:50:03.000000000 +0100 @@ -0,0 +1,10 @@ + +float +fabsf (float value) +{ + if (value < 0.0F) + return -value; + else + return value; +} + diff -Nurp src-uclibc-fresh/libm-vax/fabsl.c src-uclibc-hacked/libm-vax/fabsl.c --- src-uclibc-fresh/libm-vax/fabsl.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/fabsl.c 2005-11-12 20:50:16.000000000 +0100 @@ -0,0 +1,10 @@ + +long double +fabsl (long double value) +{ + if (value < 0.0L) + return -value; + else + return value; +} + diff -Nurp src-uclibc-fresh/libm-vax/Makefile src-uclibc-hacked/libm-vax/Makefile --- src-uclibc-fresh/libm-vax/Makefile 2005-11-12 20:40:15.000000000 +0100 +++ src-uclibc-hacked/libm-vax/Makefile 2005-11-12 20:55:05.000000000 +0100 @@ -3,7 +3,9 @@ AR=$(TARGET)ar CC=$(TARGET)gcc CFLAGS= -OBJ=sinl.o sin.o sinf.o cosl.o cos.o cosf.o +OBJ= sinf.o sin.o sinl.o \ + cosf.o cos.o cosl.o \ + fabsf.o fabs.o fabsl.o all: libm.a test --- NEW FILE: uclibc-000018-libm-6-cleanup.patch --- diff -Nurp src-uclibc-fresh/libm-vax/cosl.c src-uclibc-hacked/libm-vax/cosl.c --- src-uclibc-fresh/libm-vax/cosl.c 2005-11-12 21:25:04.000000000 +0100 +++ src-uclibc-hacked/libm-vax/cosl.c 2005-11-13 15:38:09.000000000 +0100 @@ -1,53 +1,43 @@ #include "_foo_libmath.h" static long double -taylor_cosl (long double x, int i) +taylor_cosl (long double value, unsigned long long n) { - long double divisor = 1.0L; - long double dividend = 1.0L; - int n; - - for (n = 0; n < i; n++) { - divisor *= x; - dividend *= (n + 1); - } - - if (i % 4 == 2) - divisor *= -1.0L; - - return divisor / dividend; + return (long double) _exp_ll_ll_ll (-1, n) + * _exp_ld_ld_ll (value, 2*n) + / _internal_facultaet_ld (2*n); } long double -cosl (long double x) +cosl (long double value) { long double result = 0.0L; int n_pi; - int i; + unsigned long long n; /* sin(-x) = -sin(x) */ - if (x < 0.0L) - return cosl (-x); + if (value < 0.0L) + return cosl (-value); /* left-shift x to be in [0..2pi[ */ - n_pi = x / _FOO_PI_LD; + n_pi = value / _FOO_PI_LD; if (n_pi >= 2) - x -= (n_pi/2*2) * _FOO_PI_LD; + value -= (n_pi/2*2) * _FOO_PI_LD; /* [pi..2pi[ is negatively mapped to [0..pi[ */ - if (x >= _FOO_PI_LD) - return -cosl (x - _FOO_PI_LD); + if (value >= _FOO_PI_LD) + return -cosl (value - _FOO_PI_LD); /* Mirror [pi/2..pi] -> [pi/2..0] */ - if (x >= _FOO_PI_LD/2.0L) - return -cosl (_FOO_PI_LD - x); + if (value >= _FOO_PI_LD/2.0L) + return -cosl (_FOO_PI_LD - value); /* * 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 < SIN_COS_NUM_TAYLOR; i += 2) - result += taylor_cosl (x, i); + for (n = 0; n < COS_NUM_TAYLOR; n++) + result += taylor_cosl (value, n); return result; } diff -Nurp src-uclibc-fresh/libm-vax/_foo_libmath.h src-uclibc-hacked/libm-vax/_foo_libmath.h --- src-uclibc-fresh/libm-vax/_foo_libmath.h 2005-11-13 15:26:02.000000000 +0100 +++ src-uclibc-hacked/libm-vax/_foo_libmath.h 2005-11-13 15:35:29.000000000 +0100 @@ -6,8 +6,9 @@ * Tuning parameters * */ -#define SIN_COS_NUM_TAYLOR 30 -#define ASIN_NUM_TAYLOR 30 +#define SIN_NUM_TAYLOR 30 +#define COS_NUM_TAYLOR 30 +#define ASIN_NUM_TAYLOR 30 diff -Nurp src-uclibc-fresh/libm-vax/sinl.c src-uclibc-hacked/libm-vax/sinl.c --- src-uclibc-fresh/libm-vax/sinl.c 2005-11-12 21:25:04.000000000 +0100 +++ src-uclibc-hacked/libm-vax/sinl.c 2005-11-13 15:38:49.000000000 +0100 @@ -1,53 +1,43 @@ #include "_foo_libmath.h" static long double -taylor_sinl (long double x, int i) +taylor_sinl (long double value, unsigned long long n) { - long double divisor = 1.0L; - long double dividend = 1.0L; - int n; - - for (n = 0; n < i; n++) { - divisor *= x; - dividend *= (n + 1); - } - - if (i % 4 == 3) - divisor *= -1.0L; - - return divisor / dividend; + return (long double) _exp_ll_ll_ll (-1, n) + * _exp_ld_ld_ll (value, 2*n+1) + / _internal_facultaet_ld (2*n+1); } long double -sinl (long double x) +sinl (long double value) { long double result = 0.0L; int n_pi; - int i; + unsigned long long n; /* sin(-x) = -sin(x) */ - if (x < 0.0L) - return -sinl (-x); + if (value < 0.0L) + return -sinl (-value); /* left-shift x to be in [0..2pi[ */ - n_pi = x / _FOO_PI_LD; + n_pi = value / _FOO_PI_LD; if (n_pi >= 2) - x -= (n_pi/2*2) * _FOO_PI_LD; + value -= (n_pi/2*2) * _FOO_PI_LD; /* [pi..2pi[ is negatively mapped to [0..pi[ */ - if (x >= _FOO_PI_LD) - return -sinl (x - _FOO_PI_LD); + if (value >= _FOO_PI_LD) + return -sinl (value - _FOO_PI_LD); /* Mirror [pi/2..pi] -> [pi/2..0] */ - if (x >= _FOO_PI_LD/2.0L) - return sinl (_FOO_PI_LD - x); + if (value >= _FOO_PI_LD/2.0L) + return sinl (_FOO_PI_LD - value); /* * 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 < SIN_COS_NUM_TAYLOR; i += 2) - result += taylor_sinl (x, i); + for (n = 0; n < SIN_NUM_TAYLOR; n++) + result += taylor_sinl (value, n); return result; } --- NEW FILE: uclibc-000021-libm-9-better_tests.patch --- diff -Nurp src-uclibc-fresh/libm-vax/test.c src-uclibc-hacked/libm-vax/test.c --- src-uclibc-fresh/libm-vax/test.c 2005-11-13 16:34:07.000000000 +0100 +++ src-uclibc-hacked/libm-vax/test.c 2005-11-13 19:55:30.000000000 +0100 @@ -1,27 +1,166 @@ #include <stdio.h> +#include <stdlib.h> +#include <math.h> -extern double sin (double x); -extern double cos (double x); -extern long double asinl (long double x); +#define ARRAY_SIZE(x) (sizeof (x) / sizeof ((x)[0])) -extern long double -_internal_binominal_r_over_n (long double r, unsigned long long k); +#define ENTRY(FUNC,INPUT,OUTPUT) \ +{ \ + .func_ptr = &FUNC, \ + .func_name = #FUNC, \ + .input = INPUT, \ + .output = OUTPUT, \ +} + +struct { + float (*func_ptr) (float); + char *func_name; + char *input; + char *output; +} result_one_float[] = { + ENTRY (fabsf, "-10.66", "10.66"), + ENTRY (fabsf, "0", "0"), + ENTRY (fabsf, "10.66", "10.66"), + ENTRY (cosf, "-10", "-0.83907152907645245225"), + ENTRY (cosf, "-2", "-0.41614683654714238699"), + ENTRY (cosf, "0", "1"), + ENTRY (cosf, "2", "-0.41614683654714238699"), + ENTRY (cosf, "3", "-0.98999249660044545727"), + ENTRY (sinf, "-10", "0.54402111088936981340"), + ENTRY (sinf, "-2", "-0.90929742682568169539"), + ENTRY (sinf, "0", "0"), + ENTRY (sinf, "2", "0.90929742682568169539"), + ENTRY (sinf, "3", "0.14112000805986722210"), + ENTRY (tanf, "-10", "-0.64836082745908667126"), + ENTRY (tanf, "-2", "2.18503986326151899166"), + ENTRY (tanf, "0", "0"), + ENTRY (tanf, "2", "-2.18503986326151899166"), + ENTRY (tanf, "3", "-0.14254654307427780529"), + ENTRY (asinf, "-0.99749498660405443094", "-1.5"), + ENTRY (asinf, "-0.96355818541719296470", "-1.3"), + ENTRY (asinf, "-0.89120736006143533995", "-1.1"), + ENTRY (asinf, "-0.29552020666133957510", "-0.3"), + ENTRY (asinf, "0", "0"), + ENTRY (asinf, "0.71735609089952276162", "0.8"), + ENTRY (acosf, ".16996714290024093861", "-1.4"), + ENTRY (acosf, ".26749882862458740699", "-1.3"), + ENTRY (acosf, ".45359612142557738777", "-1.1"), + ENTRY (acosf, ".95533648912560601964", "-0.3"), + ENTRY (acosf, "1", "0"), + ENTRY (acosf, ".69670670934716542092", "0.8"), +}; +struct { + double (*func_ptr) (double); + char *func_name; + char *input; + char *output; +} result_one_double[] = { + ENTRY (fabs, "-10.66", "10.66"), + ENTRY (fabs, "0", "0"), + ENTRY (fabs, "10.66", "10.66"), + ENTRY (cos, "-10", "-0.83907152907645245225"), + ENTRY (cos, "-2", "-0.41614683654714238699"), + ENTRY (cos, "0", "1"), + ENTRY (cos, "2", "-0.41614683654714238699"), + ENTRY (cos, "3", "-0.98999249660044545727"), + ENTRY (sin, "-10", "0.54402111088936981340"), + ENTRY (sin, "-2", "-0.90929742682568169539"), + ENTRY (sin, "0", "0"), + ENTRY (sin, "2", "0.90929742682568169539"), + ENTRY (sin, "3", "0.14112000805986722210"), + ENTRY (tan, "-10", "-0.64836082745908667126"), + ENTRY (tan, "-2", "2.18503986326151899166"), + ENTRY (tan, "0", "0"), + ENTRY (tan, "2", "-2.18503986326151899166"), + ENTRY (tan, "3", "-0.14254654307427780529"), + ENTRY (asin, "-0.99749498660405443094", "-1.5"), + ENTRY (asin, "-0.96355818541719296470", "-1.3"), + ENTRY (asin, "-0.89120736006143533995", "-1.1"), + ENTRY (asin, "-0.29552020666133957510", "-0.3"), + ENTRY (asin, "0", "0"), + ENTRY (asin, "0.71735609089952276162", "0.8"), + ENTRY (acos, ".16996714290024093861", "-1.4"), + ENTRY (acos, ".26749882862458740699", "-1.3"), + ENTRY (acos, ".45359612142557738777", "-1.1"), + ENTRY (acos, ".95533648912560601964", "-0.3"), + ENTRY (acos, "1", "0"), + ENTRY (acos, ".69670670934716542092", "0.8"), +}; +struct { + long double (*func_ptr) (long double); + char *func_name; + char *input; + char *output; +} result_one_long_double[] = { + ENTRY (fabsl, "-10.66", "10.66"), + ENTRY (fabsl, "0", "0"), + ENTRY (fabsl, "10.66", "10.66"), + ENTRY (cosl, "-10", "-0.83907152907645245225"), + ENTRY (cosl, "-2", "-0.41614683654714238699"), + ENTRY (cosl, "0", "1"), + ENTRY (cosl, "2", "-0.41614683654714238699"), + ENTRY (cosl, "3", "-0.98999249660044545727"), + ENTRY (sinl, "-10", "0.54402111088936981340"), + ENTRY (sinl, "-2", "-0.90929742682568169539"), + ENTRY (sinl, "0", "0"), + ENTRY (sinl, "2", "0.90929742682568169539"), + ENTRY (sinl, "3", "0.14112000805986722210"), + ENTRY (tanl, "-10", "-0.64836082745908667126"), + ENTRY (tanl, "-2", "2.18503986326151899166"), + ENTRY (tanl, "0", "0"), + ENTRY (tanl, "2", "-2.18503986326151899166"), + ENTRY (tanl, "3", "-0.14254654307427780529"), + ENTRY (asinl, "-0.99749498660405443094", "-1.5"), + ENTRY (asinl, "-0.96355818541719296470", "-1.3"), + ENTRY (asinl, "-0.89120736006143533995", "-1.1"), + ENTRY (asinl, "-0.29552020666133957510", "-0.3"), + ENTRY (asinl, "0", "0"), + ENTRY (asinl, "0.71735609089952276162", "0.8"), + ENTRY (acosl, ".16996714290024093861", "-1.4"), + ENTRY (acosl, ".26749882862458740699", "-1.3"), + ENTRY (acosl, ".45359612142557738777", "-1.1"), + ENTRY (acosl, ".95533648912560601964", "-0.3"), + ENTRY (acosl, "1", "0"), + ENTRY (acosl, ".69670670934716542092", "0.8"), +}; int main (void) { - long double x; - - x = 0.7L; - printf ("asinl(%llf)=%llf\n", x, asinl (x)); - //printf ("asinl(%lf)=%20.18lf)\n", i, asinl (i)); -#if 0 - long double r = 0.5L; - unsigned long long k = 4; - - printf ("_internal_binominal_r_over_n (%llf, %lld) = %llf\n", - r, k, _internal_binominal_r_over_n (r, k)); -#endif + float in_float, out_float, expected_float; + double in_double, out_double, expected_double; + long double in_long_double, out_long_double, expected_long_double; + unsigned int n; + + for (n = 0; n < ARRAY_SIZE (result_one_float); n++) { + in_float = strtof (result_one_float[n].input, NULL); + out_float = result_one_float[n].func_ptr (in_float); + expected_float = strtof (result_one_float[n].output, NULL); + printf ("%s(%f) = %f, d = %f\n", + result_one_float[n].func_name, + in_float, out_float, + expected_float - out_float); + } + + for (n = 0; n < ARRAY_SIZE (result_one_double); n++) { + in_double = strtof (result_one_double[n].input, NULL); + out_double = result_one_double[n].func_ptr (in_double); + expected_double = strtof (result_one_double[n].output, NULL); + printf ("%s(%lf) = %lf, d = %lf\n", + result_one_double[n].func_name, + in_double, out_double, + expected_double - out_double); + } + + for (n = 0; n < ARRAY_SIZE (result_one_long_double); n++) { + in_long_double = strtof (result_one_long_double[n].input, NULL); + out_long_double = result_one_long_double[n].func_ptr (in_long_double); + expected_long_double = strtof (result_one_long_double[n].output, NULL); + printf ("%s(%llf) = %llf, d = %llf\n", + result_one_long_double[n].func_name, + in_long_double, out_long_double, + expected_long_double - out_long_double); + } return 0; } --- NEW FILE: uclibc-000016-libm-4-tan.patch --- diff -Nurp src-uclibc-fresh/libm-vax/Makefile src-uclibc-hacked/libm-vax/Makefile --- src-uclibc-fresh/libm-vax/Makefile 2005-11-12 21:06:36.000000000 +0100 +++ src-uclibc-hacked/libm-vax/Makefile 2005-11-12 21:28:59.000000000 +0100 @@ -5,7 +5,8 @@ CFLAGS= OBJ= sinf.o sin.o sinl.o \ cosf.o cos.o cosl.o \ - fabsf.o fabs.o fabsl.o + fabsf.o fabs.o fabsl.o \ + tanf.o tan.o tanl.o all: libm.a test diff -Nurp src-uclibc-fresh/libm-vax/tan.c src-uclibc-hacked/libm-vax/tan.c --- src-uclibc-fresh/libm-vax/tan.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/tan.c 2005-11-12 21:28:32.000000000 +0100 @@ -0,0 +1,9 @@ + +extern long double tanl (long double value); + +double +tan (double value) +{ + return tanl (value); +} + diff -Nurp src-uclibc-fresh/libm-vax/tanf.c src-uclibc-hacked/libm-vax/tanf.c --- src-uclibc-fresh/libm-vax/tanf.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/tanf.c 2005-11-12 21:27:45.000000000 +0100 @@ -0,0 +1,9 @@ + +extern long double tanl (long double value); + +float +tanf (float value) +{ + return tanl (value); +} + diff -Nurp src-uclibc-fresh/libm-vax/tanl.c src-uclibc-hacked/libm-vax/tanl.c --- src-uclibc-fresh/libm-vax/tanl.c 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libm-vax/tanl.c 2005-11-12 21:38:17.000000000 +0100 @@ -0,0 +1,10 @@ + +extern long double sinl (long double value); +extern long double cosl (long double value); + +long double +tanl (long double value) +{ + return sinl (value) / cosl (value); +} + |