🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: float precision

#767
From: Tom
Date: Thu, 13 Apr 2000 00:00
39 lines
1870 bytes
On Thu, 13 Apr 2000 16:21:26 +0200, dataman@cyberdude.com wrote:

>I am really confused about float precision ..officially it's 3.4 *
>(10**-38) to 3.4 * (10**+38)

That's just the range, not the precision.

>But, that does not help me much even it confuse me more ....
>
>Here is my problem:
>
>I need to define a world of 10 000 000 units .  I need to use float for
>that . I think to use only the positive part (but will depend from the
>answer of my question).
>What precision (after the dot ) can i expect  ?

This is platform dependent. To work it out, compile and run the
following program

#include <limits>
#include <iostream>

int main()
{
	using namespace std;
	cout << "d.p. for float = " 
		 << numeric_limits<float>::digits10 - 8
		 << "\nd.p. for double = "
		 << numeric_limits<double>::digits10 - 8
		 << endl;
	return 0;
}

My system runs out of precision before the decimal point with float (I
got -2). You will probably want to use double instead, which gives me
an impressive 7d.p. of accuracy after the decimal point, with a number
around the size of 10 000 000.

Tom
Technical Details
Message-ID: <38f5edd4.21497207@news.demon.co.uk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <38F5D7E6.153591F2@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: 114592,fcf1bc31a1ccc99f
X-Google-Attributes: gid114592,public
X-Google-Thread: fdcad,fcf1bc31a1ccc99f
X-Google-Attributes: gidfdcad,public
From: rhinoceros1@hotmail.com (Tom)
Subject: Re: float precision
Date: 2000/04/13
Message-ID: <38f5edd4.21497207@news.demon.co.uk>
X-Deja-AN: 610720219
X-NNTP-Posting-Host: cenes.demon.co.uk:194.222.206.118
References: <38F5D7E6.153591F2@cyberdude.com>
X-Trace: news.demon.co.uk 955642101 nnrp-12:22856 NO-IDENT cenes.demon.co.uk:194.222.206.118
Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c++,fr.comp.lang.c++
X-Complaints-To: abuse@demon.net