Multi-Precision Arithmetic by C++ with no use of assembler
SN library Copyright (C) 1999-2018 K.Tsuru

Reference of class functions part 5


7. SDouble class's member and friend functions
The prototype declarations are given in "sdbl.h". This class is derived from "SNumber" class by "public" and "SCalcInfo" structure by "public virtual". It is a multi-precision real number class with the radix DRADIX = 10,000.
The inner expression in the floating point mode (called as "standard" form) is as follows

[+|-]f[0].f[1]...f[ef]...f[ef +h]...f[s-1]*DRADIX^rdxExp (f[0]=0, f[1]>0)

where "ef" is the number of significant figures and "rdxExp" is a private member and holds the exponent value. Last 'h' figures are assigned to the hidden precision. In the fixed point mode it is

[+|-]f[0].f[1]...f[ef]...f[s-1]*DRADIX^fixedExp (f[0]=f[1]=...=f[aHead-1]=0)

where "fixedExp" is a static private member and holds the fixed exponent value.
A part of functions below cannot be called by derived "SDecimal" class object. They are commented as "SDouble only". 

Constructors
form
SDouble(); default constructor
SDouble(double d);
SDouble(const char* s);
SDouble(const SLong& sl); This is necessary to convert SD*SL into SD*SD.
SDouble(NumberType tp, uint vsz);
Give 'tp' 'REAL'(SDouble) or 'BIN_DEC'(SDecimal) and 'vsz' size of figure[] which will be necessary. See also "FigureAlloc()".
If vsz > 0, it is initialized by zero.
If vsz > minArraySize, it takes into fixed point and irreducible size mode.
SDouble(const SDouble& a); copy constructor
SDouble(const SFraction& sf); Constructor for conversion SFraction into SDouble.
It will be natural to convert SD*SF into SD*SD.

substitution operators
form
SDouble& operator=(const char *s);
SDouble& operator=(double d);
SDouble& operator=(const SLong& sl);
SDouble& operator=(const SDouble& sd);
SDouble& operator=(const SFraction& sf); It converts SFracrion into SDouble.

fundamental operators +, -, *, / and compound operators +=, -=, *= /=
These operators are overloaded. All the objects which are usable in the constructors can be used as operands.
[Caution]
Please use cast the operations between different type variables.
SD=0.1*SL yields SD=0.0. --> SD=0.1*(SDouble)SL;
When SL=10, SD=0.1+SL yields SD=10.0 not 10.1. --> SD=0.1+(SDouble)SL;
These are expectative if lhs is SL.

relation operators >, <, ==, !=, >=, <=, ||, &&, !
These operators are overloaded. See the same item of SLong class.

SetZero
function "x.SetZero()" initializes "x.figure[]" and sign by zeros.
form inline void SDouble::SetZero();

DDCompare
function "DDCompare(x, y);" compares the absolute value of x with that of y,
and returns
1 if |x|>|y|,
0 if |x|==|y|,
-1 if |x|<|y|.
from friend int DDCompare(const SDouble& m, const SDouble& n);

RdxExp, NetRdxExp
function "x.RdxExp()" returns the exponential part of x.
form
inline int SDouble::RdxExp() const;
inline int SDouble::NetRdxExp() const;
comment "x.RdxExp()" gives a raw value in the fixed point mode. The value e in the "standard" form

[+|-]f[0].f[1]... * R e (f[1] >0)

can be obtained by "x.NetRdxExp()".

SetRdxExp(SDouble only)
function "x.SetRdxExp(e)" sets the exponential part of x equal to e.
form inline void SDouble::SetRdxExp(long e);

First
function "x.First()" returns the position of first non-zero element in "x.figure[]" or 0(if "x ==0").
form inline uint SDouble::First() const;
comment In the standard form it returns 1 or 0(if sign==0). In fixed point mode it is maybe greater than one. See "SNumber::Tail()".

Last
function : "x.Last()" returns the position of last non-zero element in "x.figure[]" or 0(if "x ==0").
form inline uint SDouble::Last() const;
comment In the fixed point mode, if non-zero part is in the outside of hidden figures, not only "x.Last()" but also "x.Sign()" return zero. See "SNumber::Head()".

FixedPoint, PointFree(SDouble only)
function "x.FixedPoint(fe)" takes into the fixed point mode setting the fixed exponent value by "fe". "x.PointFree()" cancels the fixed point mode by one step.
form
void SDouble::FixedPoint(int fe);
void SDouble::PointFree();
comment It is used in the calculation of series summation. In principle do not call mathematical functions in the fixed point mode. The general term of the floating (reducible size) and fixed point (irreducible size) modes is named as the "operation mode".

Reform
function "x.Reform(id)" reforms x into a representation which is suitable for the present operation mode.
from void SDouble::Reform(int id);
comment It adjusts the size of "figure[]" i.e. it cuts lower needless zeros if in the reducible size mode. If the top figure(figure[0]) becomes non-zero by a carry, it shifts to lower by a figure and makes figure[0]=0 and increases the exponent by one. It must be executed after directly changing the elements of figure[] or restoring the operation mode.

