Article View: alt.comp.lang.learn.c-c++
Article #770Re: float precision
From: Dieter Buerssner
Date: Thu, 13 Apr 2000 00:00
Date: Thu, 13 Apr 2000 00:00
32 lines
2071 bytes
2071 bytes
dataman@cyberdude.com wrote: >I am building a 3d word , a big 3d world ..1000 km x 1000 km with 1 cm >precision (= 100 000 000 units). You can come close to one cm resolution with type float (assuming IEEE-754 floating point, which, from your message headers, you seem to have). If you put the origin in the middle of your world, and take 1 km as unit, the largest floating point number you need will be 500. Because 500. has the same exponent in the floating point representation as 256., I will calculate the error for 256. The next bigger number, that is distinct from 256 is 256*(1+2^-23), which happens to be just 3.05 cm larger than 256. So between 256 km and 500 km, you will have a resolution of 3 cm. (Between 128 km and 256 km you have a resolution of 1.5 cm, and so on. The same is true for negative numbers.) If you use type double for calculations, you won't even have an error larger than 1.5 cm. float x1=499., x2, x3, dx; dx = 1.5*1e-5; // 1.5 cm x2 = (double)x1 + dx; // x2 will stay 499.0 dx = 1.6*1e-5; // 1.6 cm x3 = (double)x1 + dx; // x3 will be 499.0 + 3.05e-5 So the error will be about 1.5 cm in both cases. -- Regards, Dieter
Technical Details
Message-ID:
<8d5bc3.3vvrn3d.0@buerssner-17104.user.cis.dfn.de>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38F5D7E6.153591F2@cyberdude.com> <38F5E510.E33662C@gascad.at> <38F5FA5B.813A2438@cyberdude.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,fcf1bc31a1ccc99f X-Google-Attributes: gid109fba,public X-Google-Thread: fdcad,fcf1bc31a1ccc99f X-Google-Attributes: gidfdcad,public X-Google-Thread: 114592,fcf1bc31a1ccc99f X-Google-Attributes: gid114592,public From: buers@gmx.de (Dieter Buerssner) Subject: Re: float precision Date: 2000/04/13 Message-ID: <8d5bc3.3vvrn3d.0@buerssner-17104.user.cis.dfn.de> X-Deja-AN: 610778028 Content-Transfer-Encoding: 8bit References: <38F5D7E6.153591F2@cyberdude.com> <38F5E510.E33662C@gascad.at> <38F5FA5B.813A2438@cyberdude.com> X-Posting-Agent: Hamster/1.3.13.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: fu-berlin.de 955651138 7273308 149.225.44.63 (16 [17104]) Mime-Version: 1.0 User-Agent: Xnews/03.02.04 Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c++,fr.comp.lang.c++