473,566 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

double or float

Hi,

just a general question.
Which data type is more precise for large values:
float or double?

Thank you.
Chris
Sep 6 '05 #1
11 102446
Christian Christmann wrote:
just a general question.
Which data type is more precise for large values:
float or double?


Usually, 'double' contains more _significant_di gits_, so, as
a general case, 'double' is more precise for *any* values.
Also, usually, 'double' has a wider range.

V
Sep 6 '05 #2
Christian Christmann wrote:
Hi,

just a general question.
Which data type is more precise for large values:
float or double?


Define "large" and "values". If you mean integral values, then an
integer is more precise, assuming it can hold the value. Your compiler
may support 64-bit integers, which hold a fairly vast range.

If you require floating point computations or if the numbers are too
large for integral types, use floating point types. The sizes of float,
double, and long double are implementation-defined, but it is
guaranteed that:

sizeof(float) <= sizeof(double) <= sizeof(long double)

More bits generally equals more precision, but it depends how the bits
are allocated (i.e. what the floating-point format is). For more info
on floating point arithmetic, see "What Every Computer Scientist Should
Know About Floating-Point Arithmetic"
(http://docs.sun.com/source/806-3568/ncg_goldberg.html).

Cheers! --M

Sep 6 '05 #3
Christian Christmann wrote:
Just a general question.
Which data type is more precise for large values:
float or double?


double
Sep 6 '05 #4

"Christian Christmann" <pl*****@yahoo. de> wrote in message
news:43******** **************@ newsread2.arcor-online.net...
just a general question.
Which data type is more precise for large values:
float or double?


For most compilers, double with get you more. For some compilers, long
double will get you even more. For an introduction to numerical programming
with C and C++, see:

http://www.digitalmars.com/ctg/ctgNumerics.html

-Walter
www.digitalmars.com free C, C++, D compilers
Sep 6 '05 #5
Christian Christmann wrote:
Hi,

just a general question.
Which data type is more precise for large values:
float or double?

Thank you.
Chris


Hi Chris

First of all, your question is somewhat off-topic to this newsgroup. AFAIK,
the precision of C++ floating point data types is platform-dependent and
not a language subject. You would get a better answer if you posted your
question in a numerical analysis group you would get better answers than in
this newsgroup.

Still, here are my 0.02?

The float data type and the double data types are floating point data types.
A floating point data type is a digital representation of a number, which
aims to be equivalent to a real number.

Physically, a floating point data type is a set of bits which is divided
into sections (ranges of bits in the bit set). Two of those bit sections
are the significand and the exponent parts of the number. If the size of
the data type increases, the bits available to be allocated to the
significand section and to the exponent section also increase. So, if the
data type gets bigger, it also increases it's precision and it's range.

So, to finally answer your question, being the size of the double data type
usually bigger than the size of the float, then the precision of the double
data type should be greater than the precision of the float data type. But
have in mind that in the end this is all platform-dependent and not a
language issue.

for a light introduction check out the wikipedia article:
http://en.wikipedia.org/wiki/Floating_point
Hope this helps
Rui Maciel
--
Running Kubuntu 5.04 with KDE 3.4.2 and proud of it.
jabber:ru****** **@jabber.org
Sep 9 '05 #6
Christian Christmann wrote:

Hi,

just a general question.
Which data type is more precise for large values:
float or double?


On thing has not been mentioned up to now:

Use float only, iff:
* you know what you do
* you have the knowledge to fight that beast
* you are willing to fight that beast
* you have a very, very, very good reason to use float
* you have at least 4 times thought the whole thing through and
still come to the conclusion that float would be a good idea in
this specific case.

In all other cases (and that accounts for >98% of all cases): use double
The usual limitted precision of float will kill you.

--
Karl Heinz Buchegger
kb******@gascad .at
Sep 9 '05 #7
Ain't float faster on 32-bit machines (although I agree it has pretty
limited precision)?

Sep 10 '05 #8
float is normally faster and normally half the size.
I have had sizeproblems with double in a homemade racetrayer
where I had a figure with about 20 millon triangles ...

But I agree with Karl. Use double unless there are real good reasons to
use float.

Sep 10 '05 #9
On 10 Sep 2005 08:51:18 -0700, "f0r3nsic" <f0******@gmail .com> wrote:
Ain't float faster on 32-bit machines (although I agree it has pretty
limited precision)?


It depends--on certain machines with floating point math units, it could make
basically no difference.
Sep 10 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1743
by: Justin Sane | last post by:
I have created a liquid layout with 3 columns, the left and right cols being floated, and inside the middle column, I have a list of items that are floated to the left so that I have a pure liquid layout. Problem is: all that comes after the list of items is floated to left too: http://www.auriance.com/docs/test/index.html The word...
2
3473
by: Rikkert | last post by:
I am trying to make an Edit control that accepts only numbers and one point (i.e. only accepting input of type 'double' or 'float'). Can this be done without using MFC? The standard options for the Edit control seem to be either accepting all character input, or only integer number input, which doesn't quite cut it... Any tips are...
3
1930
by: Alan | last post by:
hi, are there any functions that can change double and float to string ? and is it possible to change the double/float to string which only contains decimal format instead of exponent expression? thx
1
13556
by: Jan Agermose | last post by:
Im writing a small test app that reads stringvalues, parses them to doubles and inserts the doubles into a mssql database. But the values inserted are not the same as the original string values? I tried paring the values using one of the two linies: double vekselkurs = double.Parse(node.Attributes.Value.Replace(".", ",")); //double...
0
1257
by: Andreas Busse | last post by:
Hello everybody, how can I assign one of the above values to a float or double? regards, Andreas
6
7596
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards, Karthi
2
3184
by: nemesisneo | last post by:
Please find details of small program written by me: ( UNIX NCR MP-RAS, NCR C/C++ Complier, Double is 8 bytes (Just in case)) double j; j = 3003486271; printf("\n double - > %17.14E ",j);
6
1573
by: Joakim Hove | last post by:
Hello, consider a function: double some_func(double arg) { /* */ }
4
6211
by: siryuhan | last post by:
I am trying to apply bitwise operations on float, double, and long double values. I do not believe this is possible natively, so I created a wrapper class to construct a double value given two integers, similar to the bit representation of floating point numbers. However, this is tedious and the decoding/encoding process is not efficient. ...
5
3129
by: habibo | last post by:
Hi frends double float data tybe in c# hase the folling rang 5*10^(-324) to (1.7)*10^308 yet it is mentioned in the storage size to be 64 bit how it comes the mentioned range need storag size nearly 1024 bits please to clearify such contraduction as it seem to me and what is the maximum integer size which we can handle in c# , or any...
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.