#4501 closed defect (duplicate)
preparser does not know about python notation for complex numbers
Reported by: | jason | Owned by: | somebody |
---|---|---|---|
Priority: | major | Milestone: | sage-duplicate/invalid/wontfix |
Component: | basic arithmetic | Keywords: | |
Cc: | Merged in: | ||
Authors: | Reviewers: | ||
Report Upstream: | Work issues: | ||
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
sage: 1j ------------------------------------------------------------ File "<ipython console>", line 1 Integer(1)j ^ SyntaxError: invalid syntax
but in python:
sage: preparser(False) sage: 1j 1j sage: type(1j) <type 'complex'>
Note that this does work now:
sage: 1rj 1j sage: 1rj == complex('j') True
Change History (9)
comment:1 Changed 12 years ago by
comment:2 Changed 12 years ago by
[10:57] <mhansen> jason-: I don't have time to make a patch now, but the following two lines around line 805 in sage/misc/preparser.py are the correct fix if we want 1j to return a <type 'complex'>: [10:57] <mhansen> elif i < len(line) and line[i] == 'j': [10:57] <mhansen> pass [10:57] <jason-> I can make a quick patch [10:57] <jason-> It needs to support "J" [10:57] <jason-> and also work for floating numbers too [10:58] <jason-> and then there's the issue of if we want to construct Sage complex numbers instead of python complex numbers
comment:3 Changed 12 years ago by
and the next line:
[10:58] <mhansen> Just change == "j" to in 'jJ'
comment:4 Changed 12 years ago by
I think 1j should be a Sage complex number.
comment:5 Changed 12 years ago by
I think 1j should be a Sage complex number.
And I think it should return a Python complex number. :-)
comment:6 Changed 12 years ago by
Your reasoning (that the userbase for this feature is almost entirely numeric users) has convinced me.
comment:7 Changed 12 years ago by
- Milestone changed from sage-3.2 to sage-3.2.1
comment:8 Changed 12 years ago by
- Resolution set to duplicate
- Status changed from new to closed
See #5079
comment:9 Changed 12 years ago by
- Milestone changed from sage-3.4.1 to sage-duplicate/invalid/wontfix
Note: See
TracTickets for help on using
tickets.
According to http://docs.python.org/reference/lexical_analysis.html#id7, python supports imaginary numbers being declared as:
imagnumber ::= (floatnumber | intpart) ("j" | "J")