Live data from Hacker News

So you think you know what a number is

chris.improbable.org

11–20 of 35 posts

Re: So you think you know what a number is

#12

Earlier quoted context omitted.

No worries, I'm sure the next version of Unicode will have a single glyph that provides a complete introduction to the topic.

We need to extend Unicode to account for quantum computing and qubits. It needs to evolve into Qunicode. Text with this feature baked in could be called Quneiform. It should be stored on light-reflecting crystals that are manufactured using kilns.

[deleted]

Re: So you think you know what a number is

#13

Earlier quoted context omitted.

No worries, I'm sure the next version of Unicode will have a single glyph that provides a complete introduction to the topic.

We need to extend Unicode to account for quantum computing and qubits. It needs to evolve into Qunicode. Text with this feature baked in could be called Quneiform. It should be stored on light-reflecting crystals that are manufactured using kilns.

It's turtles all the way!

Re: So you think you know what a number is

#14

>>> int("۲۶۷۹") 2679 Thats pretty cool.

Indeed. Seems to be a thing of python 3.

    $ ruby -v
    ruby 2.2.6p396 (2016-11-15 revision 56800) [x86_64-linux-gnu]
    $ ruby -e "puts \"۲۶۷۹\".to_i"
    0

    $ python2.7 -c "print(int(\"۲۶۷۹\"))"
    Traceback (most recent call last):
    File "", line 1, in 
    ValueError: invalid literal for int() with base 10: '\xdb\xb2\xdb\xb6\xdb\xb7\xdb\xb9'

    $ python3.5 -c "print(int(\"۲۶۷۹\"))"
    2679

    $ node -v
    v6.9.1
    $ node -p "parseInt(\"۲۶۷۹\")"
    NaN

Re: So you think you know what a number is

#15
Note that Python has str.isdecimal, str.isdigit and str.isnumeric.

                isdecimal    isdigit   isnumeric

    12345        True        True       True
    ១2߃໔5        True        True       True
    ①²³🄅₅       False       True       True
    ⑩⒓          False       False      True
    Five         False       False      False
Use isdecimal if you want to call `int` (though it's EAFTP).

Re: So you think you know what a number is

#16
post #15

Note that Python has str.isdecimal, str.isdigit and str.isnumeric. isdecimal isdigit isnumeric 12345 True True True ១2߃໔5 True True True ①²³🄅₅ False True True ⑩⒓ False False True Five False False False Use isdecimal if you want to call `int` (though it's EAFTP).

Don't forget to special case negative numbers though.

Re: So you think you know what a number is

#17
Speaking of tools having trouble recognizing things, one of the more common "bug reports" I get is that the Tarsnap website is disclosing user email addresses -- specifically, "me@example.com" -- and paths -- specifically, the paths /home/auser and /home/anotheruser.

Re: So you think you know what a number is

#18
post #14

>>> int("۲۶۷۹") 2679 Thats pretty cool.

Indeed. Seems to be a thing of python 3. $ ruby -v ruby 2.2.6p396 (2016-11-15 revision 56800) [x86_64-linux-gnu] $ ruby -e "puts \"۲۶۷۹\".to_i" 0 $ python2.7 -c "print(int(\"۲۶۷۹\"))" Traceback (most recent call last): File " ", line 1, in ValueError: invalid literal for int() with base 10: '\xdb\xb2\xdb\xb6\xdb\xb7\xdb\xb9' $ python3.5 -c "print(int(\"۲۶۷۹\"))" 2679 $ node -v v6.9.1 $ node -p "parseInt(\"۲۶۷۹\")" Na…

It works in Python 2, you just have to ensure that your string is unicode. I can't get it to work directly from the command line for some reason, but if you open an interactive Python session it works:

  Python 2.7.12 (default, Dec 14 2016, 13:32:53) 
  [GCC 4.9.3] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> print(int(u'۲۶۷۹'))
  2679

Re: So you think you know what a number is

#19

>>> int("۲۶۷۹") 2679 Thats pretty cool.

That's what I thought as well when I first found it – once the initial surprise passed, it seems nice to have something just work for anyone using another script. The Unicode consortium has put an enormous amount of work into building that database and it's nice to reuse that to make something friendlier for humans.

Re: So you think you know what a number is

#20
post #18
post #14

Earlier quoted context omitted.

Indeed. Seems to be a thing of python 3. $ ruby -v ruby 2.2.6p396 (2016-11-15 revision 56800) [x86_64-linux-gnu] $ ruby -e "puts \"۲۶۷۹\".to_i" 0 $ python2.7 -c "print(int(\"۲۶۷۹\"))" Traceback (most recent call last): File " ", line 1, in ValueError: invalid literal for int() with base 10: '\xdb\xb2\xdb\xb6\xdb\xb7\xdb\xb9' $ python3.5 -c "print(int(\"۲۶۷۹\"))" 2679 $ node -v v6.9.1 $ node -p "parseInt(\"۲۶۷۹\")" Na…

It works in Python 2, you just have to ensure that your string is unicode. I can't get it to work directly from the command line for some reason, but if you open an interactive Python session it works: Python 2.7.12 (default, Dec 14 2016, 13:32:53) [GCC 4.9.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print(int(u'۲۶۷۹')) 2679

Hmm, interesting. What's up with the terminal here? The shell is doing something to the text.

    $ python2.7 -c "print(int(u'۲۶۷۹'))"
    Traceback (most recent call last):
    File "", line 1, in 
    ValueError: invalid literal for int() with base 10: '\xdb\xb2\xdb\xb6\xdb\xb7\xdb\xb9'
    
    $ python2.7 
    Python 2.7.13 (default, Jan 03 2017, 17:41:54) [GCC] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print(int(u'۲۶۷۹'))
    2679
Looking at what the string is:

    $ python2.7 -c "print(list(u'۲۶۷۹'))"
    [u'\xdb', u'\xb2', u'\xdb', u'\xb6', u'\xdb', u'\xb7', u'\xdb', u'\xb9']

    $ python2.7 
    Python 2.7.13 (default, Jan 03 2017, 17:41:54) [GCC] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print(list(u'۲۶۷۹'))
    [u'\u06f2', u'\u06f6', u'\u06f7', u'\u06f9']
Post reply on HN