Re: rounding problems

Поиск
Список
Период
Сортировка
От Craig Ringer
Тема Re: rounding problems
Дата
Msg-id 4828B616.5080108@postnewspapers.com.au
обсуждение исходный текст
Ответ на Re: rounding problems  (Justin <justin@emproshunts.com>)
Список pgsql-general
Justin wrote:

> Craig Ringer wrote:

>> `double' in C++ refers to double precision floating point. `double' is
>> subject to all the usual fun with rational decimals being irrational
>> binary floats (and vice versa).

> Not according to MS specific if i'm reading it correctly
>
> *Microsoft Specific >*
>
> The double type contains 64 bits: 1 for sign, 11 for the exponent, and
> 52 for the mantissa. Its range is +/--1.7E308 with at least 15 digits of
> precision

I take it you're referring to:

http://msdn.microsoft.com/en-us/library/e02ya398(VS.80).aspx ?

See how it says "The format is similar to the float format...." ?

As you can see from:

http://msdn.microsoft.com/en-us/library/hd7199ke(VS.80).aspx

the `double' type is a binary floating point representation, just like
float. It just has a bigger exponent and a bigger mantissa, so it can
represent more extreme values and do so with more precision.

Being a binary floating point representation it's subject to all the
usual problems with comparison for equality, rounding oddities, etc.

Here's one of the many explanations out there on the 'net. I haven't
read this particular one, it's just a viable looking Google hit:

http://www.cprogramming.com/tutorial/floating_point/understanding_floating_point.html



By the way, there was at least a proposal for a numeric/decimal type for
C++0x . It doesn't seem to have made the cut.


http://209.85.173.104/search?q=cache:D0Iqhgz7X1QJ:www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2041.pdf+%22c%2B%2B0x%22+decimal+OR+numeric&hl=en&ct=clnk&cd=1&gl=au&client=firefox-a
http://en.wikipedia.org/wiki/C%2B%2B0x
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/

It looks like ISO C might adopt a decimal type or library though:

http://www2.hursley.ibm.com/decimal/

Note in particular the support in gcc 4.2 or newer.

There's also a library:

http://www2.hursley.ibm.com/decimal/dfpal/

that might be useful.

--
Craig Ringe

В списке pgsql-general по дате отправления:

Предыдущее
От: Justin
Дата:
Сообщение: Re: rounding problems
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: Making sure \timing is on