Why do doubles and floats exist?

Duplicate

When should you use double instead of decimal?

.. and much more...

We use C # and SQL Server decimal data types in all our applications because of their precision. There have never been any of these annoying issues where the grand total doesn't add up to details etc.

I was wondering why double and float exist at all, given their imprecision

0


a source to share


4 answers


Floating point arithmetic came about because it is the only way to deal with large numbers of non-integers at a reasonable amount of hardware overhead. Infinite precision arithmetic is implemented in multiple languages ​​(Python, LISP, etc.) and libraries (Java BigNum, GMP, etc.) and is an alternative for people who require more precision (e.g. in the financial industry). For most of us who are dealing with midsize numbers, floats

or of course,doubles

are more than accurate enough. Two different types of floating point data (which corresponds to IEEE 754 single and two point precision, respectively), since a single precision floating point block has much better area, power and speed properties than a double precision block, and therefore hardware designers and programmers must make appropriate trade-offs for the use of these various properties.



+3


a source


They are much faster than decimal and very often you don't need exact precision.



+1


a source


"decimal" is 128 bits, double is 64 bits, and float is 32 bits. It mattered that day.

The decimal value is mostly for money transactions (to avoid rounding), others are good enough for a few things where 29 decimal precision values ​​don't make any real sense in the world.

+1


a source


The disadvantage of the decimal data type is performance.

This post describes well enough:

Decimal and double speed

0


a source







All Articles