Article View: alt.comp.lang.learn.c-c++
Article #760Re: float precision
From: Yves Ducourneau
Date: Thu, 13 Apr 2000 00:00
Date: Thu, 13 Apr 2000 00:00
25 lines
1916 bytes
1916 bytes
I propose to store the positions in cm (instead of km) :
- The world is 100 000 cm x 100 000 cm x 100 000 cm big,
- Each coordinate neads 17 bits (17 bits means up to 131 072),
- A position is stored in 3 long integers : {long x,y,z}.
The operations, now.
No problem for adding and substracting (no overflow).
The multiplication produces 34 bits numbers (2 x 17) ; you have to convert
temporarly to double. For example, let's compute the distance between 2
points :
long dist;
dist=sqrt((double)(x1-x2)*(x1-x2)
+(double)(y1-y2)*(y1-y2)
+(double)(z1-z2)*(z1-z2))+.5;
Because a double has a 52 bits mantissa, you can compute 2 multiplications
at the same time (a x b x c), without loss : 3 x 17 = 51 bits number.
For more complexes formulas (that is, formulas that has more than 52 bits
intermediates numbers) :
- You accept a loss of precision, or
- You cut the formula into steps, so that numbers over 52 bits are
avoided.
Yves
Technical Details
Message-ID:
<38F640A8.FF6D2B12@freesbee.fr>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38F5D7E6.153591F2@cyberdude.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fdcad,fcf1bc31a1ccc99f X-Google-Attributes: gidfdcad,public X-Google-Thread: 109fba,fcf1bc31a1ccc99f X-Google-Attributes: gid109fba,public X-Google-Thread: 114592,fcf1bc31a1ccc99f X-Google-Attributes: gid114592,public From: Yves Ducourneau <yves.ducourneau@freesbee.fr> Subject: Re: float precision Date: 2000/04/13 Message-ID: <38F640A8.FF6D2B12@freesbee.fr> X-Deja-AN: 610830249 Content-Transfer-Encoding: 7bit References: <38F5D7E6.153591F2@cyberdude.com> Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353" X-Complaints-To: abuse@freesbee.fr X-Trace: nnrp1.none.net 955658896 212.129.5.81 (Thu, 13 Apr 2000 22:48:16 MET DST) Organization: Freesbee.fr MIME-Version: 1.0 Reply-To: yves.ducourneau@freesbee.fr NNTP-Posting-Date: Thu, 13 Apr 2000 22:48:16 MET DST Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c++,fr.comp.lang.c++