From: "Matthias Wächter" Date: 2012-01-27T16:51:11+09:00 Subject: Re: Microrant on Ruy's Math Skills Am 25.01.2012 15:28, schrieb botp: > 2012/1/25 Matthias Wächter: >> I’m curious to see what’s gonna happen once Desktop CPUs start to support >> the nice decimal floating-point types of IEEE 754-2008 >> [http://en.wikipedia.org/wiki/IEEE_754-2008#Basic_formats] … maybe Ruby >> should already prepare syntactically for support of these types. And, in >> theory, there is already a library from Intel >> [http://software.intel.com/en-us/articles/intel-decimal-floating-point-math-library/] >> one can use to do decimal floating-point math. > > wow, thanks for the update. i hope ruby can indeed support that even > if i need to recompile manually. Well, there is at least float-formats [http://float-formats.rubyforge.org/] available that some kind of supports IEEE 754-2008 and its decimal float types, but I’m failing quickly making it show me some basic tricks. > ruby-1.9.3-p0 :001 > require 'float-formats' > => true > ruby-1.9.3-p0 :002 > include Flt > => Object > ruby-1.9.3-p0 :003 > a = 0.1 > => 0.1 > ruby-1.9.3-p0 :004 > [a].pack('D').each_char.map {|c| c.ord.to_s(16).upcase}.join(" ") > => "9A 99 99 99 99 99 B9 3F" > ruby-1.9.3-p0 :005 > IEEE_binary64(a).to_hex(true) > => "9A 99 99 99 99 99 B9 3F" > ruby-1.9.3-p0 :006 > a = 1.1 - 1 > => 0.10000000000000009 > ruby-1.9.3-p0 :007 > [a].pack('D').each_char.map {|c| c.ord.to_s(16).upcase}.join(" ") > => "A0 99 99 99 99 99 B9 3F" > ruby-1.9.3-p0 :008 > IEEE_binary64(a).to_hex(true) > => "9A 99 99 99 99 99 B9 3F" Frankly, I don’t know how long we can maintain the one-size-fits-all approach to floats – representation and calculation precision– in Ruby. Fixnums automatically prolong into Bignums, strings can have any size and encoding, but DOUBLE’s (binary 64 floats) are the nearest and the furthest we come. How about someone already fancy going for 80 bit binary or the new 128 bit types? Decimal floats are not gonna make it easier to be dealt with. The least –and probably ugliest– we could get would be some kind of global switch which allows the selection of the wanted floating-point types. btw: who is Ruy? ;) – Matthias