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


Groups > comp.lang.python > #94095 > unrolled thread

Integers with leading zeroes

Started bySteven D'Aprano <steve@pearwood.info>
First post2015-07-19 15:39 +1000
Last post2015-07-24 13:16 +0000
Articles 14 on this page of 34 — 17 participants

Back to article view | Back to comp.lang.python


Contents

  Integers with leading zeroes Steven D'Aprano <steve@pearwood.info> - 2015-07-19 15:39 +1000
    Re: Integers with leading zeroes Ian Kelly <ian.g.kelly@gmail.com> - 2015-07-18 23:46 -0600
    Re: Integers with leading zeroes "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-07-19 10:19 +0200
      Re: Integers with leading zeroes Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-19 12:58 -0700
    Re: Integers with leading zeroes Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-07-21 19:21 +0200
      Re: Integers with leading zeroes sohcahtoa82@gmail.com - 2015-07-21 10:58 -0700
        Re: Integers with leading zeroes Emile van Sebille <emile@fenx.com> - 2015-07-21 11:06 -0700
          Re: Integers with leading zeroes sohcahtoa82@gmail.com - 2015-07-21 11:38 -0700
            Re: Integers with leading zeroes sohcahtoa82@gmail.com - 2015-07-21 11:41 -0700
      Re: Integers with leading zeroes Steven D'Aprano <steve@pearwood.info> - 2015-07-22 10:55 +1000
        Re: Integers with leading zeroes Chris Angelico <rosuav@gmail.com> - 2015-07-22 11:10 +1000
          Re: Integers with leading zeroes Steven D'Aprano <steve@pearwood.info> - 2015-07-22 12:14 +1000
            Re: Integers with leading zeroes Chris Angelico <rosuav@gmail.com> - 2015-07-22 14:16 +1000
            Re: Integers with leading zeroes Laura Creighton <lac@openend.se> - 2015-07-22 09:12 +0200
              Re: Integers with leading zeroes alister <alister.nospam.ware@ntlworld.com> - 2015-07-22 09:09 +0000
                Re: Integers with leading zeroes Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-07-22 17:27 +0200
                  Re: Integers with leading zeroes Grant Edwards <invalid@invalid.invalid> - 2015-07-22 15:47 +0000
                Re: Integers with leading zeroes MRAB <python@mrabarnett.plus.com> - 2015-07-22 16:38 +0100
                  Re: Integers with leading zeroes Grant Edwards <invalid@invalid.invalid> - 2015-07-22 15:50 +0000
                    Re: Integers with leading zeroes MRAB <python@mrabarnett.plus.com> - 2015-07-22 17:24 +0100
                Re: Integers with leading zeroes Chris Angelico <rosuav@gmail.com> - 2015-07-23 08:32 +1000
            Re: Integers with leading zeroes Laura Creighton <lac@openend.se> - 2015-07-22 09:31 +0200
            Re: Integers with leading zeroes Ben Finney <ben+python@benfinney.id.au> - 2015-07-22 18:40 +1000
              Re: Integers with leading zeroes Marko Rauhamaa <marko@pacujo.net> - 2015-07-22 12:10 +0300
                Re: Integers with leading zeroes Laura Creighton <lac@openend.se> - 2015-07-22 11:38 +0200
                  Re: Integers with leading zeroes Marko Rauhamaa <marko@pacujo.net> - 2015-07-22 13:26 +0300
              Re: Integers with leading zeroes Grant Edwards <invalid@invalid.invalid> - 2015-07-22 13:51 +0000
                Re: Integers with leading zeroes Rustom Mody <rustompmody@gmail.com> - 2015-07-22 07:03 -0700
                Re: Integers with leading zeroes Steven D'Aprano <steve@pearwood.info> - 2015-07-23 01:14 +1000
                  Re: Integers with leading zeroes Grant Edwards <invalid@invalid.invalid> - 2015-07-22 15:20 +0000
                Re: Integers with leading zeroes Michael Torrie <torriem@gmail.com> - 2015-07-22 20:11 -0600
                  Re: Integers with leading zeroes Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-07-24 18:23 +1200
                    Re: Integers with leading zeroes Chris Angelico <rosuav@gmail.com> - 2015-07-24 16:28 +1000
                  Re: Integers with leading zeroes alister <alister.nospam.ware@ntlworld.com> - 2015-07-24 13:16 +0000

