summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
Commit message (Collapse)AuthorAgeFilesLines
* Issue 705836: Fix struct.pack(">f", 1e40) to behave consistentlyMark Dickinson2008-03-141-8/+8
| | | | | | | | | | across platforms: it should now raise OverflowError on all platforms. (Previously it raised OverflowError only on non IEEE 754 platforms.) Also fix the (already existing) test for this behaviour so that it actually raises TestFailed instead of just referencing it.
* Backport of PEP 3101, Advanced String Formatting, from py3k.Eric Smith2008-02-171-0/+43
| | | | | | | | | | | | | | | Highlights: - Adding PyObject_Format. - Adding string.Format class. - Adding __format__ for str, unicode, int, long, float, datetime. - Adding builtin format. - Adding ''.format and u''.format. - str/unicode fixups for formatters. The files in Objects/stringlib that implement PEP 3101 (stringdefs.h, unicodedefs.h, formatter.h, string_format.h) are identical in trunk and py3k. Any changes from here on should be made to trunk, and changes will propogate to py3k).
* Patch #1953Christian Heimes2008-02-041-7/+23
| | | | | I implemented the function sys._compact_freelists() and C API functions PyInt_/PyFloat_CompactFreeList() to compact the pre-allocated blocks of ints and floats. They allow the user to reduce the memory usage of a Python process that deals with lots of numbers. The patch also renames sys._cleartypecache to sys._clear_type_cache
* Simpler solution to handling non-IEEE 754 environments.Raymond Hettinger2008-02-021-13/+3
|
* Add protection from weirdness while scaling the mantissa to an integer.Raymond Hettinger2008-02-011-5/+10
|
* Fix int/long typecase. Add check for non-binary floating point.Raymond Hettinger2008-02-011-2/+9
|
* labs() takes a long for an input.Raymond Hettinger2008-02-011-1/+1
|
* Integer ratio should return ints instead of longs whereever possible.Raymond Hettinger2008-02-011-2/+8
|
* Issue #1996: float.as_integer_ratio() should return fraction in lowest terms.Raymond Hettinger2008-02-011-85/+18
|
* The previous change was causing a segfault after multiple calls to ↵Christian Heimes2008-01-301-9/+5
| | | | Py_Initialize() and Py_Finalize().
* Fixed some references leaks in sys.Christian Heimes2008-01-301-1/+0
|
* Moved Rational._binary_float_to_ratio() to float.as_integer_ratio() becauseJeffrey Yasskin2008-01-271-0/+159
| | | | | | | it's useful outside of rational numbers. This is my first C code that had to do anything significant. Please be more careful when looking over it.
* Add prototypes to get the mathmodule.c to compile on OSF1 5.1 (Tru64)Neal Norwitz2008-01-251-0/+5
| | | | | and eliminate a compiler warning in floatobject.c. There might be a better way to go about this, but it should be good enough for now.
* Now that I've learnt about structseq objects I felt like converting ↵Christian Heimes2008-01-141-29/+78
| | | | | | sys.float_info to a structseq. It's readonly and help(sys.float_info) explains the attributes nicely.
* Continue rolling back pep-3141 changes that changed behavior from 2.5. ThisJeffrey Yasskin2008-01-051-55/+3
| | | | | | | | | | | | round included: * Revert round to its 2.6 behavior (half away from 0). * Because round, floor, and ceil always return float again, it's no longer necessary to have them delegate to __xxx___, so I've ripped that out of their implementations and the Real ABC. This also helps in implementing types that work in both 2.6 and 3.0: you return int from the __xxx__ methods, and let it get enabled by the version upgrade. * Make pow(-1, .5) raise a ValueError again.
* Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (justJeffrey Yasskin2008-01-031-26/+82
| | | | | | | the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361, r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new documentation. The only significant difference is that round(x) returns a float to preserve backward-compatibility. See http://bugs.python.org/issue1689.
* #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and ↵Christian Heimes2007-12-191-12/+12
| | | | Py_REFCNT. Macros for b/w compatibility are available.
* Applied patch #1635: Float patch for inf and nan on Windows (and other ↵Christian Heimes2007-12-181-1/+49
| | | | | | platforms). The patch unifies float("inf") and repr(float("inf")) on all platforms.
* The new float repr causes too much trouble and pain. I'm disabling the ↵Christian Heimes2007-12-111-1/+12
| | | | | | | feature until we have sorted out the issues on all machines. 64bit machines seem to have issues and Guido has reported even worse. Guido: It's pretty bad actually -- repr(1e5) comes out as '1.0'... Ditto for repr(1eN) for most N... Both in 2.6 and in 3.0...
* Backport of r59456:59458 from py3k to trunkChristian Heimes2007-12-101-2/+106
| | | | | | Issue #1580: New free format floating point representation based on "Floating-Point Printer Sample Code", by Robert G. Burger. For example repr(11./5) now returns '2.2' instead of '2.2000000000000002'. Thanks to noam for the patch! I had to modify doubledigits.c slightly to support X64 and IA64 machines on Windows. I also added the new file to the three project files.
* Feature #1534Christian Heimes2007-12-011-0/+47
| | | | | Added PyFloat_GetMax(), PyFloat_GetMin() and PyFloat_GetInfo() to the float API. Added a dictionary sys.float_info with information about the internal floating point type to the sys module.
* Add a bunch of GIL release/acquire points in tp_print implementations and forBrett Cannon2007-09-171-0/+2
| | | | | | PyObject_Print(). Closes issue #1164.
* PEP 3123: Provide forward compatibility with Python 3.0, while keepingMartin v. Löwis2007-07-211-14/+13
| | | | | backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and PyVarObject_HEAD_INIT.
* Remove dead code. This code couldn't be reached because earlier inNeal Norwitz2007-05-031-12/+1
| | | | the function there is another check for z != Py_None.
* Reverting the patch that tried to fix the issue whereby x**2 raisesAlex Martelli2006-08-231-3/+3
| | | | | | | OverflowError while x*x succeeds and produces infinity; apparently these inconsistencies cannot be fixed across ``all'' platforms and there's a widespread feeling that therefore ``every'' platform should keep suffering forevermore. Ah well.
* x**2 should about equal x*x (including for a float x such that the result isAlex Martelli2006-08-231-3/+3
| | | | | | inf) but didn't; added a test to test_float to verify that, and ignored the ERANGE value for errno in the pow operation to make the new test pass (with help from Marilyn Davis at the Google Python Sprint -- thanks!).
* 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.