473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 102432
Christian Christmann wrote:
just a general question.
Which data type is more precise for large values:
float or double?


Usually, 'double' contains more _significant_digits_, 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
Yeah its true
sizeof(float) <= sizeof(double) <= sizeof(long double)

- but can you give me an example on a platform/compiler with
float = double ?

And if you can then still nothing is lost by writing double instead of
float.

Sep 11 '05 #11
tmartsum wrote:

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 ...


Now *that* is a real, real, real good reason.
And I guess the problem of 'surface acne' kept you busy
for quite a while.

('Surface acne' is the name for the arithmetic problem that your
formulas come up with an intersection, when there really is none.
Such as a shadow ray emitting from a surface with the surface itself.
The ray tracer erronously sets this pixel into shadow giving the whole
surface a speckled appearance)

--
Karl Heinz Buchegger
kb******@gascad.at
Sep 12 '05 #12

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

Similar topics

4
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...
2
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...
3
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...
1
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? ...
0
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
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,...
2
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...
6
by: Joakim Hove | last post by:
Hello, consider a function: double some_func(double arg) { /* */ }
4
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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,...

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.