Page 2 of 2 — ← Prev page 1 [2]


#94405

FromChris Angelico <rosuav@gmail.com>
Date2015-07-23 08:32 +1000
Message-ID<mailman.889.1437604355.3674.python-list@python.org>
In reply to#94356
On Thu, Jul 23, 2015 at 1:38 AM, MRAB <python@mrabarnett.plus.com> wrote:
>> Does the same condition hold for strings? If you are not performing string
>> operations on something, it is not a string?
>>
> Tkinter comes to mind. You specify how widgets are laid out strings
> that are basically flags:
>
>     text_widget.pack(side=LEFT, fill=BOTH, expand=YES)
>
> where LEFT, BOTH and YES are strings.

The nearest term I can come up with here is that those three are
*atoms*. They might be implemented as integers (most C-style APIs work
that way), or as strings (which is apparently the case in Tkinter), or
as instances of object() that exist solely so their identities can be
checked (Python function default arguments are often done that way),
but there's only one operation you're allowed to do: Ask if one atom
is identical to another atom.

ChrisA

[toc] | [prev] | [next] | [standalone]


#94351

FromLaura Creighton <lac@openend.se>
Date2015-07-22 09:31 +0200
Message-ID<mailman.857.1437550314.3674.python-list@python.org>
In reply to#94340
I wonder if bitcoin miners and other cryptological users need the leading
0s.

Laura

[toc] | [prev] | [next] | [standalone]


#94355

FromBen Finney <ben+python@benfinney.id.au>
Date2015-07-22 18:40 +1000
Message-ID<mailman.860.1437554451.3674.python-list@python.org>
In reply to#94340
Laura Creighton <lac@openend.se> writes:

> The biggest use I have for decimal numbers that begin with 0 is in
> credit card numbers, account numbers and the like where the first
> check you do is 'does this thing have the correct number of digits'.

The following are examples of types from the real world that people
think of, and casually discuss, as “numbers”.

* Postal code
* Credit card number
* Telephone number
* Car registration plate number
* Personal Identification Number (PIN)

You can no doubt come up with other examples.

Despite that they are represented in text with digits, and the authority
that generates them may even use some sequence of integers, the types
should not be treated as numbers.

They are not quantities. Performing arithmetic on them (adding two
together, dividing by two, etc.) makes no sense. Representing them in a
different number base (e.g. hexadecimal) utterly changes their meaning.

And, as you've found, a leading zero makes a difference to the value. To
a computer (ignoring the legacy of octal representation), that makes
nonsense of the idea these are numbers.

So these types are not numbers and should not be treated that way in the
program.

These are, from the point of view of your computer program, opaque
tokens. They should be encoded not using a number type, but a type which
represents them as only a string of decimal digits.

Best if they're stored without spaces or punctuation; convert to and
from some format for human use if you must, but only at the input/output
borders of the program.

> So far, all the examples I've been able to find in my code -- which
> does this sort of stuff a lot -- is looking at string versions of
> decimal numbers, but I suspect there is old code out there in the
> wild which just used integers.

Maybe so, but I consider the latter kind of code to be a terrible
practice since it leads to assumptions in the code which are unfounded,
and which no human would ever make. Treat them the way a human actually
would: as an opaque tokem, a text (sequence of characters) that happen
to contain digits.

