gcalctool r2277 - trunk/gcalctool
- From: kniederk svn gnome org
- To: svn-commits-list gnome org
- Subject: gcalctool r2277 - trunk/gcalctool
- Date: Tue, 21 Oct 2008 09:03:04 +0000 (UTC)
Author: kniederk
Date: Tue Oct 21 09:03:03 2008
New Revision: 2277
URL: http://svn.gnome.org/viewvc/gcalctool?rev=2277&view=rev
Log:
Cleaned up trigonometric function names and variables within. Added myself to authors (as
told by Robert).
Modified:
trunk/gcalctool/gtk.c
trunk/gcalctool/mp-trigonometric.c
trunk/gcalctool/mp.h
trunk/gcalctool/mpmath.c
Modified: trunk/gcalctool/gtk.c
==============================================================================
--- trunk/gcalctool/gtk.c (original)
+++ trunk/gcalctool/gtk.c Tue Oct 21 09:03:03 2008
@@ -1101,6 +1101,7 @@
"Rich Burridge <rich burridge sun com>",
"Sami Pietila <sampie ariana-dsl utu fi>",
"Robert Ancell <robert ancell gmail com>",
+ "Klaus NiederkrÃger <kniederk umpa ens-lyon fr>",
NULL
};
const gchar *documenters[] = {
Modified: trunk/gcalctool/mp-trigonometric.c
==============================================================================
--- trunk/gcalctool/mp-trigonometric.c (original)
+++ trunk/gcalctool/mp-trigonometric.c Tue Oct 21 09:03:03 2008
@@ -48,8 +48,8 @@
return mp_compare_mp_to_mp(x, &MP.r[MP.t + 4]);
}
-/* COMPUTES Y = SIN(X) IF IS != 0, Y = COS(X) IF IS == 0,
- * USING TAYLOR SERIES. ASSUMES ABS(X) .LE. 1.
+/* COMPUTES Z = SIN(X) IF DO_SIN != 0, Z = COS(X) IF DO_SIN == 0,
+ * USING TAYLOR SERIES. ASSUMES ABS(X) >= 1.
* X AND Y ARE MP NUMBERS, IS AN INTEGER.
* TIME IS O(M(T)T/LOG(T)). THIS COULD BE REDUCED TO
* O(SQRT(T)M(T)) AS IN MPEXP1, BUT NOT WORTHWHILE UNLESS
@@ -60,7 +60,7 @@
* CHECK LEGALITY OF B, T, M AND MXR
*/
static void
-mpsin1(int *x, int *y, int is)
+mpsin1(const int *x, int *z, int do_sin)
{
int i, b2, i2, i3, ts;
@@ -68,9 +68,9 @@
/* SIN(0) = 0, COS(0) = 1 */
if (x[0] == 0) {
- y[0] = 0;
- if (is == 0)
- mp_set_from_integer(1, y);
+ z[0] = 0;
+ if (do_sin == 0)
+ mp_set_from_integer(1, z);
return;
}
@@ -79,19 +79,19 @@
b2 = max(MP.b,64) << 1;
mpmul(x, x, &MP.r[i3 - 1]);
if (mp_compare_mp_to_int(&MP.r[i3 - 1], 1) > 0) {
- mperr("*** ABS(X) .GT. 1 IN CALL TO MPSIN1 ***\n");
+ mperr("*** ABS(X) > 1 IN CALL TO MPSIN1 ***\n");
}
- if (is == 0)
+ if (do_sin == 0)
mp_set_from_integer(1, &MP.r[i2 - 1]);
- if (is != 0)
+ if (do_sin != 0)
mp_set_from_mp(x, &MP.r[i2 - 1]);
- y[0] = 0;
+ z[0] = 0;
i = 1;
ts = MP.t;
- if (is != 0) {
- mp_set_from_mp(&MP.r[i2 - 1], y);
+ if (do_sin != 0) {
+ mp_set_from_mp(&MP.r[i2 - 1], z);
i = 2;
}
@@ -118,25 +118,25 @@
i += 2;
MP.t = ts;
- mpadd2(&MP.r[i2 - 1], y, y, *y, 0);
+ mpadd2(&MP.r[i2 - 1], z, z, *z, 0);
} while(MP.r[i2 - 1] != 0);
MP.t = ts;
- if (is == 0)
- mp_add_integer(y, 1, y);
+ if (do_sin == 0)
+ mp_add_integer(z, 1, z);
}
-/* RETURNS Y = COS(X) FOR MP X AND Y, USING MPSIN AND MPSIN1.
+/* RETURNS Z = COS(X) FOR MP X AND Z, USING MP_SIN AND MPSIN1.
* DIMENSION OF R IN COMMON AT LEAST 5T+12.
*/
void
-mpcos(int *x, int *y)
+mp_cos(const int *x, int *z)
{
int i2;
/* COS(0) = 1 */
if (x[0] == 0) {
- mp_set_from_integer(1, y);
+ mp_set_from_integer(1, z);
return;
}
@@ -145,10 +145,10 @@
i2 = MP.t * 3 + 12;
/* SEE IF ABS(X) <= 1 */
- mp_abs(x, y);
- if (mp_compare_mp_to_int(y, 1) <= 0) {
+ mp_abs(x, z);
+ if (mp_compare_mp_to_int(z, 1) <= 0) {
/* HERE ABS(X) <= 1 SO USE POWER SERIES */
- mpsin1(y, y, 0);
+ mpsin1(z, z, 0);
} else {
/* HERE ABS(X) > 1 SO USE COS(X) = SIN(PI/2 - ABS(X)),
* COMPUTING PI/2 WITH ONE GUARD DIGIT.
@@ -157,8 +157,8 @@
mppi(&MP.r[i2 - 1]);
mpdivi(&MP.r[i2 - 1], 2, &MP.r[i2 - 1]);
--MP.t;
- mp_subtract(&MP.r[i2 - 1], y, y);
- mpsin(y, y);
+ mp_subtract(&MP.r[i2 - 1], z, z);
+ mp_sin(z, z);
}
}
@@ -178,50 +178,49 @@
*/
void
-mpacos(int *MPx, int *MPretval)
+mp_acos(const int *x, int *z)
{
- int MP0[MP_SIZE], MP1[MP_SIZE], MP2[MP_SIZE];
+ int MP1[MP_SIZE], MP2[MP_SIZE];
int MPn1[MP_SIZE], MPpi[MP_SIZE], MPy[MP_SIZE];
mppi(MPpi);
- mp_set_from_integer(0, MP0);
mp_set_from_integer(1, MP1);
mp_set_from_integer(-1, MPn1);
- if (mp_is_greater_than(MPx, MP1) || mp_is_less_than(MPx, MPn1)) {
+ if (mp_is_greater_than(x, MP1) || mp_is_less_than(x, MPn1)) {
doerr(_("Error"));
- mp_set_from_mp(MP0, MPretval);
- } else if (mp_is_equal(MPx, MP0)) {
- mpdivi(MPpi, 2, MPretval);
- } else if (mp_is_equal(MPx, MP1)) {
- mp_set_from_mp(MP0, MPretval);
- } else if (mp_is_equal(MPx, MPn1)) {
- mp_set_from_mp(MPpi, MPretval);
+ z[0] = 0;
+ } else if (x[0] == 0) {
+ mpdivi(MPpi, 2, z);
+ } else if (mp_is_equal(x, MP1)) {
+ z[0] = 0;
+ } else if (mp_is_equal(x, MPn1)) {
+ mp_set_from_mp(MPpi, z);
} else {
- mpmul(MPx, MPx, MP2);
+ mpmul(x, x, MP2);
mp_subtract(MP1, MP2, MP2);
mpsqrt(MP2, MP2);
- mpdiv(MP2, MPx, MP2);
+ mpdiv(MP2, x, MP2);
mp_atan(MP2, MPy);
- if (mp_is_greater_than(MPx, MP0)) {
- mp_set_from_mp(MPy, MPretval);
+ if (x[0] > 0) {
+ mp_set_from_mp(MPy, z);
} else {
- mp_add(MPy, MPpi, MPretval);
+ mp_add(MPy, MPpi, z);
}
}
}
-/* RETURNS Y = COSH(X) FOR MP NUMBERS X AND Y, X NOT TOO LARGE.
+/* RETURNS Z = COSH(X) FOR MP NUMBERS X AND Z, X NOT TOO LARGE.
* USES MPEXP, DIMENSION OF R IN COMMON AT LEAST 5T+12
*/
void
-mpcosh(const int *x, int *y)
+mp_cosh(const int *x, int *z)
{
int i2;
/* COSH(0) == 1 */
if (x[0] == 0) {
- mp_set_from_integer(1, y);
+ mp_set_from_integer(1, z);
return;
}
@@ -235,48 +234,48 @@
*/
MP.m += 2;
mpexp(&MP.r[i2 - 1], &MP.r[i2 - 1]);
- mprec(&MP.r[i2 - 1], y);
- mp_add(&MP.r[i2 - 1], y, y);
+ mprec(&MP.r[i2 - 1], z);
+ mp_add(&MP.r[i2 - 1], z, z);
/* RESTORE M. IF RESULT OVERFLOWS OR UNDERFLOWS, MPDIVI WILL
* ACT ACCORDINGLY.
*/
MP.m += -2;
- mpdivi(y, 2, y);
+ mpdivi(z, 2, z);
}
/* MP precision hyperbolic arc cosine.
*
- * 1. If (x < 1.0) then report DOMAIN error and return 0.0.
+ * 1. If (x < 1) then report DOMAIN error and return 0.
*
* 2. acosh(x) = log(x + sqrt(x**2 - 1))
*/
void
-mpacosh(int *MPx, int *MPretval)
+mp_acosh(const int *x, int *z)
{
int MP1[MP_SIZE];
mp_set_from_integer(1, MP1);
- if (mp_is_less_than(MPx, MP1)) {
+ if (mp_is_less_than(x, MP1)) {
doerr(_("Error"));
- mp_set_from_integer(0, MPretval);
+ mp_set_from_integer(0, z);
} else {
- mpmul(MPx, MPx, MP1);
+ mpmul(x, x, MP1);
mp_add_integer(MP1, -1, MP1);
mpsqrt(MP1, MP1);
- mp_add(MPx, MP1, MP1);
- mpln(MP1, MPretval);
+ mp_add(x, MP1, MP1);
+ mpln(MP1, z);
}
}
-/* RETURNS Y = SIN(X) FOR MP X AND Y,
+/* RETURNS Z = SIN(X) FOR MP X AND Z,
* METHOD IS TO REDUCE X TO (-1, 1) AND USE MPSIN1, SO
* TIME IS O(M(T)T/LOG(T)).
* DIMENSION OF R IN CALLING PROGRAM MUST BE AT LEAST 5T+12
* CHECK LEGALITY OF B, T, M AND MXR
*/
void
-mpsin(int *x, int *y)
+mp_sin(const int *x, int *z)
{
int i2, i3, ie, xs;
float rx = 0.0, ry;
@@ -285,7 +284,7 @@
i2 = (MP.t << 2) + 11;
if (x[0] == 0) {
- y[0] = 0;
+ z[0] = 0;
return;
}
@@ -296,10 +295,10 @@
mp_abs(x, &MP.r[i2 - 1]);
- /* USE MPSIN1 IF ABS(X) .LE. 1 */
+ /* USE MPSIN1 IF ABS(X) <= 1 */
if (mp_compare_mp_to_int(&MP.r[i2 - 1], 1) <= 0)
{
- mpsin1(&MP.r[i2 - 1], y, 1);
+ mpsin1(&MP.r[i2 - 1], z, 1);
}
/* FIND ABS(X) MODULO 2PI (IT WOULD SAVE TIME IF PI WERE
* PRECOMPUTED AND SAVED IN COMMON).
@@ -309,9 +308,9 @@
i3 = (MP.t << 1) + 7;
mpart1(5, &MP.r[i3 - 1]);
mpmuli(&MP.r[i3 - 1], 4, &MP.r[i3 - 1]);
- mpart1(239, y);
- mp_subtract(&MP.r[i3 - 1], y, y);
- mpdiv(&MP.r[i2 - 1], y, &MP.r[i2 - 1]);
+ mpart1(239, z);
+ mp_subtract(&MP.r[i3 - 1], z, z);
+ mpdiv(&MP.r[i2 - 1], z, &MP.r[i2 - 1]);
mpdivi(&MP.r[i2 - 1], 8, &MP.r[i2 - 1]);
mpcmf(&MP.r[i2 - 1], &MP.r[i2 - 1]);
@@ -319,7 +318,7 @@
mp_add_fraction(&MP.r[i2 - 1], -1, 2, &MP.r[i2 - 1]);
xs = -xs * MP.r[i2 - 1];
if (xs == 0) {
- y[0] = 0;
+ z[0] = 0;
return;
}
@@ -331,7 +330,7 @@
mp_add_integer(&MP.r[i2 - 1], -2, &MP.r[i2 - 1]);
if (MP.r[i2 - 1] == 0) {
- y[0] = 0;
+ z[0] = 0;
return;
}
@@ -343,25 +342,25 @@
*/
if (MP.r[i2] > 0) {
mp_add_integer(&MP.r[i2 - 1], -2, &MP.r[i2 - 1]);
- mpmul(&MP.r[i2 - 1], y, &MP.r[i2 - 1]);
- mpsin1(&MP.r[i2 - 1], y, 0);
+ mpmul(&MP.r[i2 - 1], z, &MP.r[i2 - 1]);
+ mpsin1(&MP.r[i2 - 1], z, 0);
} else {
- mpmul(&MP.r[i2 - 1], y, &MP.r[i2 - 1]);
- mpsin1(&MP.r[i2 - 1], y, 1);
+ mpmul(&MP.r[i2 - 1], z, &MP.r[i2 - 1]);
+ mpsin1(&MP.r[i2 - 1], z, 1);
}
}
- y[0] = xs;
+ z[0] = xs;
if (ie > 2)
return;
- /* CHECK THAT ABSOLUTE ERROR LESS THAN 0.01 IF ABS(X) .LE. 100
+ /* CHECK THAT ABSOLUTE ERROR LESS THAN 0.01 IF ABS(X) <= 100
* (IF ABS(X) IS LARGE THEN SINGLE-PRECISION SIN INACCURATE)
*/
if (fabs(rx) > (float)100.)
return;
- ry = mp_cast_to_float(y);
+ ry = mp_cast_to_float(z);
if (fabs(ry - sin(rx)) < (float) 0.01)
return;
@@ -371,22 +370,22 @@
mperr("*** ERROR OCCURRED IN MPSIN, RESULT INCORRECT ***\n");
}
-/* RETURNS Y = ARCSIN(X), ASSUMING ABS(X) <= 1,
- * FOR MP NUMBERS X AND Y.
- * Y IS IN THE RANGE -PI/2 TO +PI/2.
+/* RETURNS Z = ARCSIN(X), ASSUMING ABS(X) <= 1,
+ * FOR MP NUMBERS X AND Z.
+ * Z IS IN THE RANGE -PI/2 TO +PI/2.
* METHOD IS TO USE MP_ATAN, SO TIME IS O(M(T)T).
* DIMENSION OF R MUST BE AT LEAST 5T+12
* CHECK LEGALITY OF B, T, M AND MXR
*/
void
-mpasin(int *x, int *y)
+mp_asin(const int *x, int *z)
{
int i2, i3;
mpchk(5, 12);
i3 = (MP.t << 2) + 11;
if (x[0] == 0) {
- y[0] = 0;
+ z[0] = 0;
return;
}
@@ -399,8 +398,8 @@
mp_add(&MP.r[i3 - 1], x, &MP.r[i3 - 1]);
mpmul(&MP.r[i2 - 1], &MP.r[i3 - 1], &MP.r[i3 - 1]);
mproot(&MP.r[i3 - 1], -2, &MP.r[i3 - 1]);
- mpmul(x, &MP.r[i3 - 1], y);
- mp_atan(y, y);
+ mpmul(x, &MP.r[i3 - 1], z);
+ mp_atan(z, z);
return;
}
@@ -411,22 +410,22 @@
}
/* X == +-1 SO RETURN +-PI/2 */
- mppi(y);
- mpdivi(y, MP.r[i3 - 1] << 1, y);
+ mppi(z);
+ mpdivi(z, MP.r[i3 - 1] << 1, z);
}
-/* RETURNS Y = SINH(X) FOR MP NUMBERS X AND Y, X NOT TOO LARGE.
+/* RETURNS Z = SINH(X) FOR MP NUMBERS X AND Z, X NOT TOO LARGE.
* METHOD IS TO USE MPEXP OR MPEXP1, SPACE = 5T+12
* SAVE SIGN OF X AND CHECK FOR ZERO, SINH(0) = 0
*/
void
-mpsinh(int *x, int *y)
+mp_sinh(const int *x, int *z)
{
int i2, i3, xs;
xs = x[0];
if (xs == 0) {
- y[0] = 0;
+ z[0] = 0;
return;
}
@@ -437,23 +436,23 @@
/* WORK WITH ABS(X) */
mp_abs(x, &MP.r[i3 - 1]);
- /* HERE ABS(X) .LT. 1 SO USE MPEXP1 TO AVOID CANCELLATION */
+ /* HERE ABS(X) < 1 SO USE MPEXP1 TO AVOID CANCELLATION */
if (MP.r[i3] <= 0) {
i2 = i3 - (MP.t + 2);
mpexp1(&MP.r[i3 - 1], &MP.r[i2 - 1]);
mp_add_integer(&MP.r[i2 - 1], 2, &MP.r[i3 - 1]);
- mpmul(&MP.r[i3 - 1], &MP.r[i2 - 1], y);
+ mpmul(&MP.r[i3 - 1], &MP.r[i2 - 1], z);
mp_add_integer(&MP.r[i2 - 1], 1, &MP.r[i3 - 1]);
- mpdiv(y, &MP.r[i3 - 1], y);
+ mpdiv(z, &MP.r[i3 - 1], z);
}
- /* HERE ABS(X) .GE. 1, IF TOO LARGE MPEXP GIVES ERROR MESSAGE
+ /* HERE ABS(X) >= 1, IF TOO LARGE MPEXP GIVES ERROR MESSAGE
* INCREASE M TO AVOID OVERFLOW IF SINH(X) REPRESENTABLE
*/
else {
MP.m += 2;
mpexp(&MP.r[i3 - 1], &MP.r[i3 - 1]);
- mprec(&MP.r[i3 - 1], y);
- mp_subtract(&MP.r[i3 - 1], y, y);
+ mprec(&MP.r[i3 - 1], z);
+ mp_subtract(&MP.r[i3 - 1], z, z);
/* RESTORE M. IF RESULT OVERFLOWS OR UNDERFLOWS, MPDIVI AT
* STATEMENT 30 WILL ACT ACCORDINGLY.
@@ -462,7 +461,7 @@
}
/* DIVIDE BY TWO AND RESTORE SIGN */
- mpdivi(y, xs << 1, y);
+ mpdivi(z, xs << 1, z);
}
/* MP precision hyperbolic arc sine.
@@ -471,36 +470,35 @@
*/
void
-mpasinh(int *MPx, int *MPretval)
+mp_asinh(const int *x, int *z)
{
int MP1[MP_SIZE];
- mpmul(MPx, MPx, MP1);
+ mpmul(x, x, MP1);
mp_add_integer(MP1, 1, MP1);
mpsqrt(MP1, MP1);
- mp_add(MPx, MP1, MP1);
- mpln(MP1, MPretval);
+ mp_add(x, MP1, MP1);
+ mpln(MP1, z);
}
void
-mptan(int s1[MP_SIZE], int t1[MP_SIZE])
+mp_tan(const int x[MP_SIZE], int z[MP_SIZE])
{
int MPcos[MP_SIZE];
int MPsin[MP_SIZE];
- double cval;
- mpsin(s1, MPsin);
- mpcos(s1, MPcos);
- cval = mp_cast_to_double(MPcos);
- if (cval == 0.0) {
+ mp_sin(x, MPsin);
+ mp_cos(x, MPcos);
+ /* Check if COS(x) == 0 */
+ if (MPcos[0] == 0) {
doerr(_("Error, cannot calculate cosine"));
}
- mpdiv(MPsin, MPcos, t1);
+ mpdiv(MPsin, MPcos, z);
}
-/* RETURNS Y = ARCTAN(X) FOR MP X AND Y, USING AN O(T.M(T)) METHOD
+/* RETURNS Z = ARCTAN(X) FOR MP X AND Z, USING AN O(T.M(T)) METHOD
* WHICH COULD EASILY BE MODIFIED TO AN O(SQRT(T)M(T))
- * METHOD (AS IN MPEXP1). Y IS IN THE RANGE -PI/2 TO +PI/2.
+ * METHOD (AS IN MPEXP1). Z IS IN THE RANGE -PI/2 TO +PI/2.
* FOR AN ASYMPTOTICALLY FASTER METHOD, SEE - FAST MULTIPLE-
* PRECISION EVALUATION OF ELEMENTARY FUNCTIONS
* (BY R. P. BRENT), J. ACM 23 (1976), 242-251,
@@ -509,7 +507,7 @@
* CHECK LEGALITY OF B, T, M AND MXR
*/
void
-mp_atan(const int *x, int *y)
+mp_atan(const int *x, int *z)
{
int i, q, i2, i3, ts;
float rx = 0.0, ry;
@@ -519,7 +517,7 @@
i2 = MP.t * 3 + 9;
i3 = i2 + MP.t + 2;
if (x[0] == 0) {
- y[0] = 0;
+ z[0] = 0;
return;
}
@@ -536,15 +534,15 @@
break;
q <<= 1;
- mpmul(&MP.r[i3 - 1], &MP.r[i3 - 1], y);
- mp_add_integer(y, 1, y);
- mpsqrt(y, y);
- mp_add_integer(y, 1, y);
- mpdiv(&MP.r[i3 - 1], y, &MP.r[i3 - 1]);
+ mpmul(&MP.r[i3 - 1], &MP.r[i3 - 1], z);
+ mp_add_integer(z, 1, z);
+ mpsqrt(z, z);
+ mp_add_integer(z, 1, z);
+ mpdiv(&MP.r[i3 - 1], z, &MP.r[i3 - 1]);
}
/* USE POWER SERIES NOW ARGUMENT IN (-0.5, 0.5) */
- mp_set_from_mp(&MP.r[i3 - 1], y);
+ mp_set_from_mp(&MP.r[i3 - 1], z);
mpmul(&MP.r[i3 - 1], &MP.r[i3 - 1], &MP.r[i2 - 1]);
i = 1;
ts = MP.t;
@@ -556,13 +554,13 @@
mpmulq(&MP.r[i3 - 1], -i, i + 2, &MP.r[i3 - 1]);
i += 2;
MP.t = ts;
- mp_add(y, &MP.r[i3 - 1], y);
+ mp_add(z, &MP.r[i3 - 1], z);
if (MP.r[i3 - 1] == 0) break;
}
/* RESTORE T, CORRECT FOR ARGUMENT REDUCTION, AND EXIT */
MP.t = ts;
- mpmuli(y, q, y);
+ mpmuli(z, q, z);
/* CHECK THAT RELATIVE ERROR LESS THAN 0.01 UNLESS EXPONENT
* OF X IS LARGE (WHEN ATAN MIGHT NOT WORK)
@@ -570,7 +568,7 @@
if (abs(x[1]) > 2)
return;
- ry = mp_cast_to_float(y);
+ ry = mp_cast_to_float(z);
if (fabs(ry - atan(rx)) < fabs(ry) * (float).01)
return;
@@ -578,11 +576,11 @@
mperr("*** ERROR OCCURRED IN MP_ATAN, RESULT INCORRECT ***\n");
}
-/* RETURNS Y = TANH(X) FOR MP NUMBERS X AND Y,
+/* RETURNS Z = TANH(X) FOR MP NUMBERS X AND Z,
* USING MPEXP OR MPEXP1, SPACE = 5T+12
*/
void
-mptanh(int *x, int *y)
+mp_tanh(const int *x, int *z)
{
float r__1;
@@ -590,7 +588,7 @@
/* TANH(0) = 0 */
if (x[0] == 0) {
- y[0] = 0;
+ z[0] = 0;
return;
}
@@ -604,58 +602,57 @@
/* SEE IF ABS(X) SO LARGE THAT RESULT IS +-1 */
r__1 = (float) MP.t * (float).5 * log((float) MP.b);
- mp_set_from_float(r__1, y);
- if (mp_compare_mp_to_mp(&MP.r[i2 - 1], y) > 0) {
+ mp_set_from_float(r__1, z);
+ if (mp_compare_mp_to_mp(&MP.r[i2 - 1], z) > 0) {
/* HERE ABS(X) IS VERY LARGE */
- mp_set_from_integer(xs, y);
+ mp_set_from_integer(xs, z);
return;
}
/* HERE ABS(X) NOT SO LARGE */
mpmuli(&MP.r[i2 - 1], 2, &MP.r[i2 - 1]);
if (MP.r[i2] > 0) {
- /* HERE ABS(X) .GE. 1/2 SO USE MPEXP */
+ /* HERE ABS(X) >= 1/2 SO USE MPEXP */
mpexp(&MP.r[i2 - 1], &MP.r[i2 - 1]);
- mp_add_integer(&MP.r[i2 - 1], -1, y);
+ mp_add_integer(&MP.r[i2 - 1], -1, z);
mp_add_integer(&MP.r[i2 - 1], 1, &MP.r[i2 - 1]);
- mpdiv(y, &MP.r[i2 - 1], y);
+ mpdiv(z, &MP.r[i2 - 1], z);
} else {
- /* HERE ABS(X) .LT. 1/2, SO USE MPEXP1 TO AVOID CANCELLATION */
+ /* HERE ABS(X) < 1/2, SO USE MPEXP1 TO AVOID CANCELLATION */
mpexp1(&MP.r[i2 - 1], &MP.r[i2 - 1]);
- mp_add_integer(&MP.r[i2 - 1], 2, y);
- mpdiv(&MP.r[i2 - 1], y, y);
+ mp_add_integer(&MP.r[i2 - 1], 2, z);
+ mpdiv(&MP.r[i2 - 1], z, z);
}
/* RESTORE SIGN */
- y[0] = xs * y[0];
+ z[0] = xs * z[0];
}
/* MP precision hyperbolic arc tangent.
*
- * 1. If (x <= -1.0 or x >= 1.0) then report a DOMAIn error and return 0.0.
+ * 1. If (x <= -1 or x >= 1) then report a DOMAIN error and return 0.
*
* 2. atanh(x) = 0.5 * log((1 + x) / (1 - x))
*/
void
-mpatanh(int *MPx, int *MPretval)
+mp_atanh(const int *x, int *z)
{
- int MP0[MP_SIZE], MP1[MP_SIZE], MP2[MP_SIZE];
+ int MP1[MP_SIZE], MP2[MP_SIZE];
int MP3[MP_SIZE], MPn1[MP_SIZE];
- mp_set_from_integer(0, MP0);
mp_set_from_integer(1, MP1);
mp_set_from_integer(-1, MPn1);
- if (mp_is_greater_equal(MPx, MP1) || mp_is_less_equal(MPx, MPn1)) {
+ if (mp_is_greater_equal(x, MP1) || mp_is_less_equal(x, MPn1)) {
doerr(_("Error"));
- mp_set_from_mp(MP0, MPretval);
+ z[0] = 0;
} else {
- mp_add(MP1, MPx, MP2);
- mp_subtract(MP1, MPx, MP3);
+ mp_add(MP1, x, MP2);
+ mp_subtract(MP1, x, MP3);
mpdiv(MP2, MP3, MP3);
mpln(MP3, MP3);
MPstr_to_num("0.5", 10, MP1);
- mpmul(MP1, MP3, MPretval);
+ mpmul(MP1, MP3, z);
}
}
Modified: trunk/gcalctool/mp.h
==============================================================================
--- trunk/gcalctool/mp.h (original)
+++ trunk/gcalctool/mp.h Tue Oct 21 09:03:03 2008
@@ -93,18 +93,18 @@
void mp_set_from_string(const char *number, int base, int t[MP_SIZE]);
/* mp-trigonometric.c */
-void mpcos(int *x, int *y);
-void mpcosh(const int *x, int *y);
-void mpsin(int *x, int *y);
-void mpasin(int *, int *);
-void mpsinh(int *x, int *y);
-void mpasinh(int *MPx, int *MPretval);
-void mpacosh(int *MPx, int *MPretval);
-void mpacos(int *MPx, int *MPretval);
-void mptan(int *s1, int *t1);
-void mp_atan(const int *, int *);
-void mptanh(int *x, int *y);
-void mpatanh(int *MPx, int *MPretval);
+void mp_cos(const int *x, int *z);
+void mp_cosh(const int *x, int *z);
+void mp_sin(const int *x, int *z);
+void mp_asin(const int *x, int *z);
+void mp_sinh(const int *x, int *z);
+void mp_asinh(const int *x, int *z);
+void mp_acosh(const int *x, int *z);
+void mp_acos(const int *x, int *z);
+void mp_tan(const int *x, int *z);
+void mp_atan(const int *x, int *z);
+void mp_tanh(const int *x, int *z);
+void mp_atanh(const int *x, int *z);
#endif /* MP_H */
Modified: trunk/gcalctool/mpmath.c
==============================================================================
--- trunk/gcalctool/mpmath.c (original)
+++ trunk/gcalctool/mpmath.c Tue Oct 21 09:03:03 2008
@@ -371,38 +371,38 @@
switch (type) {
case sin_t:
to_rad(s1, s1);
- mpsin(s1, t1);
+ mp_sin(s1, t1);
break;
case cos_t:
to_rad(s1, s1);
- mpcos(s1, t1);
+ mp_cos(s1, t1);
break;
case tan_t:
to_rad(s1, s1);
- mptan(s1, t1);
+ mp_tan(s1, t1);
break;
case sinh_t:
- mpsinh(s1, t1);
+ mp_sinh(s1, t1);
break;
case cosh_t:
- mpcosh(s1, t1);
+ mp_cosh(s1, t1);
break;
case tanh_t:
- mptanh(s1, t1);
+ mp_tanh(s1, t1);
break;
case asin_t:
- mpasin(s1, t1);
+ mp_asin(s1, t1);
do_trig_typeconv(v->ttype, t1, t1);
break;
case acos_t:
- mpacos(s1, t1);
+ mp_acos(s1, t1);
do_trig_typeconv(v->ttype, t1, t1);
break;
@@ -412,15 +412,15 @@
break;
case asinh_t:
- mpasinh(s1, t1);
+ mp_asinh(s1, t1);
break;
case acosh_t:
- mpacosh(s1, t1);
+ mp_acosh(s1, t1);
break;
case atanh_t:
- mpatanh(s1, t1);
+ mp_atanh(s1, t1);
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]