Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93405

Re: "normalizing" a value

From random832@fastmail.us
References <fd370a7b-ea6a-48e5-90f4-9d86b89a745e@googlegroups.com> <mailman.230.1435800465.3674.python-list@python.org> <948e2800-e52b-429a-9e00-f268fcff5085@googlegroups.com>
Subject Re: "normalizing" a value
Date 2015-07-01 22:23 -0400
Newsgroups comp.lang.python
Message-ID <mailman.231.1435803787.3674.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Jul 1, 2015, at 21:49, bvdp wrote:
> Interesting that negative values translate properly. That's an
> non-intuitive result to me. Guess I should have studied that math stuff
> harder way back when!

There are multiple interpretations of the operation, and not all
languages behave the same way as Python does with negative operands.
Python is the odd one out when one considers C/C++, C#, and Java which
all behave a different way.

In general, almost all languages behave in a way so that given q, r = a
// b, a % b; q * b + r == a. However, this simply changes the question
to how division results involving negative operands are rounded.

Here's an article by GvR about why python behaves the way it does:
http://python-history.blogspot.com/2010/08/why-pythons-integer-division-floors.html

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

"normalizing" a value bvdp <bob@mellowood.ca> - 2015-07-01 17:12 -0700
  Re: "normalizing" a value MRAB <python@mrabarnett.plus.com> - 2015-07-02 01:30 +0100
  Re: "normalizing" a value Paul Rubin <no.email@nospam.invalid> - 2015-07-01 17:36 -0700
  Re: "normalizing" a value Denis McMahon <denismfmcmahon@gmail.com> - 2015-07-02 01:06 +0000
  Re: "normalizing" a value random832@fastmail.us - 2015-07-01 21:27 -0400
    Re: "normalizing" a value bvdp <bob@mellowood.ca> - 2015-07-01 18:49 -0700
      Re: "normalizing" a value random832@fastmail.us - 2015-07-01 22:23 -0400
        Re: "normalizing" a value bvdp <bob@mellowood.ca> - 2015-07-01 19:41 -0700
      Re: "normalizing" a value Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-07-01 23:36 -0400
        Re: "normalizing" a value bvdp <bob@mellowood.ca> - 2015-07-02 10:03 -0700
  Re: "normalizing" a value Steven D'Aprano <steve@pearwood.info> - 2015-07-02 12:15 +1000
    Re: "normalizing" a value bvdp <bob@mellowood.ca> - 2015-07-01 19:42 -0700
  Re: "normalizing" a value Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-02 05:41 +0100
  Re: "normalizing" a value Skip Montanaro <skip.montanaro@gmail.com> - 2015-07-02 10:05 -0500

csiph-web