forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Imaginary type and IEC 60559-compatible complex arithmetic #1
Draft
skirpichev
wants to merge
16
commits into
main
Choose a base branch
from
imaginary-class-109218
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
skirpichev
force-pushed
the
imaginary-class-109218
branch
2 times, most recently
from
May 25, 2024 13:45
7323971
to
99d1b8c
Compare
skirpichev
changed the title
gh-109218: Imaginary type and IEC 60559-compatible complex arithmetic
Imaginary type and IEC 60559-compatible complex arithmetic
Jun 9, 2024
skirpichev
force-pushed
the
imaginary-class-109218
branch
2 times, most recently
from
June 14, 2024 12:19
4db428d
to
6f13b24
Compare
skirpichev
force-pushed
the
imaginary-class-109218
branch
3 times, most recently
from
June 29, 2024 09:16
4ca3e9a
to
c114f16
Compare
skirpichev
pushed a commit
that referenced
this pull request
Jul 21, 2024
…ython#119498) (#1… (python#119905) Revert "[3.12] pythongh-69214: Fix fcntl.ioctl() request type (python#119498) (python#119505)" This reverts commit 078da88. The change modified how negative values, like termios.TIOCSWINSZ, was treated and is actually backward incompatible.
skirpichev
force-pushed
the
imaginary-class-109218
branch
from
July 25, 2024 07:51
36c6bf5
to
7e68e91
Compare
skirpichev
force-pushed
the
imaginary-class-109218
branch
from
August 3, 2024 07:19
6a44153
to
d605b8e
Compare
skirpichev
force-pushed
the
imaginary-class-109218
branch
from
October 1, 2024 04:15
2c3d2b4
to
db12274
Compare
skirpichev
force-pushed
the
imaginary-class-109218
branch
2 times, most recently
from
November 27, 2024 01:14
45dfe36
to
f9edb38
Compare
skirpichev
force-pushed
the
imaginary-class-109218
branch
2 times, most recently
from
November 27, 2024 04:14
36a5a26
to
517a029
Compare
…nGH-127256) Remove seriously outdated netlink constants. Co-authored-by: Gregory P. Smith <[email protected]>
…he Windows console (pythonGH-124059) Since MultiByteToWideChar()/WideCharToMultiByte() is not reversible if the data contains invalid UTF-8 sequences, use binary search to calculate the number of written bytes from the number of written characters. Also fix writing incomplete UTF-8 sequences. Also fix handling of memory allocation failures.
If the top-most frame is a trampoline frame, skip it.
…122289) Improve performance of this function by a factor of 1.7x. Co-authored-by: Barney Gale <[email protected]>
"Generally, mixed-mode arithmetic combining real and complex variables should be performed directly, not by first coercing the real to complex, lest the sign of zero be rendered uninformative; the same goes for combinations of pure imaginary quantities with complex variables." (c) Kahan, W: Branch cuts for complex elementary functions. That's why C standards since C99 introduce imaginary types. This patch proposes similar extension to the Python language: * Added a new subtype (imaginary) of the complex type. New type has few overloaded methods (conjugate() and __getnewargs__()). * Complex and imaginary types implement IEC 60559-compatible complex arithmetic (as specified by C11 Annex G). * Imaginary literals now produce instances of imaginary type. * cmath.infj/nanj were changed to be of imaginary type. * Modules ast, code, copy, marshal got support for imaginary type. * Few tests adapted to use complex, instead of imaginary literals - Lib/test/test_fractions.py - Lib/test/test_socket.py - Lib/test/test_str.py * Print dot for signed zeros in the real part of repr(complex): >>> complex(-0.0, 1) # was (-0+1j) (-0.0+1j) * repr(complex) naw prints real part even if it's zero. Lets consider (actually interrelated) problems, shown for unpatched code, which will be solved on this way. 1) New code allows to use complex arithmetic for implementation of mathematical functions without special "corner cases". Take the inverse tangent as an example: >>> z = complex(-0.0, 2) >>> cmath.atan(z) (-1.5707963267948966+0.5493061443340549j) >>> # real part was wrong: >>> 1j*(cmath.log(1 - 1j*z) - cmath.log(1 + 1j*z))/2 (1.5707963267948966+0.5493061443340549j) 2) Previously, we have only unsigned imaginary literals with the following semantics: ±a±bj = complex(±float(a), 0.0) ± complex(0.0, float(b)) While this behaviour was well documented, most users would expect instead here: ±a±bj = complex(±float(a), ±float(b)) i.e. that it follows to the rectangular notation for complex numbers. For example: >>> -0.0+1j # now (-0.0+1j) 1j >>> float('inf')*1j # now infj (nan+infj) 3) The ``eval(repr(x)) == x`` invariant was broken for the complex type: >>> complex(-0.0, 1.0) # also note funny signed integer zero below (-0+1j) >>> -0+1j 1j >>> complex(0.0, -cmath.inf) -infj >>> -cmath.infj (-0-infj)
skirpichev
force-pushed
the
imaginary-class-109218
branch
from
November 28, 2024 02:24
d56a55c
to
d062169
Compare
… process (pythonGH-127331) - Add `git describe` output to headers generated by `make_ssl_data.py` This info is more important than the date when the file was generated. It does mean that the tool now requires a Git checkout of OpenSSL, not for example a release tarball. - Regenerate the older file to add the info. To the other older file, add a note about manual edits. - Add notes on how to add a new OpenSSL version - Add 3.4 error messages and multissl tests
Reformat paragraphs, add backquotes, and directives.
Don't make the assumption that the 'name' argument is a string. Use repr() to format the 'name' argument instead.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
"Generally, mixed-mode arithmetic combining real and complex variables should be performed directly, not by first coercing the real to complex, lest the sign of zero be rendered uninformative; the same goes for combinations of pure imaginary quantities with complex variables." (c) Kahan, W: Branch cuts for complex elementary functions.
That's why C standards since C99 introduce imaginary types. This patch proposes similar extension to the Python language:
__getnewargs__()
).Lets consider (actually interrelated) problems, shown for unpatched code, which will be solved on this way.
While this behaviour was well documented, most users would expect instead here:
i.e. that it follows to the rectangular notation for complex numbers.
For example:
eval(repr(x)) == x
invariant was broken for the complex type. Below are simple examples with signed zero:See also ISO/IEC 9899:2011, Annex G and Rationale for C99 and Augmenting a Programming Language with Complex Arithmetic.
📚 Documentation preview 📚: https://cpython-previews--1.org.readthedocs.build/