Float#to_s?

I think I’m going mad…

   >> t, f = Time.now.to_f, 1.5
   => [1042465260, 1.5]
   
   >> puts t, f
   1042465260
   1.5
   => nil

   >> puts t.class, f.class
   Float
   Float
   => nil

Why doesn’t “puts Time.now.to_f” print the fractional part of the
current epoch second?

I’ve confirmed that it “is_a?” Float. And I’ve done it several times,
to be sure that it’s not falling on an exact second.

This is Cygwin Ruby 1.6.8, BTW. On Windows XP.

Gavin

I think I’m going mad…

Let me provide further evidence:

  >> f = Time.now.to_f
  => 1042465453
  >> g = Time.now.to_f
  => 1042465457
  >> f - g
  => -4.146000028
···

On Tuesday, January 14, 2003, 12:43:40 AM, Gavin wrote:

Maybe a 1.6.8 problem:

irb
irb(main):001:0> t,f=Time.now.to_f, 1.5
=> [1042465529.056271, 1.5]
irb(main):002:0> puts t,f
1042465529.056271
1.5
=> nil
irb(main):003:0> puts t.class, f.class
Float
Float
=> nil
irb(main):004:0> puts Time.now.to_f
1042465559.700954
=> nil
irb(main):005:0> VERSION
=> “1.7.3”
irb(main):006:0>

···

On Monday, 13 January 2003 at 22:43:40 +0900, Gavin Sinclair wrote:

I think I’m going mad…

   >> t, f = Time.now.to_f, 1.5
   => [1042465260, 1.5]
   
   >> puts t, f
   1042465260
   1.5
   => nil

   >> puts t.class, f.class
   Float
   Float
   => nil

Why doesn’t “puts Time.now.to_f” print the fractional part of the
current epoch second?


Jim Freeze

I have discovered the art of deceiving diplomats. I tell them the truth
and they never believe me.
– Camillo Di Cavour

irb(main):005:0> VERSION
=> “1.7.3”
irb(main):006:0> f=Time.now.to_f
=> 1042465664.61685
irb(main):007:0> g=Time.now.to_f
=> 1042465669.193938
irb(main):008:0> f-g
=> -4.577087998390198
irb(main):009:0>

usr/local/bin/ruby -e ‘puts VERSION, Time.now.to_f’
1.6.6
1042465746

/usr/local/bin/ruby -e ‘puts VERSION, sprintf(“%.10f”, Time.now.to_f)’
1.6.6
1042465787.0673509836

I think the digits are there, they just are not printing.

···

On Monday, 13 January 2003 at 22:46:25 +0900, Gavin Sinclair wrote:

On Tuesday, January 14, 2003, 12:43:40 AM, Gavin wrote:

I think I’m going mad…

Let me provide further evidence:

  >> f = Time.now.to_f
  => 1042465453
  >> g = Time.now.to_f
  => 1042465457
  >> f - g
  => -4.146000028


Jim Freeze

Liar, n.:
A lawyer with a roving commission.
– Ambrose Bierce, “The Devil’s Dictionary”

Thanks for the results, Jim. You’re right that the digits are there,
the subtraction above proves it. But why wouldn’t they print? They
are Floats. Float#to_s prints digits (e.g. the literal 1.5).

It is as if the results from Time.to_f are singleton objects whose
#to_s has been rewritten!

I wish there was a way to know if an object is a singleton or has
otherwise been structually modified.

Gavin

···

On Tuesday, January 14, 2003, 12:50:24 AM, Jim wrote:

On Monday, 13 January 2003 at 22:46:25 +0900, Gavin Sinclair wrote:

On Tuesday, January 14, 2003, 12:43:40 AM, Gavin wrote:

I think I’m going mad…

Let me provide further evidence:

  >> f = Time.now.to_f
  => 1042465453
  >> g = Time.now.to_f
  => 1042465457
  >> f - g
  => -4.146000028

[Expected behaviour is displayed in 1.7]

I think the digits are there, they just are not printing.

I have searched the archives and posted this message three times
and have yet to get a response. I am trying to create a web page
that let’s a user upload a file.

OK, I felt sorry for you and looked in too it just now (but I
had already deleted your mail, so I high-jacked another one from
you, possibly upsetting people’s threading mail-clients, inserting
the contents of your original posting from the mailinglist archive).

I have worked through most of the issues, and can even get
a file on to my server, but it is embedded in a binary file
whose format is unknown.
Has anyone experience with this, or is there documentation on
how to extract the file data from what is sent to the server?
Below is an example of the file I get from webrick.
The original contents of the file v.rb is “This is a test.\n”

The spooky data is a boundary, which also is submitted via the
CONTENT_TYPE environment variable.

Test the following html-file (invalid, lacks head, body, and such):

···

On Mon, Jan 13, 2003 at 10:50:24PM +0900, Jim Freeze wrote:

--

with this ruby-snipet as the responding cgi action[1]:

env.rb

#!/usr/bin/ruby -w

puts “Content-type: text/html\n\n”;

puts “–START–
\n”;

while line = gets()

    puts line;

end

puts “
–STOP–
\n”;

ENV.each_pair { |e, v|

    puts "#{e} = #{v}<br>\n";

}

Look especially at the value of CONTENT_TYPE. Is it not that boundary
that comes before and after the actual contents of the file you chose
to upload?

Best Regards /Selander

[1] I hope your web-server supports Ruby-cgi:s. If not, try to
experiment with the directive “AddType application/x-httpd-cgi .rb”
in an own .htaccess file, if the server allows that. It, of course,
still requires that the web-server have Ruby installed, but it
should be possible to have it installet in your own home directory
and direct the shebang-line to it. Just don’t tell your sysadmin or
he might consider it as an violation of security.

Anders Selander Centre for Parallel Computers selander@pdc.kth.se
Programmer Royal Institute of Technology +46 (0)8 790 72 11
SE-100 44 STOCKHOLM, SWEDEN +46 (0)70 266 29 67

It is as if the results from Time.to_f are singleton objects whose
#to_s has been rewritten!

No, no

pigeon% /usr/bin/ruby -ve 'f = 1042465453.1; puts f.to_s'
ruby 1.6.8 (2002-12-24) [i686-linux]
1042465453
pigeon%

pigeon% ./ruby -ve 'f = 1042465453.1; puts f.to_s'
ruby 1.8.0 (2003-01-12) [i686-linux]
1042465453.1
pigeon%

Guy Decoux

Thanks for that, Guy. I’ve confirmed it here. Silly me, I should
have tried that literal in the first place.

Gavin

···

On Tuesday, January 14, 2003, 1:03:44 AM, ts wrote:

It is as if the results from Time.to_f are singleton objects whose
#to_s has been rewritten!

No, no

pigeon% /usr/bin/ruby -ve ‘f = 1042465453.1; puts f.to_s’
ruby 1.6.8 (2002-12-24) [i686-linux]
1042465453
pigeon%

pigeon% ./ruby -ve ‘f = 1042465453.1; puts f.to_s’
ruby 1.8.0 (2003-01-12) [i686-linux]
1042465453.1
pigeon%

Guy Decoux