--------------ms070508070500030009020000
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jannis Harder wrote:
> Luke Galea wrote:
> 
>> Hi All,
>>
>> I need to convert a float to a fraction.. So 1.5 to 1 1/2..
>> The rational class would represent at least 3/2 well.. but I was 
>> surprised to find that there is no way to easily go from float to 
>> rational.. 
>> Am I missing an easier way?
>> Thanks in advance
>>
> I wrote a small float rational method:

Here is another one - it's probably much slower, but works
better for corner-cases like (0.2).to_r

class Numeric
   def to_r
     chain_fractions.reverse.inject(nil) do |r,a|
       Rational(a) + (r.nil? ? 0 : (Rational(1) / r))
     end
   end
end

class Integer
   def chain_fractions
     [self]
   end
end

class Float
   def chain_fractions
     remainder  elf
     if ! block_given? then
       coefficients  rray::new
     end
     while (true) do
       if block_given? then
         yield remainder.floor
       else
         coefficients << remainder.floor
       end
       break if remainder remainder.floor
       remainder   / (remainder - remainder.floor)
     end
     coefficients
   end
end

greetings, Florian Pflug

--------------ms070508070500030009020000
Content-Type: application/x-pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature

MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIL4DCC
BewwggVVoAMCAQICAzAABDANBgkqhkiG9w0BAQQFADCByDELMAkGA1UEBhMCQVQxDzANBgNV
BAgTBlZpZW5uYTEPMA0GA1UEBxMGVmllbm5hMSEwHwYDVQQKExhzb2x1dGlvbi14IFNvZnR3
YXJlIEdtYkgxHjAcBgNVBAsTFUNlcnRpZmljYXRlIEF1dGhvcml0eTEqMCgGA1UEAxMhc29s
dXRpb24teDo6Y2VydGlmaWNhdGUtYXV0aG9yaXR5MSgwJgYJKoZIhvcNAQkBFhlob3N0bWFz
dGVyQHNvbHV0aW9uLXguY29tMB4XDTA0MTAwODE4MTkxN1oXDTA5MTAwODE4MTkxN1owgdUx
CzAJB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