M
mike3
Hi!
Maybe start with some small pieces:
What are the attributes of class BigFloat. What does BigFloat::Init do?
Does BigFloat have a default ctor?
Frank
Attributes? You mean all the data fields, etc? It
has 6:
sign: The sign of the number, 0 for positive, 1 for
negative.
Type: u8
err: Error flag. This is 1 if an error occured during
calculation (overflow, div by 0, etc.)
Type: u8
exp: Exponent field, from -32768 to +32767. Power
of 2 the mantissa is multiplied by.
Type: s16
length: Length of mantissa in DIGIT32s.
Type: int
digits: Pointer to an array of DIGIT32s that holds
the mantissa of the number. The least significant
digit comes first. The most significant digit
is normalized so it's top bit is 1 since numbers
should be 1.xxxxxxxxxxxx... * 10^exp (everything
there is in binary, "10" = 2). Unnormal numbers
are treated as zeroes, so no "denormals" or "gradual
underflow" is implemented (in my application I can
settle for the reduced range of representable values.).
Type: DIGIT32 *
(Note: u8 = unsigned char, s16 = signed short,
int = int).
BigFloat has a default constructor, yes, which just
calls BigFloat::Init to the default precision (128bit).
BigFloat::Init allocates the memory for the BigFloat.
It's real simple:
/* Initialize a BigFloat. Used by all constructors. */
FG3DError BigFloat::Init(int reqprec)
{
/* Safety */
if(((reqprec < MIN_PRECISION) || (reqprec > MAX_PRECISION)) &&
(reqprec != -1))
return(FG3DError(FG3D_INVALID_PRECISION, (DWORD)reqprec));
/* -1 means default precision */
if(reqprec == -1) reqprec = DEFAULT_PRECISION;
/* Set fields */
length = reqprec;
sign = 0;
err = 0;
exp = 0;
digits = NULL;
/* Allocate array of DIGIT32s */
digits = new DIGIT32[length];
if(digits == NULL)
return(FG3DError(FG3D_OUT_OF_MEMORY, (DWORD)this));
/* Zeroize digits */
FG3DRawInt_Zeroize(digits, length);
/* Done! */
return(FG3DError(FG3D_SUCCESS));
}