Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'u/jdemeyer/ticket/17808' into 6.7.b1
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric Chapoton committed Apr 19, 2015
2 parents 9d18e27 + f72c449 commit 293c474
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 82 deletions.
15 changes: 0 additions & 15 deletions src/doc/de/tutorial/tour_assignment.rst
Expand Up @@ -102,18 +102,3 @@ beliebigen Python-Typs innerhalb eines Sichtbarkeitsbereich aufnehmen.
Die Programmiersprache C, welche statisch typisiert ist, unterscheidet
sich hierzu stark; eine Variable, die dazu deklariert ist eine Ganzzahl (int)
aufzunehmen, kann in ihrem Sichtbarkeitsbereich auch nur ganze Zahlen aufnehmen.

Für Verwirrung in Python sorgt häufig, dass Integer Literale, die mit
Null beginnen als Oktalzahl, d.h. als Zahl zur Basis 8, behandelt werden.

::

sage: 011
9
sage: 8 + 1
9
sage: n = 011
sage: n.str(8) # Darstellung von n als String zur Basis 8
'11'

Dies ist konsistent mit der Programmiersprache C.
16 changes: 0 additions & 16 deletions src/doc/en/tutorial/tour_assignment.rst
Expand Up @@ -100,19 +100,3 @@ hold values of any Python type within a given scope:
The C programming language, which is statically typed, is much
different; a variable declared to hold an int can only hold an int
in its scope.

A potential source of confusion in Python is that an integer
literal that begins with a zero is treated as an octal number,
i.e., a number in base 8.

::

sage: 011
9
sage: 8 + 1
9
sage: n = 011
sage: n.str(8) # string representation of n in base 8
'11'

This is consistent with the C programming language.
16 changes: 0 additions & 16 deletions src/doc/fr/tutorial/tour_assignment.rst
Expand Up @@ -104,19 +104,3 @@ sein d'une même portée :
Le langage de programmation C, qui est statiquement typé, est bien
différent : une fois déclarée de type int, une variable ne peut contenir
que des int au sein de sa portée.

Un entier Python dont l'écriture commence par un zéro peut susciter des
confusions : il est considéré comme un nombre octal, c'est-à-dire un
nombre en base huit.

::

sage: 011
9
sage: 8 + 1
9
sage: n = 011
sage: n.str(8) # écriture en base 8 de n, sous forme de chaîne
'11'

Ceci est cohérent avec le langage de programmation C.
14 changes: 0 additions & 14 deletions src/doc/ru/tutorial/tour_assignment.rst
Expand Up @@ -97,17 +97,3 @@ Python имеет динамический контроль типов, так

Язык C, который имеет статический контроль типов, существенно отличается;
переменная, объявленная как целое число, может содержать только целое число.

Потенциальным источником путаницы в Python является тот факт, что
числовая константа, начинающаяся с 0, рассматривается как восьмеричное число,
т.е. число по основанию 8:

::

sage: 011
9
sage: 8 + 1
9
sage: n = 011
sage: n.str(8) # строка представляющая n по основанию 8
'11'
2 changes: 1 addition & 1 deletion src/sage/graphs/digraph.py
Expand Up @@ -3232,7 +3232,7 @@ def strongly_connected_components_digraph(self, keep_labels = False):
The following digraph has three strongly connected components,
and the digraph of those is a chain::
sage: g = DiGraph({0:{1:"01", 2: "02", 3: 03}, 1: {2: "12"}, 2:{1: "21", 3: "23"}})
sage: g = DiGraph({0:{1:"01", 2: "02", 3: "03"}, 1: {2: "12"}, 2:{1: "21", 3: "23"}})
sage: scc_digraph = g.strongly_connected_components_digraph()
sage: scc_digraph.vertices()
[{0}, {3}, {1, 2}]
Expand Down
31 changes: 12 additions & 19 deletions src/sage/repl/preparse.py
Expand Up @@ -660,9 +660,9 @@ def preparse_numeric_literals(code, extract=False):
sage: preparse_numeric_literals("0x10.sqrt()")
'Integer(0x10).sqrt()'
sage: preparse_numeric_literals('0o100')
"Integer('100', 8)"
'Integer(0o100)'
sage: preparse_numeric_literals('0b111001')
"Integer('111001', 2)"
'Integer(0b111001)'
sage: preparse_numeric_literals('0xe')
'Integer(0xe)'
sage: preparse_numeric_literals('0xEAR')
Expand Down Expand Up @@ -719,25 +719,18 @@ def preparse_numeric_literals(code, extract=False):
end += 1
num += '.'

num_name = numeric_literal_prefix + num.replace('.', 'p').replace('-', 'n').replace('+', '')

if len(num)>2 and num[1] in 'oObBxX':
# Py3 oct and bin support
num_name = numeric_literal_prefix + num
if num[1] in 'bB':
num_make = "Integer('%s', 2)" % num[2:]
elif num[1] in 'oO':
num_make = "Integer('%s', 8)" % num[2:]
else:
num_make = "Integer(%s)" % num
elif '.' in num or 'e' in num or 'E' in num or 'J' in postfix:
num_name = numeric_literal_prefix + num.replace('.', 'p').replace('-', 'n').replace('+', '')
if 'J' in postfix:
num_make = "ComplexNumber(0, '%s')" % num
num_name += 'j'
else:
num_make = "RealNumber('%s')" % num
if 'J' in postfix:
num_make = "ComplexNumber(0, '%s')" % num
num_name += 'j'
elif len(num) < 2 or num[1] in 'oObBxX':
num_make = "Integer(%s)" % num
elif '.' in num or 'e' in num or 'E' in num:
num_make = "RealNumber('%s')" % num
elif num[0] == "0":
num_make = "Integer('%s')" % num
else:
num_name = numeric_literal_prefix + num
num_make = "Integer(%s)" % num

literals[num_name] = num_make
Expand Down
3 changes: 2 additions & 1 deletion src/sage/rings/integer.pyx
Expand Up @@ -6203,6 +6203,7 @@ cdef int mpz_set_str_python(mpz_ptr z, char* s, int base) except -1:
10
sage: Integer('012')
doctest:...: DeprecationWarning: use 0o as octal prefix instead of 0
If you do not want this number to be interpreted as octal, remove the leading zeros.
See http://trac.sagemath.org/17413 for details.
10
Expand Down Expand Up @@ -6269,7 +6270,7 @@ cdef int mpz_set_str_python(mpz_ptr z, char* s, int base) except -1:
mpz_neg(z, z)
if warnoctal and mpz_sgn(z) != 0:
from sage.misc.superseded import deprecation
deprecation(17413, "use 0o as octal prefix instead of 0")
deprecation(17413, "use 0o as octal prefix instead of 0\nIf you do not want this number to be interpreted as octal, remove the leading zeros.")


cpdef LCM_list(v):
Expand Down

0 comments on commit 293c474

Please sign in to comment.