StdReform(SDouble only)
function Even if in the fixed point mode "x.StdReform(id)" forcibly changes x into a standard form.
form void SDouble::StdReform(int id);

SetSNBlock, SetSNBlockNorm
function "x.SetSNBlock(a, sgn, exp)" sets a SDouble value to x by SNBlock a, sign sgn and exponent exp.
form 
inline void SDouble::SetSNBlock(const SNBlock& a, int sgn, int exp);
inline void SetSNBlockNorm(const SNBlock& a, int sgn, int exp); calls normalization function

FigureAlloc(overrided function of SNumber class)
function "x.FigureAlloc(size, copy)" allocates the memory of "x.figure[]".
form inline void SDouble::FigureAlloc(uint size, int copy);
comment See SNumber::FigureAlloc() for the meaning of "copy". If "size" is greater than "minArraySize" it takes into fixed point mode.

DsMult, DsDiv
function "DsMult(SD, n)" returns "SD*n" and "DsDiv(SD, n)" "SD/n".
form
friend SDouble DsMult(const SDouble& m, ulong n);
friend SDouble DsDiv(const SDouble& m, ulong n); (0<n<=ULONG_MAX/radix)
See the comment of "LsMult" in SLong class.

DReciprocal
function : "DReciprocal(x)" returns "1/x" for "x !=0.0".
form friend SDouble DReciprocal(const SDouble& x);
comment It calculate the reciprocal of x by the Newton's method with doubling significant figures algorithm. It is used in division "y/x".

MultPowRdx
function "x.MultPowRdx(n)" changes the value of x into x R n.
from SDouble& SDouble::MultPowRdx(int n);

MultPow10 (SDouble only)
function "x.MultPow10(p)" changes the value of x into x10p.
form SDouble& SDouble::MultPow10(long p);

enumerating constants
function It gives the definition of values for output function.
form enum SDouble::{ NO_CR = 0, CRLF = 1, CONTINUE = 2, LAST_CR =4 , ROUND = 8, INT_PUT = 16, SHOW_FIG = 32};

Put, Puts
function "x.Put(s)(...)" outputs the value of x to the present stream.
form
long SDouble::Put(long fig=5, long pr = 0, int perLine = 0, int mode = CRLF|ROUND|INT_PUT, int delmt =' ') const;
inline long SDouble::Puts(long fig = 5, long pr = 0, int perLine = 0, int mode = CRLF|ROUND|INT_PUT, int delmt =' ') const;
comment 
"Put()" does not output carriage return, "Puts()" feeds new line.
It inserts delimiter given by "delmt " at intervals of "fig " digits.
If "delmt == 0", no delimiter is inserted.
If "fig == 0", it continuously outputs with neither delimiter nor carriage return.
Give "pr " the number of decimal figures. When "pr = 0"(default) all significant figures are output.
Give "perLine " the number of blocks which contains "fig " decimal per line. When "perLine = 0"(default) automatically set "perLine = crtWidth/(fig+1)".
NO_CR, CRLF, CONTINUE and LAST_CR have the same meaning as SLong class's ones.
ROUND : do Round() or not.
INT_PUT : It outputs one decimal figure as integer part.
SHOW_FIG: It shows the number of decimal figures at end of line, and adds carriage return.
It returns the total number of output bytes, including '\n', '.' and delimiter, the same as "printf()".

RawPut, RawPuts
function "x.RawPut(s)(...)" outputs the inner expression of x.
from
long SDouble::RawPut(int crlf = 0) const; does not add '\n'
inline long SDouble::RawPuts() const; adds '\n' at last

TakeOutFigures
function "x.TakeOutFigures(fig)" returns an approximated value of x taking first "fig" figures.
form SDouble SDouble::TakeOutFigures(uint fig) const;

IsOne
function If "|x|==1", "x.IsOne()" returns the sign of x (1 or -1), else returns 0.
form inline int SDouble::IsOne() const;

DFigures(SDouble only)
function "x.DFigures()" returns the number of decimal digits of x.
form long SDouble::DFigures() const;

IsHidden
function "x.IsHidden()" returns whether x is composed by hidden figures only(1) or not(0). It is available in the fixed point mode only.
form inline bool SDouble::IsHidden() const;

IsMLT
function "x.IsMLT(y)" returns whether x is much less than y (1 or -1) or not(0).
When you use as "x.IsMLT(y)" you can read "x is much less than y ?".
form short SDouble::IsMLT(const SDouble& x) const;

[Other related function]
Dabs
function "Dabs(x);" returns the absolute value of SDouble x, i.e. |x|.
Its prototype declaration is given in "snfunc.h".
form inline SDouble Dabs(const SDouble& x);

doubleD(SDouble only)
function "doubleD(SD );" returns the approximated value of SD by double. 
form double doubleD(const SDouble& sd, int err = 1);
comment If "err != 0"(default) and "sd  " is too large or too small to convert into double value, an abnormal termination occurs. If "err == 0", it returns DBL_MAX (overflow) or zero (underflow) and the program continues. You can know the information of error by the returned value of "SNManager::SNError()"(NO_ERR, OVERFLOW_ERR or UNDERFLOW_ERR).