Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Questions on implementing a floating point bignum package

Reply
Thread Tools

Questions on implementing a floating point bignum package

 
 
mike3
Guest
Posts: n/a
 
      12-05-2007
Hi.

(I'm xposting this to comp.lang.c++ as well just in case C++-specific
questions arise)

I've been writing ths bignum package in C++, and am wondering about
this. See, it's really made only to do big floating point arithmetic,
and the way that I'm doing it now, I have routines like the one below
that assume their operands should all have the same length, routines
that manipulate bits and pieces of the bignums as needed to implement
the floating point arithmetic which have to handle variable lengths
but such handling is done, by the very nature of floating point, in a
way often different from that of ordinary integers (due, among other
things, to the mantissa of a floating point number being a fractional
expansion (in binary), not an integer, so the place-value of the bits
is different and hence the arithmetic works somewhat differently (ie.
to add 1.1101 and 1.1 (bin) you add the latter to the _upper_ digits
of the former, not the lower digits.).).

Is this a good idea? Or should I include that differing-length
handling in these lower-
level digit-manipulating routines?

Example:
/* Add two digit slices.
* Parameters:
* a: First slice.
* b: Second slice.
*
* Returns: carry.
*
* Operation: *this = a + b.
*
* Assumes: *this, a, b have same length. (The floating point routines
* are written in such a way so that's all we need so we don't include
* extra functionality for reasons of performance and wanting to avoid
* too much redundancy.) If lengths are unequal, uses the _smallest_
* length of all operands as a safety.
*/
Digit RawDigitSlice::Add(const RawDigitSlice &a, const RawDigitSlice
&b)
{
/* Set up iterators */
DigitIterator ri(start);
DigitIterator ai(a.start);
DigitIterator bi(b.start);
int length(std::min(std::min(a.length, b.length), length));

/* Add digits */
Digit carry(0);
for(int i(0);i<length;i++,ri++,ai++,bi++)
{
Digit tmp(*ai + *bi + carry);
carry = carry ? (tmp <= *ai) : (tmp < *ai);
*ri = tmp;
}

/* Done! */
return(carry);
}
 
Reply With Quote
 
 
 
 
mike3
Guest
Posts: n/a
 
      12-10-2007
On Dec 4, 5:46 pm, mike3 <(E-Mail Removed)> wrote:
<snip>

Any comments? Should one implement all that stuff?
 
Reply With Quote
 
 
 
 
mike3
Guest
Posts: n/a
 
      12-16-2007
On Dec 4, 5:46 pm, mike3 <(E-Mail Removed)> wrote:
> Hi.
>
> (I'm xposting this to comp.lang.c++ as well just in case C++-specific
> questions arise)
>
> I've been writing thsbignumpackage in C++, and am wondering about
> this. See, it's really made only to do big floating point arithmetic,
> and the way that I'm doing it now, I have routines like the one below
> that assume their operands should all have the same length, routines
> that manipulate bits and pieces of the bignums as needed to implement
> the floating point arithmetic which have to handle variable lengths
> but such handling is done, by the very nature of floating point, in a
> way often different from that of ordinary integers (due, among other
> things, to the mantissa of a floating point number being a fractional
> expansion (in binary), not an integer, so the place-value of the bits
> is different and hence the arithmetic works somewhat differently (ie.
> to add 1.1101 and 1.1 (bin) you add the latter to the _upper_ digits
> of the former, not the lower digits.).).
>
> Is this a good idea? Or should I include that differing-length
> handling in these lower-
> level digit-manipulating routines?
>

<snip>

Hmm? I really would like to know this, as I'm having trouble deciding
if I should or shouldn't.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
error message while using floating point package kdas VHDL 0 04-18-2008 04:55 PM
Bignum package implementation in C++/OO question mike3 C++ 8 03-10-2008 07:06 PM
floating point problem... floating indeed :( teeshift Ruby 2 12-01-2006 01:16 AM
Problem with using Floating Point Package ravi81082@gmail.com VHDL 0 10-30-2006 02:24 PM



Advertisments