I do a calculation that often includes values ββlike 3.47493E + 17298. This is much higher than double can handle, and I don't need extra precision, just an extra range of exponents, so I created my own small structure in C #.
My structure uses long for sign and sign, and int for exponent, so I have:
1 sign bit 32 exponential bits (regular 2 component metric) 63 significant bits
I am curious about what steps can be taken to make my multiplication procedure more efficient. I start a huge number of multiplications of these extended range values, and it is pretty fast, but I was looking for clues to speed it up.
My multiplication procedure:
public static BigFloat Multiply(BigFloat left, BigFloat right)
{
long shsign1;
long shsign2;
if (left.significand == 0)
{
return bigZero;
}
if (right.significand == 0)
{
return bigZero;
}
shsign1 = left.significand;
shsign2 = right.significand;
int s1 = qshift(shsign1, multLimit);
int s2 = qshift(shsign2, multLimit);
shsign1 >>= s1;
shsign2 >>= s2;
BigFloat r;
r.significand = shsign1 * shsign2;
r.exponent = left.exponent + right.exponent + s1 + s2;
return r;
}
qshift:
, val, , .
public static int qshift(long val, long limit)
{
long q = val;
long c = limit;
long nc = -limit;
int counter = 0;
while (q > c || q < nc)
{
q >>= 1;
counter++;
}
return counter;
}