Re: [Zope] Weird interaction between int() and DateTime.timeTime

2000-05-25 Thread Jeff K. Hoffman

On Thu, 25 May 2000, Chris Withers wrote:

> "Jeff K. Hoffman" wrote:
> >   Python 1.5.2 (#3, Mar  8 2000, 16:34:52) [C] on sunos5
> >   Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >   >>>
> >   >>> f = 1.
> >   >>> f
> >   2.0
> >   >>> int(f)
> >   1
> >   >>>
> 
> > the int() function takes a different code path and returns 1, correctly.
> 
> Forgive my ignorance, but in what way is 1 correct here? Surely 2 is the
> what should be returned?!

int() disregards everything after the decimal.

  >>> int(1.25)
  1
  >>> int(1.5)
  1
  >>> int(1.75)
  1
  >>> int(1.)
  1
  >>> int(2)
  2

The problem comes in when you consider that the string representation
functions (and thus, print) do not behave in the same way.

  >>> print 1.25
  1.25
  >>> print 1.5
  1.5
  >>> print 1.75
  1.75
  >>> print 1.9
  1.9
  >>> print 1.999
  1.999
  >>> print 1.9
  1.9
  >>> print 1.999
  1.999
  >>> print 1.9
  1.9
  >>> print 1.999
  1.999
  >>> print 1.9
  2.0

> Chris

--Jeff

---
Jeff K. Hoffman   704.849.0731 x108
Chief Technology Officer  mailto:[EMAIL PROTECTED]
Going Virtual, L.L.C. http://www.goingv.com/


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Weird interaction between int() and DateTime.timeTime

2000-05-25 Thread Chris Withers

[EMAIL PROTECTED] wrote:
> >From the python int doc string:
> 
> >>> print int.__doc__
> int(x) -> integer
> 
> Convert a string or number to an integer, if possible.
> A floating point argument will be truncated towards zero.

I _always_ get bitten by this :(

Sorry for my igorance, 

Chris

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Weird interaction between int() and DateTime.timeTime

2000-05-25 Thread andres

On Thu, May 25, 2000 at 07:44:44PM +0200, [EMAIL PROTECTED] wrote:
> 
> int() works fine (truncating everything behind "."):
> 
> >>> t.timeTime() == 953146937.0
> 0
> >>> t.timeTime() -  953146937.0
> -4.76837158203e-07  
> >>> int (round (t.timeTime()))
> 953146937   
> 

Thank you, that was illuminating. Keep forgetting that floats are not
always what they are printed to be.

--
Andres Corrada-Emmanuel   Email: [EMAIL PROTECTED]
--

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Weird interaction between int() and DateTime.timeTime

2000-05-25 Thread andres

On Thu, May 25, 2000 at 06:48:51PM +0100, Chris Withers wrote:
> "Jeff K. Hoffman" wrote:
> >   Python 1.5.2 (#3, Mar  8 2000, 16:34:52) [C] on sunos5
> >   Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >   >>>
> >   >>> f = 1.
> >   >>> f
> >   2.0
> >   >>> int(f)
> >   1
> >   >>>
> 
> > the int() function takes a different code path and returns 1, correctly.
> 
> Forgive my ignorance, but in what way is 1 correct here? Surely 2 is the
> what should be returned?!
> 

>From the python int doc string:

>>> print int.__doc__
int(x) -> integer
 
Convert a string or number to an integer, if possible.
A floating point argument will be truncated towards zero.   

--
Andres Corrada-Emmanuel   Email: [EMAIL PROTECTED]
--

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Weird interaction between int() and DateTime.timeTime

2000-05-25 Thread jq-zope

[EMAIL PROTECTED] writes:

> >>> t.timeTime()
> 953146937.0
> >>> int( t.timeTime() )
> 953146936  < This is wrong
> >>> int( 953146937.0 )
> 953146937   
> 
> Any ideas on how this can be happening. Stepping through the DateTime module
> yields the sensible return value of 953146937.0 but somehow int() converts
> this incorrectly.

int() works fine (truncating everything behind "."):

>>> t.timeTime() == 953146937.0
0
>>> t.timeTime() -  953146937.0
-4.76837158203e-07  
>>> int (round (t.timeTime()))
953146937   

jens


-- 
   http://www.jquade.de/

And here they are: Nitwit! Blubber! Oddment! Tweak!
  -- Albus Dumbledore


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Weird interaction between int() and DateTime.timeTime

2000-05-25 Thread Chris Withers

"Jeff K. Hoffman" wrote:
>   Python 1.5.2 (#3, Mar  8 2000, 16:34:52) [C] on sunos5
>   Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>   >>>
>   >>> f = 1.
>   >>> f
>   2.0
>   >>> int(f)
>   1
>   >>>

> the int() function takes a different code path and returns 1, correctly.

Forgive my ignorance, but in what way is 1 correct here? Surely 2 is the
what should be returned?!

Chris

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Weird interaction between int() and DateTime.timeTime

2000-05-25 Thread Jeff K. Hoffman

On Thu, 25 May 2000 [EMAIL PROTECTED] wrote:

> On Thu, May 25, 2000 at 12:56:48PM -0400, Shane Hathaway wrote:
> >
> > Simple: DateTime has been using floating-point calculations.  I believe
> > all of that has been corrected, however, with the new DateTime module,
> > available in the public CVS repository.
> > 
> > Shane
> > 
> 
> I don't understand how your answer explains the buggy behaviour. If
> DateTime.timeTime() returns a float that's okay. Why should a call to it
> wrapped with int() return the incorrect answer?
> 
> >> t.timeTime() 
> 953146937.0 
> >> int( t.timeTime() ) 
> 953146936
> >> int( 953146937.0 ) 
> 953146937

Check this out:

  Python 1.5.2 (#3, Mar  8 2000, 16:34:52) [C] on sunos5
  Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
  >>>
  >>> f = 1.
  >>> f
  2.0
  >>> int(f)
  1
  >>> 

This was on one of our Solaris boxes. Apparently, the string
representation of a float having the value 1. is 2.0, while
the int() function takes a different code path and returns 1, correctly.

I could be wrong, but I think that's what's biting you.

--Jeff

---
Jeff K. Hoffman   704.849.0731 x108
Chief Technology Officer  mailto:[EMAIL PROTECTED]
Going Virtual, L.L.C. http://www.goingv.com/


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Weird interaction between int() and DateTime.timeTime

2000-05-25 Thread Chris Withers

Shane Hathaway wrote:
> Simple: DateTime has been using floating-point calculations.  I believe
> all of that has been corrected, however, with the new DateTime module,
> available in the public CVS repository.

And will be in 2.2?

Chris

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Weird interaction between int() and DateTime.timeTime

2000-05-25 Thread andres

On Thu, May 25, 2000 at 12:56:48PM -0400, Shane Hathaway wrote:
>
> Simple: DateTime has been using floating-point calculations.  I believe
> all of that has been corrected, however, with the new DateTime module,
> available in the public CVS repository.
> 
> Shane
> 

I don't understand how your answer explains the buggy behaviour. If
DateTime.timeTime() returns a float that's okay. Why should a call to it
wrapped with int() return the incorrect answer?

>> t.timeTime() 
953146937.0 
>> int( t.timeTime() ) 
953146936
>> int( 953146937.0 ) 
953146937

--
Andres Corrada-Emmanuel   Email: [EMAIL PROTECTED]
--

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Weird interaction between int() and DateTime.timeTime

2000-05-25 Thread Shane Hathaway

[EMAIL PROTECTED] wrote:
> 
> In a previous posting about Netscape Image problems I mentioned a weird
> interaction between int() and DateTime.timeTime(). I can reproduce the error
> within the python interpreter as follows-
> 
> Python 1.5.2 (#5, Jan  6 2000, 17:10:24)  [GCC egcs-2.91.66 19990314/Linux
> (egcs- on linux2
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> from DateTime import DateTime
> >>> h = 'Wed, 15 Mar 2000 19:02:17 GMT'
> >>> t = DateTime( h )
> >>> print t
> 2000/03/15 19:02:17 GMT
> >>> t.timeTime()
> 953146937.0
> >>> int( t.timeTime() )
> 953146936  < This is wrong
> >>> int( 953146937.0 )
> 953146937
> 
> Any ideas on how this can be happening. Stepping through the DateTime module
> yields the sensible return value of 953146937.0 but somehow int() converts
> this incorrectly.

Simple: DateTime has been using floating-point calculations.  I believe
all of that has been corrected, however, with the new DateTime module,
available in the public CVS repository.

Shane

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




[Zope] Weird interaction between int() and DateTime.timeTime

2000-05-25 Thread andres

In a previous posting about Netscape Image problems I mentioned a weird
interaction between int() and DateTime.timeTime(). I can reproduce the error
within the python interpreter as follows-

Python 1.5.2 (#5, Jan  6 2000, 17:10:24)  [GCC egcs-2.91.66 19990314/Linux
(egcs- on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from DateTime import DateTime
>>> h = 'Wed, 15 Mar 2000 19:02:17 GMT'
>>> t = DateTime( h )
>>> print t
2000/03/15 19:02:17 GMT
>>> t.timeTime()
953146937.0
>>> int( t.timeTime() )
953146936  < This is wrong
>>> int( 953146937.0 )
953146937   

Any ideas on how this can be happening. Stepping through the DateTime module
yields the sensible return value of 953146937.0 but somehow int() converts
this incorrectly.

--
Andres Corrada-Emmanuel   Email: [EMAIL PROTECTED]
--

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )