Increased precision of PI

This commit is contained in:
jjgarcia 2008-08-02 16:24:34 +00:00
parent ad286a7901
commit ebefa6ed13
3 changed files with 18 additions and 29 deletions

View file

@ -21,13 +21,6 @@
# undef complex
#endif
#include "ecl/internal.h"
#ifndef M_PI
# ifdef PI
# define M_PI PI
# else
# define M_PI 3.14159265358979323846
# endif
#endif
#ifndef HAVE_LOG1P
double
@ -414,19 +407,19 @@ ecl_atan2_double(double y, double x)
}
} else if (x == 0) {
if (y > 0) {
return M_PI / 2.0;
return ECL_PI2_D;
} else if (y == 0) {
FEerror("Logarithmic singularity.", 0);
} else {
return -M_PI / 2.0;
return -ECL_PI2_D;
}
} else {
if (y > 0) {
return M_PI - atan(y / -x);
return ECL_PI_D - atan(y / -x);
} else if (y == 0) {
return M_PI;
return ECL_PI_D;
} else {
return -M_PI + atan(-y / -x);
return -ECL_PI_D + atan(-y / -x);
}
}
}
@ -445,19 +438,19 @@ ecl_atan2_long_double(long double y, long double x)
}
} else if (x == 0) {
if (y > 0) {
return M_PI / 2.0;
return ECL_PI2_L;
} else if (y == 0) {
FEerror("Logarithmic singularity.", 0);
} else {
return -M_PI / 2.0;
return -ECL_PI2_L;
}
} else {
if (y > 0) {
return M_PI - atanl(y / -x);
return ECL_PI_L - atanl(y / -x);
} else if (y == 0) {
return M_PI;
return ECL_PI_L;
} else {
return -M_PI + atanl(-y / -x);
return -ECL_PI_L + atanl(-y / -x);
}
}
}

View file

@ -16,22 +16,13 @@
*/
#include <ecl/ecl.h>
#include <math.h>
#include <float.h>
#include <math.h>
#ifdef _MSC_VER
# undef complex
#endif
#include <float.h>
#include <ecl/internal.h>
#ifndef M_PI
# ifdef PI
# define M_PI PI
# else
# define M_PI 3.14159265358979323846
# endif
#endif
cl_fixnum
fixint(cl_object x)
{
@ -604,9 +595,9 @@ init_number(void)
ecl_make_complex(ecl_make_singlefloat(0.0), ecl_make_singlefloat(2.0));
#ifdef ECL_LONG_FLOAT
ECL_SET(@'pi', make_longfloat(M_PI));
ECL_SET(@'pi', make_longfloat((long double)ECL_PI_L));
#else
ECL_SET(@'pi', ecl_make_doublefloat(M_PI));
ECL_SET(@'pi', ecl_make_doublefloat((double)ECL_PI_D));
#endif
init_big();

View file

@ -216,6 +216,11 @@ typedef int fenv_t;
# define fesetenv(bits) _controlfp(*(bits), MCW_EM)
#endif
#define ECL_PI_D 3.14159265358979323846264338327950288
#define ECL_PI_L 3.14159265358979323846264338327950288l
#define ECL_PI2_D 1.57079632679489661923132169163975144
#define ECL_PI2_L 1.57079632679489661923132169163975144l
/*
* Fake several ISO C99 mathematical functions
*/