From: Marnen Laibow-Koser on 29 Oct 2009 08:06
Christopher Dicely wrote:
> On Wed, Oct 28, 2009 at 12:30 PM, Marnen Laibow-Koser
> <marnen(a)marnen.org> wrote:
>>> work with real numbers but just rational numbers.
>> That is not the issue here -- after all, BigDecimal does precise
>> arithmetic, but only with rational numbers.
> BigDecimal actually works with decimal numbers, which are a subset of
> rational numbers; Rational does precise math with rational numbers.
You're quite right, and I realized that about 10 seconds after I posted.
>> The issue is rather that IEEE 754 does an inadequate job of representing
>> arbitrary rational numbers, and the small errors are accumulated and
>> magnified in calculations.
> The bigger issue is that Ruby -- like most general purpose programming
> languages, though there are exceptions like Scheme -- makes IEEE 754
> floating point the easiest non-integer data type to use, rather than
> using exact numbers by default and using inexact numbers only when
> explicitly called for (or when an operation that produces inexact
> results is used.)
Yup. At least Ruby took a step in the right direction by making Bignum
transparent; it would be lovely if some future version did likewise with
Posted via http://www.ruby-forum.com/.
From: Aldric Giacomoni on 29 Oct 2009 08:50
Rajinder Yadav wrote:
> I've been following this thread and am wondering if there are other
> classes for Ruby other than BigDecimal?
That should get you started :)
Posted via http://www.ruby-forum.com/.
From: Rajinder Yadav on 29 Oct 2009 20:32
Aldric Giacomoni wrote:
> Rajinder Yadav wrote:
>> I've been following this thread and am wondering if there are other
>> classes for Ruby other than BigDecimal?
> That should get you started :)
Thanks (Jedi) Aldric, good place to expand =)
Do Good! - Share Freely, Enrich and Empower people to Transform their lives.
From: George Neuner on 31 Oct 2009 02:35
On Wed, 28 Oct 2009 14:30:21 -0500, Marnen Laibow-Koser
>Robert Klemme wrote:
>> On 28.10.2009 19:21, Matthew K. Williams wrote:
>>>> I bash my head against the wall? :)
>>> Pamphlet -> http://en.wikipedia.org/wiki/IEEE_754-2008
>>> Popcorn, well, it's kinda hard to transmit over the wire. ;-)
>> Easy to do with a modern email client - just needs support for POP3 and
>> a working firewall (for the heat). :-)
>>> As a rule of thumb, if you really care about the decimals, either use
>>> BigDecimal or integers (and keep track of where the decimal should be --
>>> this is common for $$$$). Unfortunately, this is not limited to ruby,
>>> either -- C, Java, and a host of other languages all are subject.
>> Absolutely: this is a common issue in *all* programming languages which
>> are not systems for symbolic math (like Mathematica) because they do not
>> work with real numbers but just rational numbers.
>That is not the issue here -- after all, BigDecimal does precise
>arithmetic, but only with rational numbers. The issue is rather that
>IEEE 754 does an inadequate job of representing arbitrary rational
>numbers, and the small errors are accumulated and magnified in
The problem is that the 754 representation has finite precision. I
suppose you can call that "inadequate", but I don't see a good way
around it ... 0.6 is still infinite in binary. BigDecimal will get
you the right answer (unless you run out of memory), but when the
significant figures pile up it tends to get you there very slowly. All
the various arbitrary precision formats suffer badly performance wise.
It's also worth noting that most floating point hardware is not
anywhere close to 754 compliant even though most FPUs do use the
standard number formats (at least for single and double precision).
From: Robert Klemme on 31 Oct 2009 08:51
On 10/31/2009 07:35 AM, George Neuner wrote:
> It's also worth noting that most floating point hardware is not
> anywhere close to 754 compliant even though most FPUs do use the
> standard number formats (at least for single and double precision).
Interesting! I wasn't aware of that. Why is that? Do they just leave
out operations or are HW vendors actually cutting corners and digressing
from the prescribed algorithms / results?
remember.guy do |as, often| as.you_can - without end