[Python-Dev] Floor division

Guido van Rossum guido at python.org
Thu Jan 25 22:22:54 CET 2007


The only thing I would miss about this is that I am used to write
certain timing loops that like to sync on whole seconds, by taking
time.time() % 1.0 which nicely gives me the milliseconds in the
current second. E.g.

while True:
  do_something_expensive_once_a_second_on_the_second()
  now = time.time()
  time.sleep(1.0 - (now % 1.0))

I guess I could use (now - int(now)) in a pinch, assuming int()
continues to truncate.

--Guido

On 1/25/07, Armin Rigo <arigo at tunes.org> wrote:
> Hi Tim,
>
> On Tue, Jan 23, 2007 at 05:14:29PM -0500, Tim Peters wrote:
> > For some reason `decimal` implemented __mod__ as the proposed
> > standard's "remainder" operation.  That's the immediate source of your
> > surprise.  IMO `decimal` should not have implemented __mod__ at all,
> > as Python's number-theoretic mod is not part of the proposed standard,
> > is a poor basis for a floating-point mod regardess, and it was a
> > mistake to implement decimal % decimal in a way so visibly different
> > from float % float and integer % integer:  it confuses the meaning of
> > "%".  That's your complaint, right?
>
> Thanks for the clarification.  Yes, it makes sense that __mod__,
> __divmod__ and __floordiv__ on float and decimal would eventually follow
> the same path as for complex (where they make even less sense and
> already raise a DeprecationWarning).
>
>
> A bientot,
>
> Armin.
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list