Thanks Adam Majewski, marcm200 and 3DickUlus.
I guess I didn't explain very well what I was asking. It's not the arithmetic functions, but the arithmetic operators.
These operators allow one to do arithmetic like:
int init_big_Formula_74()
{
if (!juliaflag)
zBig = qBig;
zBig.x += param[0];
zBig.y += param[1];
return 0;
}
int do_big_Formula_74() // Flarium 106
{
double d;
BigComplex z1, z3, zd, a;
z1 = zBig;
z3 = zBig.CCube();
a = 1;
zBig=((a-zBig-z3*zBig)/(zBig-(z3*4))-zBig)*qBig; // sort of a good one
zd = zBig-z1;
d = zd.CSumSqr();
return (d < MINSIZE);
}
The problem to make a library for normal arithmetic operations on complex MPFR variables. Here is BigComplex class for the arithmetic operators that works well when I don't use multi-threading:
// BigComplex.h: interface for the Complex Bignum class.
//
//////////////////////////////////////////////////////////////////////
#pragma once
#include <math.h>
#include "BigDouble.h"
#include "Complex.h"
#define FALSE 0
#define TRUE 1
#define zerotol 1.e-50
#define BYTE unsigned char
class BigComplex
{
public:
BigComplex(void) { }
BigComplex(const BigDouble & real, const BigDouble & imaginary)
{
x = real;
y = imaginary;
}
BigComplex(const BigComplex & Cmplx1)// Copy Constructor
{
mpfr_set(x.x, Cmplx1.x.x, MPFR_RNDN);
mpfr_set(y.x, Cmplx1.y.x, MPFR_RNDN);
}
BigComplex(const BigDouble & value)
{
x = value;
y = 0;
}
~BigComplex(void);
inline BigComplex * operator =(const BigComplex &); // Assignment Operator
inline BigComplex * operator =(const BigDouble &); // Assignment to a big double Operator
BigComplex * operator =(const Complex &); // Assignment to a complex Operator
BigComplex * operator =(const double &); // Assignment to a double Operator
BigComplex * operator+=(const BigComplex &);
BigComplex * operator+=(BigDouble&);
BigComplex * operator-=(const BigComplex &);
BigComplex * operator-=(BigDouble &);
BigComplex * operator*=(const BigComplex &);
BigComplex * operator*=(BigDouble &);
BigComplex * operator++(void); // prefix ++ operator
bool operator==(BigComplex &);
BigComplex operator^(BigDouble &);
BigComplex operator^(BigComplex &);
BigComplex operator^(BYTE &);
BigComplex operator +(const BigComplex &); // Addition Operator
BigComplex operator +(const BigDouble &); // complex add by double Operator
BigComplex operator -(const BigComplex &); // Subtraction Operator
BigComplex operator -(const BigDouble &); // complex subtract by double Operator
BigComplex operator -(void); // unary minus
BigComplex operator *(const BigComplex &); // Multiplication Operator
BigComplex operator *(const BigDouble &); // complex multiply by double Operator
BigComplex operator /(const BigComplex &); // Division Operator
BigComplex operator /(const BigDouble &); // complex divide by double Operator
BigComplex CSqr(void); // square
BigComplex CCube(void); // cube
BigComplex CInvert(void); // invert
double CSumSqr(void); // real squared + imaginary squared
BigComplex CPolynomial(int); // take a complex number to an integer power
BigComplex CSin(void); // sine of a complex number
BigComplex CCos(void); // cosine
BigComplex CTan(); // tangent
BigComplex CSinh(); // hyperbolic sine of a complex number
BigComplex CCosh(); // hyperbolic cosine
BigComplex CTanh(); // hyperbolic tangent
BigComplex CExp(void); // exponent
BigComplex CDouble(void); // double r = 2*n
BigComplex CHalf(void); // half r = n/2
BigComplex CLog(void); // log
BigDouble CFabs(void); // abs
BigComplex BigComplexPower(BigComplex &); // a^b
BigDouble x, y;
};
Here is the BigDouble class:
// BigDouble.h: interface for the Bignum class.
//
//////////////////////////////////////////////////////////////////////
#pragma once
#include <math.h>
#include "mpfr.h"
#define FALSE 0
#define TRUE 1
#define zerotol 1.e-50 // 1.e-14
#define SAFETYMARGIN 5 // Multiply number of digits by a safety margin
extern int decimals;
class BigDouble
{
public:
BigDouble(void);
~BigDouble(void);
BigDouble(const double & value)
{
bitcount = decimals * SAFETYMARGIN;
mpfr_init2(x, bitcount);
mpfr_set_d(x, value, MPFR_RNDN);
}
BigDouble(const BigDouble & Big) // Copy Constructor
{
bitcount = decimals * SAFETYMARGIN;
mpfr_init2(x, bitcount);
mpfr_set(x, Big.x, MPFR_RNDN);
}
BigDouble * operator =(const BigDouble &); // Assignment Operator
BigDouble * operator =(const double &); // Assignment to a double Operator
BigDouble * operator+=(const BigDouble &);
BigDouble * operator+=(double&);
BigDouble * operator-=(const BigDouble &);
BigDouble * operator-=(double &);
BigDouble * operator*=(const BigDouble &);
BigDouble * operator*=(double &);
BigDouble BigSqr(void); // square is faster than * because of symmetry
BigDouble BigSqrt(void); // square root
BigDouble BigInvert(void); // invert
BigDouble BigAbs(void); // abs()
BigDouble BigX2(void); // double r = 2*n
BigDouble BigHalf(void); // half r - n/2
BigDouble BigCos(); // cos
BigDouble BigSin(); // sin
BigDouble BigTan(); // tan
BigDouble BigSinh(); // sinh
BigDouble BigCosh(); // cosh
BigDouble BigTanh(); // tanh
BigDouble BigLog(); // log
BigDouble BigLog10(); // log10
long BigDoubleToInt(void); // convert a big double to int
double BigDoubleToDouble(void); // convert a big double to double
int ChangePrecision(int n); // increase precision to n digits -1 means precision is out of range
BigDouble operator +(const BigDouble &); // Addition Operator
BigDouble operator +(const double &); // add to double Operator
BigDouble operator -(const BigDouble &); // Subtraction Operator
BigDouble operator -(const double &); // subtract from double Operator
BigDouble operator -(void); // unary minus
BigDouble operator *(const BigDouble &); // Multiplication Operator
BigDouble operator *(const double &); // Multiply by double Operator
BigDouble operator /(const BigDouble &); // Division Operator
BigDouble operator /(const double &); // divide by double Operator
bool operator==(BigDouble &);
bool operator<(BigDouble &);
bool operator>(BigDouble &);
bool operator==(double &);
bool operator<(double &);
bool operator>(double &);
mpfr_t x; // pointer to BigNum
mpfr_prec_t bitcount;
};
I would like to know if there is a library of these complex operations on MPFR. Does this make sense?
Thanks.