Article View: alt.comp.lang.learn.c-c++
Article #590Re: High-precision fixed point math
From: B Summers
Date: Wed, 18 Sep 2002 21:32
Date: Wed, 18 Sep 2002 21:32
43 lines
2900 bytes
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 > ----- > > >
Technical Details
Message-ID:
<Yh6i9.72948$U_.54674@news04.bloor.is.net.cable.rogers.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-hub.siol.net!newsfeeds-atl2!news.webusenet.com!news03.bloor.is.net.cable.rogers.com!news04.bloor.is.net.cable.rogers.com.POSTED!not-for-mailReferences:
<w8Rh9.77700$561.55900@news02.bloor.is.net.cable.rogers.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 102541,951da3994a2133ff X-Google-Attributes: gid102541,public X-Google-Thread: 114592,951da3994a2133ff X-Google-Attributes: gid114592,public X-Google-Thread: 109fba,951da3994a2133ff X-Google-Attributes: gid109fba,public X-Google-ArrivalTime: 2002-09-18 14:40:18 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-hub.siol.net!newsfeeds-atl2!news.webusenet.com!news03.bloor.is.net.cable.rogers.com!news04.bloor.is.net.cable.rogers.com.POSTED!not-for-mail From: "B Summers" <.@.> Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cppbuilder.students,comp.lang.c++ References: <w8Rh9.77700$561.55900@news02.bloor.is.net.cable.rogers.com> Subject: Re: High-precision fixed point math Lines: 45 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Message-ID: <Yh6i9.72948$U_.54674@news04.bloor.is.net.cable.rogers.com> Date: Wed, 18 Sep 2002 21:32:40 GMT NNTP-Posting-Host: 24.42.221.54 X-Complaints-To: abuse@rogers.com X-Trace: news04.bloor.is.net.cable.rogers.com 1032384760 24.42.221.54 (Wed, 18 Sep 2002 17:32:40 EDT) NNTP-Posting-Date: Wed, 18 Sep 2002 17:32:40 EDT