summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
Commit message (Collapse)AuthorAgeFilesLines
* Added a new macro, Py_IS_FINITE(X). On windows there is an intrinsic for ↵Kristján Valur Jónsson2006-05-251-5/+2
| | | | this and it is more efficient than to use !Py_IS_INFINITE(X) && !Py_IS_NAN(X). No change on other platforms
* C++ compiler cleanup: bunch-o-casts, plus use of unsigned loop index var in ↵Skip Montanaro2006-04-181-1/+1
| | | | a couple places
* More C++-compliance. Note especially listobject.c - to get C++ to accept theAnthony Baxter2006-04-111-5/+5
| | | | | | | | | PyTypeObject structures, I had to make prototypes for the functions, and move the structure definition ahead of the functions. I'd dearly like a better way to do this - to change this would make for a massive set of changes to the codebase. There's still some warnings - this is purely to get rid of errors first.
* Remove unnecessary casts in type object initializers.Georg Brandl2006-03-301-12/+12
|
* Use %ld and casts to long for refcount printing, in absense of a universallyThomas Wouters2006-03-011-2/+6
| | | | | available %zd format character. Mark with an XXX comment so we can fix this, later.
* Revert backwards-incompatible const changes.Martin v. Löwis2006-02-271-1/+1
|
* Merge ssize_t branch.Martin v. Löwis2006-02-151-2/+2
|
* Fix icc warnings: remove unused variableNeal Norwitz2006-01-081-2/+1
|
* Add const to several API functions that take char *.Jeremy Hylton2005-12-101-1/+1
| | | | | | | | | | | | | | | | | | | In C++, it's an error to pass a string literal to a char* function without a const_cast(). Rather than require every C++ extension module to put a cast around string literals, fix the API to state the const-ness. I focused on parts of the API where people usually pass literals: PyArg_ParseTuple() and friends, Py_BuildValue(), PyMethodDef, the type slots, etc. Predictably, there were a large set of functions that needed to be fixed as a result of these changes. The most pervasive change was to make the keyword args list passed to PyArg_ParseTupleAndKewords() to be a const char *kwlist[]. One cast was required as a result of the changes: A type object mallocs the memory for its tp_doc slot and later frees it. PyTypeObject says that tp_doc is const char *; but if the type was created by type_new(), we know it is safe to cast to char *.
* Fix bugMichael W. Hudson2005-12-051-5/+13
| | | | | | | | [ 1346144 ] Segfaults from unaligned loads in floatobject.c by using memcpy and not just blinding casting char* to double*. Thanks to Rune Holm for the report.
* Apparently some compiler gives a warning onMichael W. Hudson2005-06-301-1/+1
| | | | | | float y = x; when x is a double. Go figure.
* This is my patch:Michael W. Hudson2005-05-271-239/+509
| | | | | | | | | | | | | | [ 1181301 ] make float packing copy bytes when they can which hasn't been reviewed, despite numerous threats to check it in anyway if noone reviews it. Please read the diff on the checkin list, at least! The basic idea is to examine the bytes of some 'probe values' to see if the current platform is a IEEE 754-ish platform, and if so _PyFloat_{Pack,Unpack}{4,8} just copy bytes around. The rest is hair for testing, and tests.
* Make subclasses of int, long, complex, float, and unicode perform typeBrett Cannon2005-04-261-1/+4
| | | | | | | conversion using the proper magic slot (e.g., __int__()). Also move conversion code out of PyNumber_*() functions in the C API into the nb_* function. Applied patch #1109424. Thanks Walter Doewald.
* float_richcompare(): Use the new Py_IS_NAN macro to ensure that, onTim Peters2004-09-231-11/+9
| | | | | platforms where that macro works, NaN compared to an int or long works the same as NaN compared to a finite float.
* SF bug #513866: Float/long comparison anomaly.Tim Peters2004-09-231-8/+206
| | | | | | | | | | | | | | | | | | When an integer is compared to a float now, the int isn't coerced to float. This avoids spurious overflow exceptions and insane results. This should compute correct results, without raising spurious exceptions, in all cases now -- although I expect that what happens when an int/long is compared to a NaN is still a platform accident. Note that we had potential problems here even with "short" ints, on boxes where sizeof(long)==8. There's #ifdef'ed code here to handle that, but I can't test it as intended. I tested it by changing the #ifdef to trigger on my 32-bit box instead. I suppose this is a bugfix candidate, but I won't backport it. It's long-winded (for speed) and messy (because the problem is messy). Note that this also depends on a previous 2.4 patch that introduced _Py_SwappedOp[] as an extern.
* Fix a couple of signed/unsigned comparison warningsNeal Norwitz2004-07-081-1/+1
|
* Patch #774665: Make Python LC_NUMERIC agnostic.Martin v. Löwis2004-06-081-3/+5
|
* Remove float_compare as perMichael W. Hudson2004-05-261-9/+1
| | | | | | [ 899109 ] 1==float('nan') which can now finally be closed, I think.
* Oops, didn't mean to commit the removal of float_compare!Michael W. Hudson2004-02-261-1/+1
|
* Pass a variable that actually exists to PyFPE_END_PROTECT inMichael W. Hudson2004-02-261-2/+2
| | | | float_richcompare. Reported on c.l.py by Helmut Jarausch.
* "Fix" (for certain configurations of the planets, includingMichael W. Hudson2004-02-191-1/+35
| | | | | | | | | | | recent gcc on Linux/x86) [ 899109 ] 1==float('nan') by implementing rich comparisons for floats. Seems to make comparisons involving NaNs somewhat less surprising when the underlying C compiler actually implements C99 semantics.
* Remove support for SunOS 4.Skip Montanaro2004-01-171-10/+0
| | | | Remove BAD_EXEC_PROTOYPE (leftover from IRIX 4 demolition).
* Getting rid of all the code inside #ifdef macintosh too.Jack Jansen2003-11-201-1/+1
|
* SF patch 703666: Several objects don't decref tmp on failure in subtype_newRaymond Hettinger2003-06-281-1/+3
| | | | | | Submitted By: Christopher A. Craig Fillin some missing decrefs.
* SF bug 705231: Assertion failed, python aborts.Tim Peters2003-05-241-6/+38
| | | | | | | float_pow(): Don't let the platform pow() raise -1.0 to an integer power anymore; at least glibc gets it wrong in some cases. Note that math.pow() will continue to deliver wrong (but platform-native) results in such cases.
* _PyFloat_Pack4(): Removed needless call of floor().Tim Peters2003-03-211-1/+1
|
* New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is aTim Peters2003-03-201-0/+313
| | | | | refactoring to get all the duplicates of this delicate code out of the cPickle and struct modules.
* Implement appropriate __getnewargs__ for all immutable subclassable builtinGuido van Rossum2003-01-291-1/+12
| | | | | | | | 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.
* Fix SF bug# 676155, RuntimeWarning with tp_compareNeal Norwitz2003-01-281-1/+4
| | | | Check return value of PyLong_AsDouble(), it can return an error.
* float_int(): Some systems raise an exception if a double is cast toTim Peters2002-11-211-14/+16
| | | | | | | | long but the double is too big to fit in a long. Prevent that. This closes some recent bug or patch on SF, but SF is down now so I can't say which. Bugfix candidate.
* Change int() so that passing a string, unicode, float or long argumentWalter Dörwald2002-11-191-11/+9
| | | | | | | that is outside the integer range no longer raises OverflowError, but returns a long object instead. This fixes SF bug http://www.python.org/sf/635115
* Improve exception message raised by PyFloat_AsDouble if the object does notNeil Schemenauer2002-11-181-2/+6
| | | | have a nb_float slot. This matches what PyInt_AsLong does.
* Call me anal, but there was a particular phrase that was speading toGuido van Rossum2002-08-191-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.
* staticforward bites the dust.Jeremy Hylton2002-07-171-1/+1
| | | | | | | | | | | | | | | The staticforward define was needed to support certain broken C compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the static keyword when it was used with a forward declaration of a static initialized structure. Standard C allows the forward declaration with static, and we've decided to stop catering to broken C compilers. (In fact, we expect that the compilers are all fixed eight years later.) I'm leaving staticforward and statichere defined in object.h as static. This is only for backwards compatibility with C extensions that might still use it. XXX I haven't updated the documentation.
* Patch #568124: Add doc string macros.Martin v. Löwis2002-06-131-2/+2
|
* clarify message when raising TypeError to indicate that float() acceptsSkip Montanaro2002-05-021-1/+1
| | | | strings or numbers
* SF bug 525705: [2.2] underflow raise OverflowException.Tim Peters2002-03-091-2/+2
| | | | | | | | | | | | | | | | | | | | Another year in the quest to out-guess random C behavior. Added macros Py_ADJUST_ERANGE1(X) and Py_ADJUST_ERANGE2(X, Y). The latter is useful for functions with complex results. Two corrections to errno- after-libm-call are attempted: 1. If the platform set errno to ERANGE due to underflow, clear errno. Some unknown subset of libm versions and link options do this. It's allowed by C89, but I never figured anyone would do it. 2. If the platform did not set errno but overflow occurred, force errno to ERANGE. C89 required setting errno to ERANGE, but C99 doesn't. Some unknown subset of libm versions and link options do it the C99 way now. Bugfix candidate, but hold off until some Linux people actually try it, with and without -lieee. I'll send a help plea to Python-Dev.
* float_floor_div: An expression like 3.//1j crashed the interpreter, orTim Peters2001-12-111-9/+12
| | | | | | | delivered bizarre results. Check float_divmod for a Py_NotImplemented return and pass it along (instead of treating Py_NotImplemented as a 2-tuple). CONVERT_TO_DOUBLE: Added comments; this macro is obscure.
* float_int_div(): For clarity, move this closer to the other floatTim Peters2001-12-111-16/+16
| | | | division functions, and rename to float_floor_div.
* PyFloat_AsStringEx(): This function takes an output char* but doesn'tTim Peters2001-11-281-8/+24
| | | | | | | pass the buffer length. Stop using it. It should be deprecated, but too late in the release cycle to do that now. New static format_float() does the same thing but requires passing the buffer length too. Use it instead.
* PyFloat_FromString(): Conversion of sprintf() to PyOS_snprintf() forBarry Warsaw2001-11-281-2/+4
| | | | buffer overrun avoidance.
* float_divmod(): the code wasn't sick enough to stop the MS optimizerTim Peters2001-11-011-1/+1
| | | | | from optimizing away mod's sign adjustment when mod == 0; so it got the intended result only in the debug build.
* SF bug #477221: abs and divmod act oddly with -0.0Tim Peters2001-11-011-9/+26
| | | | | | | Try to ensure that divmod(-0.0, 1.0) -> (-0.0, +0.0) across platforms. It always did on Windows, and still does. It didn't on Linux. Alas, there's no platform-independent way to write a test case for this. Bugfix candidate.
* float_abs() again: Guido pointed out that this could screw up in theTim Peters2001-11-011-6/+1
| | | | | | presence of NaNs. So pass the issue on to the platform libm fabs(); after all, fabs() is a std C function because you can't implement it correctly in portable C89.
* SF bug #477221: abs and divmod act oddly with -0.0.Tim Peters2001-11-011-9/+11
| | | | | | Partial fix. float_abs(): ensure abs(-0.0) returns +0.0. Bugfix candidate.
* SF patch #474590 -- RISC OS supportGuido van Rossum2001-10-241-0/+7
|
* Enable GC for new-style instances. This touches lots of files, sinceGuido van Rossum2001-10-051-2/+6
| | | | | | | | | | | | | | | | | | | | | | 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.
* Add additional coercion support for "self subtypes" to int, long,Guido van Rossum2001-09-191-0/+5
| | | | float (compare the recent checkin to complex). Added tests for these.
* Again perhaps the end of [#460020] bug or feature: unicode() and subclasses.Tim Peters2001-09-121-1/+1
| | | | | Inhibited complex unary plus optimization when applied to a complex subtype. Added PyComplex_CheckExact macro. Some comments and minor code fiddling.
* More bug 460020: when F is a subclass of float, disable the unary plusTim Peters2001-09-111-2/+6
| | | | optimization (+F(whatever)).