summaryrefslogtreecommitdiff
path: root/Objects/complexobject.c
AgeCommit message (Collapse)AuthorLines
2003-08-30Remove 'e.g.' from error messageRaymond Hettinger-3/+3
2003-06-17Fix typo in comment.Walter Dörwald-1/+1
2003-03-02Fix from Greg Chapman from SF bug #695651: a complex subclassGuido van Rossum-2/+3
constructor, when passed a single complex argument, returns the argument unchanged. This should be done only for the complex base class; a complex subclass should of course cast the value to the subclass in this case. The fix also revealed a segfault in complex_getnewargs(): the argument for the Py_BuildValue() format code "D" is the *address* of a Py_complex struct, not the value. (This corroborated by the API documentation.) I expect this needs to be backported to 2.2.3.
2003-01-29Implement appropriate __getnewargs__ for all immutable subclassable builtinGuido van Rossum-0/+7
types. The special handling for these can now be removed from save_newobj(). Add some testing for this. Also add support for setting the 'fast' flag on the Python Pickler class, which suppresses use of the memo.
2002-08-29complex() was the only numeric constructor that created a new instanceRaymond Hettinger-0/+9
when given its own type as an argument.
2002-08-19Call me anal, but there was a particular phrase that was speading toGuido van Rossum-1/+1
comments everywhere that bugged me: /* Foo is inlined */ instead of /* Inline Foo */. Somehow the "is inlined" phrase always confused me for half a second (thinking, "No it isn't" until I added the missing "here"). The new phrase is hopefully unambiguous.
2002-06-13Patch #568124: Add doc string macros.Martin v. Löwis-2/+2
2002-06-13Rearrange the #ifndef WITHOUT_COMPLEX so it can be picked up fromGuido van Rossum-2/+2
pyconfig.h.
2002-06-06Close SF bug 563740. complex() now finds __complex__() in new style classes.Raymond Hettinger-26/+23
Made conversion failure error messages consistent between types. Added related unittests.
2002-04-15Deprecate % as well. The message for deprecation of //, % and divmodGuido van Rossum-1/+6
is the same in all three cases (mostly because // calls divmod :-).
2002-04-15SF bug #543387.Guido van Rossum-0/+5
Complex numbers implement divmod() and //, neither of which makes one lick of sense. Unfortunately this is documented, so I'm adding a deprecation warning now, so we can delete this silliness, oh, around 2005 or so. Bugfix candidate (At least for 2.2.2, I think.)
2002-04-14SF bug 543840: complex(string) accepts strings with \0Tim Peters-1/+1
complex_subtype_from_string(): this stopped parsing at the first 0 byte, as if that were the end of the input string. Bugfix candidate.
2002-04-12PyObject_Del can now be used as a function designator.Neil Schemenauer-1/+1
2002-03-22SF bug 533198: Complex power underflow raises exception.Tim Peters-3/+9
Konrad was too kind. Not only did it raise an exception, the specific exception it raised made no sense. These are old bugs in complex_pow() and friends: 1. Raising 0 to a negative power isn't a range error, it's a domain error, so changed c_pow() to set errno to EDOM in that case instead of ERANGE. 2. Changed complex_pow() to: A. Used the Py_ADJUST_ERANGE2 macro to try to clear errno of a spurious ERANGE error due to underflow in the libm pow() called by c_pow(). B. Produced different exceptions depending on the errno value: i) For errno==EDOM, raise ZeroDivisionError instead of ValueError. This is for consistency with the non-complex cases 0.0**-2 and 0**-2 and 0L**-2. ii) For errno==ERANGE, raise OverflowError. Bugfix candidate.
2002-02-08Declare real and imag as read-only attributes.Guido van Rossum-2/+2
This fixes SF bug #514858 (Gregory Smith): complex not entirely immutable 2.2.1 Bugfix candidate!
2001-12-13Ensure that complex() only accepts a string argument as the first arg,Fred Drake-1/+13
and only if there is no second arg. This closes SF patch #479551.
2001-11-28complex_to_buf(), complex_subtype_from_c_complex(): Conversion ofBarry Warsaw-8/+10
sprintf() to PyOS_snprintf() for buffer overrun avoidance. complex_print(), complex_repr(), complex_str(): Call complex_to_buf() passing in sizeof(buf).
2001-10-25complex_subtype_from_string(): move the declaration of s_buffer[] outGuido van Rossum-1/+3
of the if block where it was before. The name is only used inside that if block, but the storage is referenced outside it via the 's' variable. (This patch was part of SF patch #474590 -- RISC OS support.)
2001-10-05Enable GC for new-style instances. This touches lots of files, sinceGuido van Rossum-1/+2
many types were subclassable but had a xxx_dealloc function that called PyObject_DEL(self) directly instead of deferring to self->ob_type->tp_free(self). It is permissible to set tp_free in the type object directly to _PyObject_Del, for non-GC types, or to _PyObject_GC_Del, for GC types. Still, PyObject_DEL was a tad faster, so I'm fearing that our pystone rating is going down again. I'm not sure if doing something like void xxx_dealloc(PyObject *self) { if (PyXxxCheckExact(self)) PyObject_DEL(self); else self->ob_type->tp_free(self); } is any faster than always calling the else branch, so I haven't attempted that -- however those types whose own dealloc is fancier (int, float, unicode) do use this pattern.
2001-09-27Merge branch changes (coercion, rich comparisons) into trunk.Guido van Rossum-4/+2
2001-09-24Do the same thing to complex that I did to str: the rich comparisonGuido van Rossum-7/+10
function returns NotImplemented when comparing objects whose tp_richcompare slot is not itself.
2001-09-20Add optional docstrings to member descriptors. For backwardsGuido van Rossum-3/+5
compatibility, this required all places where an array of "struct memberlist" structures was declared that is referenced from a type's tp_members slot to change the type of the structure to PyMemberDef; "struct memberlist" is now only used by old code that still calls PyMember_Get/Set. The code in PyObject_GenericGetAttr/SetAttr now calls the new APIs PyMember_GetOne/SetOne, which take a PyMemberDef argument. As examples, I added actual docstrings to the attributes of a few types: file, complex, instance method, super, and xxsubtype.spamlist. Also converted the symtable to new style getattr.
2001-09-19complex_coerce(): add explicit PyComplex_Check() test. Previously,Guido van Rossum-0/+5
complex_coerce() would never be called with a complex argument, because PyNumber_Coerce[Ex] doesn't bother calling the type's coercion method if the values already have the same type. But now, of course, it's possible to pass an instance of a complex *subtype*, and those must be accepted.
2001-09-12Again perhaps the end of [#460020] bug or feature: unicode() and subclasses.Tim Peters-11/+19
Inhibited complex unary plus optimization when applied to a complex subtype. Added PyComplex_CheckExact macro. Some comments and minor code fiddling.
2001-09-06Revert parts of patch #453627, documenting the resulting test failuresMartin v. Löwis-17/+1
instead.
2001-09-05Patch #453627: Define the following macros when compiling on a UnixWare 7.x ↵Martin v. Löwis-1/+17
system: SCO_ATAN2_BUG, SCO_ACCEPT_BUG, and STRICT_SYSV_CURSES. Work aroudn a bug in the SCO UnixWare atan2() implementation.
2001-09-04Raise OverflowError when appropriate on long->float conversion. Most ofTim Peters-0/+2
the fiddling is simply due to that no caller of PyLong_AsDouble ever checked for failure (so that's fixing old bugs). PyLong_AsDouble is much faster for big inputs now too, but that's more of a happy consequence than a design goal.
2001-09-04PEP 238 documented -Qwarn as warning only for classic int or longGuido van Rossum-1/+1
division, and this makes sense. Add -Qwarnall to warn for all classic divisions, as required by the fixdiv.py tool.
2001-08-31Add warning mode for classic division, almost exactly as specified inGuido van Rossum-1/+22
PEP 238. Changes: - add a new flag variable Py_DivisionWarningFlag, declared in pydebug.h, defined in object.c, set in main.c, and used in {int,long,float,complex}object.c. When this flag is set, the classic division operator issues a DeprecationWarning message. - add a new API PyRun_SimpleStringFlags() to match PyRun_SimpleString(). The main() function calls this so that commands run with -c can also benefit from -Dnew. - While I was at it, I changed the usage message in main() somewhat: alphabetized the options, split it in *four* parts to fit in under 512 bytes (not that I still believe this is necessary -- doc strings elsewhere are much longer), and perhaps most visibly, don't display the full list of options on each command line error. Instead, the full list is only displayed when -h is used, and otherwise a brief reminder of -h is displayed. When -h is used, write to stdout so that you can do `python -h | more'. Notes: - I don't want to use the -W option to control whether the classic division warning is issued or not, because the machinery to decide whether to display the warning or not is very expensive (it involves calling into the warnings.py module). You can use -Werror to turn the warnings into exceptions though. - The -Dnew option doesn't select future division for all of the program -- only for the __main__ module. I don't know if I'll ever change this -- it would require changes to the .pyc file magic number to do it right, and a more global notion of compiler flags. - You can usefully combine -Dwarn and -Dnew: this gives the __main__ module new division, and warns about classic division everywhere else.
2001-08-17Patch #445762: Support --disable-unicodeMartin v. Löwis-1/+3
- Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled - check for Py_USING_UNICODE in all places that use Unicode functions - disables unicode literals, and the builtin functions - add the types.StringTypes list - remove Unicode literals from most tests.
2001-08-16Patch #427190: Implement and use METH_NOARGS and METH_O.Martin v. Löwis-4/+2
2001-08-08Implement PEP 238 in its (almost) full glory.Guido van Rossum-0/+30
This introduces: - A new operator // that means floor division (the kind of division where 1/2 is 0). - The "future division" statement ("from __future__ import division) which changes the meaning of the / operator to implement "true division" (where 1/2 is 0.5). - New overloadable operators __truediv__ and __floordiv__. - New slots in the PyNumberMethods struct for true and floor division, new abstract APIs for them, new opcodes, and so on. I emphasize that without the future division statement, the semantics of / will remain unchanged until Python 3.0. Not yet implemented are warnings (default off) when / is used with int or long arguments. This has been on display since 7/31 as SF patch #443474. Flames to /dev/null.
2001-08-02Merge of descr-branch back into trunk.Tim Peters-12/+289
2001-03-18SF bug [ #409448 ] Complex division is braindeadTim Peters-8/+58
http://sourceforge.net/tracker/?func=detail&aid=409448&group_id=5470&atid=105470 Now less braindead. Also added test_complex.py, which doesn't test much, but fails without this patch.
2001-03-11When 1.6 boosted the # of digits produced by repr(float), repr(complex)Tim Peters-8/+32
apparently forgot to play along. Make complex act like float.
2001-01-18Use rich comparisons to fulfill an old wish: complex numbers now raiseGuido van Rossum-49/+84
exceptions when compared using <, <=, > or >=. NOTE: This is a tentative change: this means that cmp() involving complex numbers will raise an exception when the numbers differ, and that in turn means that e.g. dictionaries and certain other compounds (e.g. UserLists) containing complex numbers can't be compared either. So we'll have to decide whether this is acceptable. The alpha test cycle is a good time to keep an eye on this!
2000-09-26Rationalize use of limits.h, moving the inclusion to Python.h.Fred Drake-4/+0
Add definitions of INT_MAX and LONG_MAX to pyport.h. Remove includes of limits.h and conditional definitions of INT_MAX and LONG_MAX elsewhere. This closes SourceForge patch #101659 and bug #115323.
2000-09-01REMOVED all CWI, CNRI and BeOpen copyright markings.Guido van Rossum-9/+0
This should match the situation in the 1.6b1 tree.
2000-08-15Fix for http://sourceforge.net/bugs/?func=detailbug&bug_id=111866&group_id=5470.Tim Peters-46/+17
This was a misleading bug -- the true "bug" was that hash(x) gave an error return when x is an infinity. Fixed that. Added new Py_IS_INFINITY macro to pyport.h. Rearranged code to reduce growing duplication in hashing of float and complex numbers, pushing Trent's earlier stab at that to a logical conclusion. Fixed exceedingly rare bug where hashing of floats could return -1 even if there wasn't an error (didn't waste time trying to construct a test case, it was simply obvious from the code that it *could* happen). Improved complex hash so that hash(complex(x, y)) doesn't systematically equal hash(complex(y, x)) anymore.
2000-07-31merge Include/my*.h into Include/pyport.hPeter Schneider-Kamp-1/+0
marked my*.h as obsolete
2000-07-09ANSI-fication of the sources.Fred Drake-98/+48
2000-06-30Change copyright notice - 2nd try.Guido van Rossum-6/+0
2000-06-30Change copyright notice.Guido van Rossum-21/+6
2000-06-29This patch addresses two main issues: (1) There exist some non-fatalFred Drake-28/+9
errors in some of the hash algorithms. For exmaple, in float_hash and complex_hash a certain part of the value is not included in the hash calculation. See Tim's, Guido's, and my discussion of this on python-dev in May under the title "fix float_hash and complex_hash for 64-bit *nix" (2) The hash algorithms that use pointers (e.g. func_hash, code_hash) are universally not correct on Win64 (they assume that sizeof(long) == sizeof(void*)) As well, this patch significantly cleans up the hash code. It adds the two function _Py_HashDouble and _PyHash_VoidPtr that the various hashing routine are changed to use. These help maintain the hash function invariant: (a==b) => (hash(a)==hash(b))) I have added Lib/test/test_hash.py and Lib/test/output/test_hash to test this for some cases.
2000-05-03Vladimir Marangozov's long-awaited malloc restructuring.Guido van Rossum-5/+6
For more comments, read the patches@python.org archives. For documentation read the comments in mymalloc.h and objimpl.h. (This is not exactly what Vladimir posted to the patches list; I've made a few changes, and Vladimir sent me a fix in private email for a problem that only occurs in debug mode. I'm also holding back on his change to main.c, which seems unnecessary to me.)
2000-02-29Massive patch by Skip Montanaro to add ":name" to as manyGuido van Rossum-1/+1
PyArg_ParseTuple() format string arguments as possible.
2000-01-20The rest of the changes by Trent Mick and Dale Nagata for warning-freeGuido van Rossum-1/+1
compilation on NT Alpha. Mostly added casts etc.
1999-01-25Ai! complex_nonzero() has && which should be ||, else decidedlyGuido van Rossum-1/+1
non-zero things like 5j and complex(1,0) are considered to be zero/false. Tim Peters.
1998-05-07Add check to conjugate() that there are no excess arguments.Guido van Rossum-2/+5
1997-05-20Got rid of c_error in favor of errno (and EDOM/ERANGE).Guido van Rossum-49/+43
Assume that errno usage is thread-safe -- most vendors do this by making in a macro that refers to a per-thread storage area.