🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: alt.comp.lang.learn.c-c++
6 messages
6 total messages Started by Mike K Wed, 18 Sep 2002 02:02
High-precision fixed point math
#586
Author: Mike K
Date: Wed, 18 Sep 2002 02:02
28 lines
2510 bytes
Hi,

To start off, yes this is a school question. The question is as follows:
Write a C++ program to calculate and print the square root of an integer to
40 decimal points.
To me, this seems like a Newton's Method type problem, except for the fact
that my computer can't do more than MSVC++'s 80-bit/10-byte long double.
So, I was thinking of writing a template class which holds BCD number
information in nibbles (full bytes for now, optimize later). Then, math is
performed through the nibble array.
Is this sane? Is there a better way to do it? I don't want to waste my time
reinventing the wheel, if there's already a better answer out there.
I did find, through my travels, a library called BigInt.h, which kind of
implements the same kind of idea:

#define BIGINT_TOTAL_BITS 128       // Produces 38   decimal digits
#define BIGINT_BASE_BITS 32         // Number of bits in base type
#define BIGINTSIZE (BIGINT_TOTAL_BITS / BIGINT_BASE_BITS)
typedef unsigned long BIGINT_BASE;  // The base type.
public:
  BIGINT_BASE data[BIGINTSIZE];     /* Little endian data */

But I couldn't get it to work properly.

Thanks for your help!

Michael
-----
Re: High-precision fixed point math
#587
Author: Alf P. Steinbach
Date: Wed, 18 Sep 2002 02:49
15 lines
1601 bytes
On Wed, 18 Sep 2002 02:02:04 GMT, "Mike K" <mkipper@rogers.com> wrote:

>Hi,
>
>To start off, yes this is a school question. The question is as follows:
>Write a C++ program to calculate and print the square root of an integer to
>40 decimal points.

Can you choose the integer yourself?  In that case, calculate and write
out the square root of 4.  Limit yourself to integers, and assert that
the computed integer square root is a precise square root.

Hth.,

- Alf
Re: High-precision fixed point math
#588
Author: B Summers .com
Date: Wed, 18 Sep 2002 03:56
38 lines
2835 bytes
<cough>...array...<cough>....


"Mike K" <mkipper@rogers.com> wrote in message
news:w8Rh9.77700$561.55900@news02.bloor.is.net.cable.rogers.com...
> Hi,
>
> To start off, yes this is a school question. The question is as follows:
> Write a C++ program to calculate and print the square root of an integer
to
> 40 decimal points.
> To me, this seems like a Newton's Method type problem, except for the fact
> that my computer can't do more than MSVC++'s 80-bit/10-byte long double.
> So, I was thinking of writing a template class which holds BCD number
> information in nibbles (full bytes for now, optimize later). Then, math is
> performed through the nibble array.
> Is this sane? Is there a better way to do it? I don't want to waste my
time
> reinventing the wheel, if there's already a better answer out there.
> I did find, through my travels, a library called BigInt.h, which kind of
> implements the same kind of idea:
>
> #define BIGINT_TOTAL_BITS 128       // Produces 38   decimal digits
> #define BIGINT_BASE_BITS 32         // Number of bits in base type
> #define BIGINTSIZE (BIGINT_TOTAL_BITS / BIGINT_BASE_BITS)
> typedef unsigned long BIGINT_BASE;  // The base type.
> public:
>   BIGINT_BASE data[BIGINTSIZE];     /* Little endian data */
>
> But I couldn't get it to work properly.
>
> Thanks for your help!
>
> Michael
> -----
>
>
>
Re: High-precision fixed point math
#589
Author: Richard van Wegen
Date: Wed, 18 Sep 2002 07:09
18 lines
1709 bytes
Howdy!

> Is this sane? Is there a better way to do it? I don't want to waste my time
> reinventing the wheel, if there's already a better answer out there.
> I did find, through my travels, a library called BigInt.h, which kind of
> implements the same kind of idea:

Well I recall seeing another bit of code to do this:

http://www.snippets.org/snippets/portable/portable.php3, under
"Cliff Rhodes' package of unsigned integer math for arbitrarily large
numbers"

For all I know it's the same as "BigInt", and I haven't got a clue if
it works or not.  But it might be worth a look.

Cheers
  Richard
Re: High-precision fixed point math
#590
Author: B Summers
Date: Wed, 18 Sep 2002 21:32
43 lines
2900 bytes
Try this site:

http://www.perfsci.com/free/giantint/index.html

Download the file at "click here". Open up tutor.c and examine the code.
They basically used an array. Check out their giants.h header file too.


"Mike K" <mkipper@rogers.com> wrote in message
news:w8Rh9.77700$561.55900@news02.bloor.is.net.cable.rogers.com...
> Hi,
>
> To start off, yes this is a school question. The question is as follows:
> Write a C++ program to calculate and print the square root of an integer
to
> 40 decimal points.
> To me, this seems like a Newton's Method type problem, except for the fact
> that my computer can't do more than MSVC++'s 80-bit/10-byte long double.
> So, I was thinking of writing a template class which holds BCD number
> information in nibbles (full bytes for now, optimize later). Then, math is
> performed through the nibble array.
> Is this sane? Is there a better way to do it? I don't want to waste my
time
> reinventing the wheel, if there's already a better answer out there.
> I did find, through my travels, a library called BigInt.h, which kind of
> implements the same kind of idea:
>
> #define BIGINT_TOTAL_BITS 128       // Produces 38   decimal digits
> #define BIGINT_BASE_BITS 32         // Number of bits in base type
> #define BIGINTSIZE (BIGINT_TOTAL_BITS / BIGINT_BASE_BITS)
> typedef unsigned long BIGINT_BASE;  // The base type.
> public:
>   BIGINT_BASE data[BIGINTSIZE];     /* Little endian data */
>
> But I couldn't get it to work properly.
>
> Thanks for your help!
>
> Michael
> -----
>
>
>
Re: High-precision fixed point math
#591
Author: Richard Heathfield
Date: Wed, 18 Sep 2002 21:56
23 lines
1851 bytes
B Summers wrote:
> 
> Try this site:
> 
> http://www.perfsci.com/free/giantint/index.html
> 
> Download the file at "click here". Open up tutor.c and examine the code.

I did that. Here's the first thing I found:

void
main(
        void
)
{

I'm not convinced that the code is worth further study.

-- 
Richard Heathfield : binary@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads