⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rr.h

📁 NTL is a high-performance, portable C++ library providing data structures and algorithms for manipul
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifndef NTL_RR__H
#define NTL_RR__H

#include <NTL/ZZ.h>
#include <NTL/xdouble.h>
#include <NTL/quad_float.h>

NTL_OPEN_NNS


class RR {

public:

ZZ x;
long e;

RR() {  e = 0; }

inline RR(INIT_VAL_TYPE, const ZZ& a);
inline RR(INIT_VAL_TYPE, int a);
inline RR(INIT_VAL_TYPE, long a);
inline RR(INIT_VAL_TYPE, unsigned int a);
inline RR(INIT_VAL_TYPE, unsigned long a);
inline RR(INIT_VAL_TYPE, float a);
inline RR(INIT_VAL_TYPE, double a);
inline RR(INIT_VAL_TYPE, const xdouble& a);
inline RR(INIT_VAL_TYPE, const quad_float& a);
inline RR(INIT_VAL_TYPE, const char *a);  // read from string
inline RR(INIT_VAL_TYPE, const RR& a);


inline RR& operator=(double a);

RR(RR& z, INIT_TRANS_TYPE) : x(z.x, INIT_TRANS), e(z.e) { } 





~RR() { }

const ZZ& mantissa() const { return x; }
long exponent() const { return e; }

static long prec;
static void SetPrecision(long p);
static long precision() { return prec; }

static long oprec;
static void SetOutputPrecision(long p);
static long OutputPrecision() { return oprec; }

#ifdef NTL_TRANSITION
private:
RR& operator=(const RR&);
RR(const RR&);
#endif

};


long IsZero(const RR& a);
long IsOne(const RR& a);
long sign(const RR& a);
void clear(RR& z);
void set(RR& z);
void swap(RR& a, RR& b);

void add(RR& z, const RR& a, const RR& b);

void add(RR& z, const RR& a, double b);
inline void add(RR& z, double a, const RR& b) { add(z, b, a); }



void sub(RR& z, const RR& a, const RR& b);

void sub(RR& z, const RR& a, double b);
void sub(RR& z, double a, const RR& b);

void negate(RR& z, const RR& a);

void abs(RR& z, const RR& a);
inline RR abs(const RR& a)
   { RR z; abs(z, a); NTL_OPT_RETURN(RR, z); }
inline RR fabs(const RR& a)
   { RR z; abs(z, a); NTL_OPT_RETURN(RR, z); }

void mul(RR& z, const RR& a, const RR& b);

void mul(RR& z, const RR& a, double b);
inline void mul(RR& z, double a, const RR& b) { mul(z, b, a); }

void sqr(RR& z, const RR& a);
inline RR sqr(const RR& a)
   { RR z; sqr(z, a); NTL_OPT_RETURN(RR, z); }

void div(RR& z, const RR& a, const RR& b);

void div(RR& z, const RR& a, double b);
void div(RR& z, double a, const RR& b);

void inv(RR& z, const RR& a);
inline RR inv(const RR& a)
   { RR z; inv(z, a); NTL_OPT_RETURN(RR, z); }

// operator notation:

inline RR operator+(const RR& a, const RR& b)
   { RR x; add(x, a, b); NTL_OPT_RETURN(RR, x); }

inline RR operator+(const RR& a, double b)
   { RR x; add(x, a, b); NTL_OPT_RETURN(RR, x); }

inline RR operator+(double a, const RR& b)
   { RR x; add(x, a, b); NTL_OPT_RETURN(RR, x); }

inline RR& operator+=(RR& x, const RR& b)
   { add(x, x, b); return x; } 

inline RR& operator+=(RR& x, double b)
   { add(x, x, b); return x; } 



inline RR operator-(const RR& a, const RR& b)
   { RR x; sub(x, a, b); NTL_OPT_RETURN(RR, x); }

inline RR operator-(const RR& a, double b)
   { RR x; sub(x, a, b); NTL_OPT_RETURN(RR, x); }

inline RR operator-(double a, const RR& b)
   { RR x; sub(x, a, b); NTL_OPT_RETURN(RR, x); }

inline RR& operator-=(RR& x, const RR& b)
   { sub(x, x, b); return x; } 

inline RR& operator-=(RR& x, double b)
   { sub(x, x, b); return x; } 



inline RR operator*(const RR& a, const RR& b)
   { RR x; mul(x, a, b); NTL_OPT_RETURN(RR, x); }

inline RR operator*(const RR& a, double b)
   { RR x; mul(x, a, b); NTL_OPT_RETURN(RR, x); }