-- 
 \            “Simplicity is prerequisite for reliability.” —Edsger W. |
  `\                                                          Dijkstra |
_o__)                                                                  |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#94357

FromMarko Rauhamaa <marko@pacujo.net>
Date2015-07-22 12:10 +0300
Message-ID<878ua8imlc.fsf@elektro.pacujo.net>
In reply to#94355
Ben Finney <ben+python@benfinney.id.au>:

> Despite that they are represented in text with digits, and the
> authority that generates them may even use some sequence of integers,
> the types should not be treated as numbers.

Let's just say that the word "number" has multiple meanings. Words with
many meanings often lead to confusion.

My native Finnish luckily has distinct words for the two things: "luku"
(a quantity) and "numero" (a digit, numeral or label):

   luonnollinen luku (natural number)
   kokonaisluku      (integer)
   rationaaliluku    (rational number)
   reaaliluku        (real number)
   kompleksiluku     (complex number)
   liukuluku         (floating-point number)
   desimaaliluku     (decimal number)

   puhelinnumero     (telephone number)
   rekisterinumero   (registration number, license plate number)
   tilinumero        (account number)
   huoneen numero    (room number)
   sarjanumero       (serial number)
   tuotenumero       (product number)

Obviously, the words "liukuluku" and "desimaaliluku" slide into the
realms of numerals, but nevertheless, they deal with quantification
rather than identification.


Marko

[toc] | [prev] | [next] | [standalone]


#94358

FromLaura Creighton <lac@openend.se>
Date2015-07-22 11:38 +0200
Message-ID<mailman.861.1437557936.3674.python-list@python.org>
In reply to#94357
In a message of Wed, 22 Jul 2015 12:10:55 +0300, Marko Rauhamaa writes:
>My native Finnish luckily has distinct words for the two things: "luku"
>(a quantity) and "numero" (a digit, numeral or label):
>
>   luonnollinen luku (natural number)
>   kokonaisluku      (integer)
>   rationaaliluku    (rational number)
>   reaaliluku        (real number)
>   kompleksiluku     (complex number)
>   liukuluku         (floating-point number)
>   desimaaliluku     (decimal number)
>
>   puhelinnumero     (telephone number)
>   rekisterinumero   (registration number, license plate number)
>   tilinumero        (account number)
>   huoneen numero    (room number)
>   sarjanumero       (serial number)
>   tuotenumero       (product number)
>
>Obviously, the words "liukuluku" and "desimaaliluku" slide into the
>realms of numerals, but nevertheless, they deal with quantification
>rather than identification.
>
>
>Marko

What I want to know is why is 'huoneen numero' 2 words?

Laura

[toc] | [prev] | [next] | [standalone]


#94360

FromMarko Rauhamaa <marko@pacujo.net>
Date2015-07-22 13:26 +0300
Message-ID<87zj2oh4ir.fsf@elektro.pacujo.net>
In reply to#94358
Laura Creighton <lac@openend.se>:

> What I want to know is why is 'huoneen numero' 2 words?

rummets nummer


Marko

[toc] | [prev] | [next] | [standalone]


#94364

FromGrant Edwards <invalid@invalid.invalid>
Date2015-07-22 13:51 +0000
Message-ID<moo74i$bpn$1@reader1.panix.com>
In reply to#94355
On 2015-07-22, Ben Finney <ben+python@benfinney.id.au> wrote:
> Laura Creighton <lac@openend.se> writes:
>
>> The biggest use I have for decimal numbers that begin with 0 is in
>> credit card numbers, account numbers and the like where the first
>> check you do is 'does this thing have the correct number of digits'.
>
> The following are examples of types from the real world that people
> think of, and casually discuss, as “numbers”.
>
> * Postal code
> * Credit card number
> * Telephone number
> * Car registration plate number
> * Personal Identification Number (PIN)

Those are all strings.  Not numbers.

-- 
Grant Edwards               grant.b.edwards        Yow! does your DRESSING
                                  at               ROOM have enough ASPARAGUS?
                              gmail.com            

[toc] | [prev] | [next] | [standalone]


#94366

FromRustom Mody <rustompmody@gmail.com>
Date2015-07-22 07:03 -0700
Message-ID<9e864177-9677-484a-9486-8961310fac8c@googlegroups.com>
In reply to#94364
On Wednesday, July 22, 2015 at 7:21:29 PM UTC+5:30, Grant Edwards wrote:
> On 2015-07-22, Ben Finney wrote:
> > Laura Creighton writes:
> >
> >> The biggest use I have for decimal numbers that begin with 0 is in
> >> credit card numbers, account numbers and the like where the first
> >> check you do is 'does this thing have the correct number of digits'.
> >
> > The following are examples of types from the real world that people
> > think of, and casually discuss, as "numbers".
> >
> > * Postal code
> > * Credit card number
> > * Telephone number
> > * Car registration plate number
> > * Personal Identification Number (PIN)
> 
> Those are all strings.  Not numbers.

Cobol would represent these well (if I remember rightly) as
PIC 9(n) USAGE DISPLAY
The USAGE DISPLAY was the default and unnecessary to state explicitly whereas
the alternative USAGE COMP(UTATIONAL) corresponds to what most post-COBOL 
programmers think of as (binary) numbers.

[Just sayin'... NOT asking for python to have 'usage display' ints]

[toc] | [prev] | [next] | [standalone]


#94372

FromSteven D'Aprano <steve@pearwood.info>
Date2015-07-23 01:14 +1000
Message-ID<55afb360$0$1651$c3e8da3$5496439d@news.astraweb.com>
In reply to#94364
On Wed, 22 Jul 2015 11:51 pm, Grant Edwards wrote:

> On 2015-07-22, Ben Finney <ben+python@benfinney.id.au> wrote:
>> Laura Creighton <lac@openend.se> writes:
>>
>>> The biggest use I have for decimal numbers that begin with 0 is in
>>> credit card numbers, account numbers and the like where the first
>>> check you do is 'does this thing have the correct number of digits'.
>>
>> The following are examples of types from the real world that people
>> think of, and casually discuss, as “numbers”.
>>
>> * Postal code
>> * Credit card number
>> * Telephone number
>> * Car registration plate number
>> * Personal Identification Number (PIN)
> 
> Those are all strings.  Not numbers.

I'm pretty sure that was Ben's point :-)



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#94373

FromGrant Edwards <invalid@invalid.invalid>
Date2015-07-22 15:20 +0000
Message-ID<moocbn$qp5$1@reader1.panix.com>
In reply to#94372
On 2015-07-22, Steven D'Aprano <steve@pearwood.info> wrote:
> On Wed, 22 Jul 2015 11:51 pm, Grant Edwards wrote:
>
>> On 2015-07-22, Ben Finney <ben+python@benfinney.id.au> wrote:
>>> Laura Creighton <lac@openend.se> writes:
>>>
>>>> The biggest use I have for decimal numbers that begin with 0 is in
>>>> credit card numbers, account numbers and the like where the first
>>>> check you do is 'does this thing have the correct number of digits'.
>>>
>>> The following are examples of types from the real world that people
>>> think of, and casually discuss, as “numbers”.
>>>
>>> * Postal code
>>> * Credit card number
>>> * Telephone number
>>> * Car registration plate number
>>> * Personal Identification Number (PIN)
>> 
>> Those are all strings.  Not numbers.
>
> I'm pretty sure that was Ben's point :-)

Ah yes, now I see it was.

-- 
Grant Edwards               grant.b.edwards        Yow! HELLO, everybody,
                                  at               I'm a HUMAN!!
                              gmail.com            

[toc] | [prev] | [next] | [standalone]


#94431

FromMichael Torrie <torriem@gmail.com>
Date2015-07-22 20:11 -0600
Message-ID<mailman.904.1437636422.3674.python-list@python.org>
In reply to#94364
On 07/22/2015 07:51 AM, Grant Edwards wrote:
> On 2015-07-22, Ben Finney <ben+python@benfinney.id.au> wrote:
>> Laura Creighton <lac@openend.se> writes:
>>
>>> The biggest use I have for decimal numbers that begin with 0 is in
>>> credit card numbers, account numbers and the like where the first
>>> check you do is 'does this thing have the correct number of digits'.
>>
>> The following are examples of types from the real world that people
>> think of, and casually discuss, as “numbers”.
>>
>> * Postal code
>> * Credit card number
>> * Telephone number
>> * Car registration plate number
>> * Personal Identification Number (PIN)
> 
> Those are all strings.  Not numbers.

That depends.  A credit card number is indeed a number, and there are
mathematical formulas for determining if a particular number is a valid
(as in well-formed) credit card number, and possibly to identify what
kind of card it is.

[toc] | [prev] | [next] | [standalone]


#94492

FromGregory Ewing <greg.ewing@canterbury.ac.nz>
Date2015-07-24 18:23 +1200
Message-ID<d1e3ufFp4ugU1@mid.individual.net>
In reply to#94431
Michael Torrie wrote:
> A credit card number is indeed a number, and there are
> mathematical formulas for determining if a particular number is a valid
> (as in well-formed) credit card number,

If you're talking about the check-digit algorithm,
that doesn't treat the whole number as an integer,
it works on the individual digits:

http://www.datagenetics.com/blog/july42013/

> and possibly to identify what kind of card it is.

That's determined by the leading digits, and can
be done just as well by treating them as characters.

-- 
Greg

[toc] | [prev] | [next] | [standalone]


#94493

FromChris Angelico <rosuav@gmail.com>
Date2015-07-24 16:28 +1000
Message-ID<mailman.936.1437719335.3674.python-list@python.org>
In reply to#94492
On Fri, Jul 24, 2015 at 4:23 PM, Gregory Ewing
<greg.ewing@canterbury.ac.nz> wrote:
> Michael Torrie wrote:
>>
>> A credit card number is indeed a number, and there are
>> mathematical formulas for determining if a particular number is a valid
>> (as in well-formed) credit card number,
>
>
> If you're talking about the check-digit algorithm,
> that doesn't treat the whole number as an integer,
> it works on the individual digits:
>
> http://www.datagenetics.com/blog/july42013/
>
>> and possibly to identify what kind of card it is.
>
>
> That's determined by the leading digits, and can
> be done just as well by treating them as characters.

So, the definition of a number is: Something on which you perform
numeric operations. Aside from being circular, wouldn't this mean that
"rope" is a number, since its square root is string?

ChrisA

[toc] | [prev] | [next] | [standalone]


#94504

Fromalister <alister.nospam.ware@ntlworld.com>
Date2015-07-24 13:16 +0000
Message-ID<motdqh$gjl$1@speranza.aioe.org>
In reply to#94431
On Wed, 22 Jul 2015 20:11:47 -0600, Michael Torrie wrote:

> On 07/22/2015 07:51 AM, Grant Edwards wrote:
>> On 2015-07-22, Ben Finney <ben+python@benfinney.id.au> wrote:
>>> Laura Creighton <lac@openend.se> writes:
>>>
>>>> The biggest use I have for decimal numbers that begin with 0 is in
>>>> credit card numbers, account numbers and the like where the first
>>>> check you do is 'does this thing have the correct number of digits'.
>>>
>>> The following are examples of types from the real world that people
>>> think of, and casually discuss, as “numbers”.
>>>
>>> * Postal code * Credit card number * Telephone number * Car
>>> registration plate number * Personal Identification Number (PIN)
>> 
>> Those are all strings.  Not numbers.
> 
> That depends.  A credit card number is indeed a number, and there are
> mathematical formulas for determining if a particular number is a valid
> (as in well-formed) credit card number, and possibly to identify what
> kind of card it is.

no it is a string,that happens to be made up out of digits.
the digits can be manipulated but you do not perform maths on a credit 
card number as a whole




-- 
Did I do an INCORRECT THING??

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web