🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #586

High-precision fixed point math

#586
From: 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
-----
Technical Details
Message-ID: <w8Rh9.77700$561.55900@news02.bloor.is.net.cable.rogers.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!193.251.151.101!opentransit.net!fr.clara.net!heighliner.fr.clara.net!news-hub.siol.net!newsfeeds-atl2!news.webusenet.com!news03.bloor.is.net.cable.rogers.com!news02.bloor.is.net.cable.rogers.com.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,951da3994a2133ff,start
X-Google-Attributes: gid109fba,public
X-Google-Thread: 114592,951da3994a2133ff,start
X-Google-Attributes: gid114592,public
X-Google-Thread: 102541,951da3994a2133ff,start
X-Google-Attributes: gid102541,public
X-Google-ArrivalTime: 2002-09-17 19:06:24 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!193.251.151.101!opentransit.net!fr.clara.net!heighliner.fr.clara.net!news-hub.siol.net!newsfeeds-atl2!news.webusenet.com!news03.bloor.is.net.cable.rogers.com!news02.bloor.is.net.cable.rogers.com.POSTED!not-for-mail
From: "Mike K" <mkipper@rogers.com>
Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cppbuilder.students,comp.lang.c++
Subject: High-precision fixed point math
Lines: 31
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Message-ID: <w8Rh9.77700$561.55900@news02.bloor.is.net.cable.rogers.com>
Date: Wed, 18 Sep 2002 02:02:04 GMT
NNTP-Posting-Host: 24.101.95.126
X-Complaints-To: abuse@rogers.com
X-Trace: news02.bloor.is.net.cable.rogers.com 1032314524 24.101.95.126 (Tue, 17 Sep 2002 22:02:04 EDT)
NNTP-Posting-Date: Tue, 17 Sep 2002 22:02:04 EDT