inline RR operator*(double a, const RR& b)
   { RR x; mul(x, a, b); NTL_OPT_RETURN(RR, x); }

inline RR& operator*=(RR& x, const RR& b)
   { mul(x, x, b); return x; } 

inline RR& operator*=(RR& x, double b)
   { mul(x, x, b); return x; } 


inline RR operator/(const RR& a, const RR& b)
   { RR x; div(x, a, b); NTL_OPT_RETURN(RR, x); }

inline RR operator/(const RR& a, double b)
   { RR x; div(x, a, b); NTL_OPT_RETURN(RR, x); }

inline RR operator/(double a, const RR& b)
   { RR x; div(x, a, b); NTL_OPT_RETURN(RR, x); }

inline RR& operator/=(RR& x, const RR& b)
   { div(x, x, b); return x; } 

inline RR& operator/=(RR& x, double b)
   { div(x, x, b); return x; } 


inline RR operator-(const RR& a)
   { RR x; negate(x, a); NTL_OPT_RETURN(RR, x); }


inline RR& operator++(RR& x) { add(x, x, 1); return x; }
inline void operator++(RR& x, int) { add(x, x, 1); }
inline RR& operator--(RR& x) { sub(x, x, 1); return x; }
inline void operator--(RR& x, int) { sub(x, x, 1); }



long compare(const RR& a, const RR& b);

long compare(const RR& a, double b);
inline long compare(double a, const RR& b) { return -compare(b, a); }


long operator==(const RR& a, const RR& b);
inline long operator!=(const RR& a, const RR& b) { return !(a == b); }
inline long operator<=(const RR& a, const RR& b) { return compare(a, b) <= 0; }
inline long operator>=(const RR& a, const RR& b) { return compare(a, b) >= 0; }
inline long operator <(const RR& a, const RR& b) { return compare(a, b)  < 0; }
inline long operator >(const RR& a, const RR& b) { return compare(a, b)  > 0; }

long operator==(const RR& a, double b);
inline long operator!=(const RR& a, double b) { return !(a == b); }
inline long operator<=(const RR& a, double b) { return compare(a, b) <= 0; }
inline long operator>=(const RR& a, double b) { return compare(a, b) >= 0; }
inline long operator <(const RR& a, double b) { return compare(a, b)  < 0; }
inline long operator >(const RR& a, double b) { return compare(a, b)  > 0; }

inline long operator==(double a, const RR& b) { return (b == a); }
inline long operator!=(double a, const RR& b) { return !(a == b); }
inline long operator<=(double a, const RR& b) { return compare(a, b) <= 0; }
inline long operator>=(double a, const RR& b) { return compare(a, b) >= 0; }
inline long operator <(double a, const RR& b) { return compare(a, b)  < 0; }
inline long operator >(double a, const RR& b) { return compare(a, b)  > 0; }

void ceil(RR& z, const RR& a);
inline RR ceil(const RR& a)
   { RR z; ceil(z, a); NTL_OPT_RETURN(RR, z); }

void floor(RR& z, const RR& a);
inline RR floor(const RR& a)
   { RR z; floor(z, a); NTL_OPT_RETURN(RR, z); }

void trunc(RR& z, const RR& a);
inline RR trunc(const RR& a)
   { RR z; trunc(z, a); NTL_OPT_RETURN(RR, z); }

void round(RR& z, const RR& a);
inline RR round(const RR& a)
   { RR z; round(z, a); NTL_OPT_RETURN(RR, z); }

void RoundToPrecision(RR& z, const RR& a, long p);
inline RR RoundToPrecision(const RR& a, long p)
   { RR z; RoundToPrecision(z, a, p); NTL_OPT_RETURN(RR, z); }


// routines with a precision parameter

void ConvPrec(RR& z, const RR& a, long p);
inline RR ConvPrec(const RR& a, long p)
   { RR z; ConvPrec(z, a, p); NTL_OPT_RETURN(RR, z); }

void AddPrec(RR& z, const RR& a, const RR& b, long p);
inline RR AddPrec(const RR& a, const RR& b, long p)
   { RR z; AddPrec(z, a, b, p); NTL_OPT_RETURN(RR, z); }

void SubPrec(RR& z, const RR& a, const RR& b, long p);
inline RR SubPrec(const RR& a, const RR& b, long p)
   { RR z; SubPrec(z, a, b, p); NTL_OPT_RETURN(RR, z); }

void NegatePrec(RR& z, const RR& a, long p);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -