Skip to content

Commit

Permalink
Initial revision
Browse files Browse the repository at this point in the history
  • Loading branch information
fdedinec committed Apr 7, 2004
0 parents commit f3b44a8
Show file tree
Hide file tree
Showing 140 changed files with 33,279 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
David Defour and Catherine Daramy and Florent de Dinechin
504 changes: 504 additions & 0 deletions COPYING

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2003-04-18 : Florent de Dinechin
* initial autoconf/automake obsfuscation
31 changes: 31 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Process this file with automake to produce Makefile.in

lib_LIBRARIES = libcrlibm.a

# shared libraries need libtool. We'll do it later.
#lib_LTLIBRARIES = libcrlibm.la

libcrlibm_a_SOURCES = \
crlibm.h crlibm_private.h crlibm_private.c\
exp.h exp.c exp_fast.h exp_fast.c\
log.h log.c log_fast.c log_fast.h\
log10.h log10.c\
log2.h log2.c \
coefpi2.h rem_pio2.c\
sine.h sine.c\
cosine.h cosine.c\
tan.h tan.c cotan.c\
atan.h atan.c

# add all the scs_lib useful functions
libcrlibm_a_LIBADD = scs_lib/addition_scs.o \
scs_lib/division_scs.o scs_lib/print_scs.o\
scs_lib/double2scs.o scs_lib/zero_scs.o\
scs_lib/multiplication_scs.o scs_lib/scs2double.o

include_HEADERS = crlibm.h

SUBDIRS = scs_lib . tests

AM_CFLAGS = -fPIC -Wall -Wshadow -Wpointer-arith -Wcast-align -Wconversion -Waggregate-return -Wstrict-prototypes -Wnested-externs -Wlong-long -Winline
EXTRA_DIST = VERSION
Empty file added NEWS
Empty file.
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cr-libm, a portable, efficient, correctly rounded mathematical library.
12 changes: 12 additions & 0 deletions README.DEV
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Les commandes � taper la premi�re fois apr�s le cvs checkout sont
(dans l'ordre)

aclocal
autoheader
autoconf
automake --add-missing
./configure

Remarque : sur mon debian woody l'autoconf de service est trop vieux,
il faut utiliser la commande autoconf2.50 ...

1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.03
278 changes: 278 additions & 0 deletions atan.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
/*
* atan.c
*
*
* Created by cathydar on Thu Nov 07 2002.
* Copyright (c) 2001 __MyCompanyName__. All rights reserved.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <atan.h>

void atan(scs_ptr, scs_ptr);
double atan_rd(double);
double atan_ru(double);
double atan_rn(double);

/*
* WHAT WE CAN DO :
*
* 1) Range reduction
*
* x > 0 because atan(-x) = - atan(x)
*
* we have built 50 intervals I(i), associated to a b(i) so that :
*
* For every x :
*
* we find the interval I(i) , as atan(x) = atan(b(i)) + atan( (x - b(i)) / (1 + x * b(i)) )
*
* so that X = (x - b(i)) / (1 + x * b(i)) be in interval [ -2^(-6) , 2^(-6) ]
* There is no cancellation because :
* for every x in [ -2^(-6) , 2^(-6) ],
*
* atan(x) <= 0.01562372862 in binary 0.000001111111111
* AND for the smallest b(i) atan(b(i)) = 0.04687118592 in binary 0.00001011111111
*
*
* 2) Polynomial evaluation of atan(X), atan(b(i)) is tabulated.
*
* (-???)
* Approximation error: |err| < 2^
*
*
* 3) Reconstruction:
*
* atan(x) = atan(b(i)) + atan(X)
*
*
* 4) Rounding:
*
* when |x| is too big, the result is always sign(x) * Pi/2,
* because Pi/2 is appromated by the biggest value smallest than Pi/2,
* in order not to have an atan > Pi/2.
*/




void atan(scs_ptr res_scs, scs_ptr x){
scs_t X_scs, denom1_scs, denom2_scs, num_scs, poly_scs, X2;
db_number db;
int k, ind = 100, j, intmid = 32;

scs_get_d(&db.d, x);

/* Test if x need to be reduced */

if( db.i[0] >= borne_I[48]){
if ( db.i[0] < borne_I[49]){
j = 48;}
else if( db.i[0] > borne_I[49]){
j = 49;}
else {
res_scs = atan_bi_ptr[49];
return;
}
ind = j;

/* evaluate X = (x - b(j)) / (1 + x*b(j)) */

scs_mul(denom1_scs,bsc_ptr[ind],x);
scs_add(denom2_scs,denom1_scs,SCS_ONE);
scs_sub(X_scs,x,bsc_ptr[ind]);
scs_div(X_scs,X_scs,denom2_scs);
}
else if (((int) db.i[0]) == borne_I[48]) {
res_scs = atan_bi_ptr[48];
return ;
}
else if ( db.i[0] < borne_I[0]){
scs_set(X_scs, x);
ind = 60;
}
else{ /* First reduction : find the interval including x, "save" j to have b(j) and then being able to calculate X */
j = 32;
for (k=1;k<=5;k++){
if (db.i[0] < borne_I[j]){
j -= (intmid >> k);
}
else if(db.i[0] > borne_I[j]){
j += (intmid >> k);
}
else {res_scs = atan_bi_ptr[j];
return ;
}
}
if (db.i[0] < borne_I[j]){
ind = j-1;
}
else{
ind = j;
}

/* evaluate X = (x - b(j)) / (1 + x*b(j)) */

scs_mul(denom1_scs,bsc_ptr[ind],x);
scs_add(denom2_scs,denom1_scs,SCS_ONE);
scs_sub(num_scs,x,bsc_ptr[ind]);
scs_div(X_scs,num_scs,denom2_scs);
}
printf("ind = %d\n", ind);

/* Polynomial evaluation of atan(X) , X = (x-b(i)) / (1+ x*b(i)) */

scs_square(X2, X_scs);
scs_set(res_scs, constant_poly_ptr[0]);
for(k=1; k < 13; k++){
scs_mul(res_scs, res_scs, X2); /* we use Horner expression */
scs_add(res_scs, constant_poly_ptr[k], res_scs);

}
scs_mul(poly_scs, res_scs, X_scs);

if(ind == 60){
scs_set(res_scs, poly_scs);
return;
}else{
printf("on ajoute l' atan de b(j)\n");
/*scs_set(denom_scs, res_scs);*/
scs_add(res_scs,atan_bi_ptr[ind], poly_scs);
}
return;
}

/*************************************************************
*************************************************************
* ROUNDED TO NEAREST
*************************************************************
*************************************************************/

double sn_atan(double x){
scs_t sc1;
scs_t res_scs;
db_number res;
int sign =1;

res.d = x;

/* Filter cases */
if((res.l & 0x7fffffffffffffffULL) > larg_int.l)
{
if (x > 0){
return pio2.d;
}
else{
return mpio2.d;
}
}
else if ((res.l & 0x7fffffffffffffffULL) < tiny_int.l) {
return 0.0;
}
else{
if (x < 0){
sign = -1;
x *= -1;
}
scs_set_d(sc1, x);
atan(res_scs, sc1);
scs_get_d(&res.d, res_scs);
if (sign == -1){
res.d *= -1;
return res.d;
}
return res.d;
}
}

/*************************************************************
*************************************************************
* ROUNDED TOWARD -INFINITY
*************************************************************
*************************************************************/

double atan_rd(double x){
scs_t sc1;
scs_t res_scs;
db_number res;
int sign = 1;

res.d = x;

/* Filter cases */
if((res.l & 0x7fffffffffffffffULL) > larg_int.l)
{
if (x < 0){
return mpio2.d;
}
else{
return pio2.d;
}
}
else {
if (x < 0){
sign = -1;
x *= -1;
}
scs_set_d(sc1, x);
atan(res_scs, sc1);
if (sign == -1){
scs_get_d_pinf(&res.d, res_scs);
res.d *= -1;
return res.d;
}
else{
scs_get_d_minf(&res.d, res_scs);
return res.d;
}
}
}

/*************************************************************
*************************************************************
* ROUNDED TOWARD +INFINITY
*************************************************************
*************************************************************/

double atan_ru(double x){
scs_t sc1;
scs_t res_scs;
db_number res;
int sign = 1;

res.d = x;

/* Filter cases */
if((res.l & 0x7fffffffffffffffULL) > larg_int.l)
{
if (x > 0)
{
return pio2.d;
}
else
{
return mpio2.d;
}
}
else
{
if (x < 0){
sign = -1;
x *= -1;
}

scs_set_d(sc1, x);
atan(res_scs, sc1);
if (sign == -1){
scs_get_d_minf(&res.d, res_scs);
res.d *= -1;
return res.d;
}
else{
scs_get_d_pinf(&res.d, res_scs);
return res.d;
}
}
}

Loading

0 comments on commit f3b44a8

Please sign in to comment.