summaryrefslogtreecommitdiff
path: root/tests/float
AgeCommit message (Collapse)Author
2018-09-27py/objfloat: Fix abs(-0.0) so it returns 0.0.Damien George
Nan and inf (signed and unsigned) are also handled correctly by using signbit (they were also handled correctly with "val<0", but that didn't handle -0.0 correctly). A test case is added for this behaviour.
2018-09-26py/modmath: Add math.factorial, optimised and non-opt implementations.Christopher Swenson
This commit adds the math.factorial function in two variants: - squared difference, which is faster than the naive version, relatively compact, and non-recursive; - a mildly optimised recursive version, faster than the above one. There are some more optimisations that could be done, but they tend to take more code, and more storage space. The recursive version seems like a sensible compromise. The new function is disabled by default, and uses the non-optimised version by default if it is enabled. The options are MICROPY_PY_MATH_FACTORIAL and MICROPY_OPT_MATH_FACTORIAL.
2018-09-20tests/float/float_parse.py: Add tests for accuracy of small decimals.Damien George
2018-09-04tests/float: Test -inf and some larger values for special math funcs.Damien George
2018-09-04tests/float/cmath_fun.py: Fix truncation of small real part of complex.Damien George
2018-06-12py/lexer: Add support for underscores in numeric literals.Damien George
This is a very convenient feature introduced in Python 3.6 by PEP 515.
2018-05-21tests: Add some tests for bigint hash, float hash and float parsing.Damien George
Following outcome of recent fuzz testing and sanitizing by @jepler.
2018-05-11tests/float/float_parse: Allow test to run on 32-bit archs.Damien George
Printing of uPy floats can differ by the floating-point precision on different architectures (eg 64-bit vs 32-bit x86), so it's not possible to using printing of floats in some parts of this test. Instead we can just check for equivalence with what is known to be the correct answer.
2018-03-01py/formatfloat: Fix case where floats could render with negative digits.Damien George
Prior to this patch, some architectures (eg unix x86) could render floats with "negative" digits, like ")". For example, '%.23e' % 1e-80 would come out as "1.0000000000000000/)/(,*0e-80". This patch fixes the known cases.
2018-03-01py/formatfloat: Fix case where floats could render with a ":" character.Damien George
Prior to this patch, some architectures (eg unix x86) could render floats with a ":" character in them, eg 1e+39 would come out as ":e+38" (":" is just after "9" in ASCII so this is like 10e+38). This patch fixes some of these cases.
2018-03-01py/formatfloat: Fix rounding of %f format with edge-case FP values.Damien George
Prior to this patch the %f formatting of some FP values could be off by up to 1, eg '%.0f' % 123 would return "122" (unix x64). Depending on the FP precision (single vs double) certain numbers would format correctly, but others wolud not. This patch should fix all cases of rounding for %f.
2018-02-26tests/float: Adjust float-parsing tests to pass with only a small error.Damien George
Float parsing (both single and double precision) may have a relative error of order the floating point precision, so adjust tests to take this into account by not printing all of the digits of the answer.
2018-02-08py/objfloat: Fix case of raising 0 to -infinity.Damien George
It was raising an exception but it should return infinity.
2018-02-08py/parsenum: Fix parsing of floats that are close to subnormal.Damien George
Prior to this patch, a float literal that was close to subnormal would have a loss of precision when parsed. The worst case was something like float('10000000000000000000e-326') which returned 0.0.
2017-12-19tests/float/builtin_float_hash: Add test to improve objfloat.c coverage.Damien George
2017-11-27py/parsenum: Improve parsing of floating point numbers.Damien George
This patch improves parsing of floating point numbers by converting all the digits (integer and fractional) together into a number 1 or greater, and then applying the correct power of 10 at the very end. In particular the multiple "multiply by 0.1" operations to build a fraction are now combined together and applied at the same time as the exponent, at the very end. This helps to retain precision during parsing of floats, and also includes a check that the number doesn't overflow during the parsing. One benefit is that a float will have the same value no matter where the decimal point is located, eg 1.23 == 123e-2.
2017-11-21py/objfloat: Allow float() to parse anything with the buffer protocol.Damien George
This generalises and simplifies the code and follows CPython behaviour.
2017-10-10py/formatfloat: Don't print the negative sign of a NaN value.Damien George
NaN may have the sign bit set but it has no meaning, so don't print it out.
2017-10-10py/modmath: Add full checks for math domain errors.Damien George
This patch changes how most of the plain math functions are implemented: there are now two generic math wrapper functions that take a pointer to a math function (like sin, cos) and perform the necessary conversion to and from MicroPython types. This helps to reduce code size. The generic functions can also check for math domain errors in a generic way, by testing if the result is NaN or infinity combined with finite inputs. The result is that, with this patch, all math functions now have full domain error checking (even gamma and lgamma) and code size has decreased for most ports. Code size changes in bytes for those with the math module are: unix x64: -432 unix nanbox: -792 stm32: -88 esp8266: +12 Tests are also added to check domain errors are handled correctly.
2017-09-26py/objfloat: Support raising a negative number to a fractional power.Damien George
This returns a complex number, following CPython behaviour. For ports that don't have complex numbers enabled this will raise a ValueError which gives a fail-safe for scripts that were written assuming complex numbers exist.
2017-09-04py/obj: Fix comparison of float/complex NaN with itself.Damien George
IEEE floating point is specified such that a comparison of NaN with itself returns false, and Python respects these semantics. This patch makes uPy also have these semantics. The fix has a minor impact on the speed of the object-equality fast-path, but that seems to be unavoidable and it's much more important to have correct behaviour (especially in this case where the wrong answer for nan==nan is silently returned).
2017-09-02py/objfloat: Fix binary ops with incompatible objects.Paul Sokolovsky
These are now returned as "operation not supported" instead of raising TypeError. In particular, this fixes equality for float vs incompatible types, which now properly results in False instead of exception. This also paves the road to support reverse operation (e.g. __radd__) with float objects. This is achieved by introducing mp_obj_get_float_maybe(), similar to existing mp_obj_get_int_maybe().
2017-07-25py: Implement raising a big-int to a negative power.Damien George
Before this patch raising a big-int to a negative power would just return 0. Now it returns a floating-point number with the correct value.
2017-07-04py/modmath: Check for zero division in log with 2 args.Damien George
2017-06-13py/formatfloat: Fix number of digits and exponent sign when rounding.Damien George
This patch fixes 2 things when printing a floating-point number that requires rounding up of the mantissa: - retain the correct precision; eg 0.99 becomes 1.0, not 1.00 - if the exponent goes from -1 to 0 then render it as +0, not -0
2017-06-08tests/float/builtin_float_minmax: PEP8 fixes.Paul Sokolovsky
2017-06-08tests/float: Convert "sys.exit()" to "raise SystemExit".Damien George
The latter is shorter and simpler because it doesn't require importing the sys module.
2017-04-04tests/float: Add tests for hashing float and complex numbers.Damien George
2017-04-03tests/float/byte*_construct: Skip on missing array module.Paul Sokolovsky
2017-03-24tests/float: Add tests for round() of inf, nan and large number.Damien George
2017-03-23tests/float: Add tests for math funcs that return ints.Damien George
One should test bigint, inf and nan to make sure all cases are covered.
2017-03-09tests/float: Make various tests skippable.Paul Sokolovsky
2017-03-07tests/string_format_modulo2: Split off intbig test.Paul Sokolovsky
2017-03-06tests/float2int*: Suffix with _intbig, don't run on any other int type.Paul Sokolovsky
I.e. they don't run successfully with MICROPY_LONGINT_IMPL_NONE and MICROPY_LONGINT_IMPL_LONGLONG (the problem is that they generate different output than CPython, TODO to fix that).
2017-03-06float/float2int*: Make actually be parsable for MICROPY_LONGINT_IMPL_NONE.Paul Sokolovsky
The use of large literal numbers is a big no-no when it comes to writing programs which work with different int representations. Also, some checks are pretty adhoc (e.g using struct module to check for 64-bitness). This change bases entire detection on sys.maxsize and integer operarions, and thus more correct, even if longer. Note that this change doesn't mean that any of these tests can pass with anything but MPZ - even despite checking for various int representations, the tests aren't written to be portable among them.
2017-03-06tests/float/complex1: Split out intbig test.Paul Sokolovsky
2017-02-03tests/float: Add tests for zero to a negative power.Damien George
2017-01-19tests/float: Add test for assigning to attribute of complex number.Damien George
2017-01-05tests/float: Improve formatfloat.c test coverage using Python.Rami Ali
2016-12-21tests: Add tests to improve coverage of runtime.c.Rami Ali
2016-12-20tests/float/builtin_float_round: Test round() with second arg.Damien George
2016-09-27tests/float: Add test for parsing a float from an empty string.Damien George
2016-03-29py/formatfloat: Fix further cases of buffer overflow in formatting.Damien George
Includes extensive test cases to catch hopefully all cases where buffer might overflow.
2016-03-15py/formatfloat: Fix buffer overflow when formatting tiny numbers.Damien George
2016-03-06test/string_format_fp30: Variant of string_format for 30-bit stuffed float.Paul Sokolovsky
2016-03-06test/float2int_fp30: Variant of float2int for 30-bit stuffed float.Paul Sokolovsky
2016-02-13float/string_format: Split large test in 2.Paul Sokolovsky
2016-02-13test/float2int: Make test output clearer.Paul Sokolovsky
2016-01-08tests: Fix math_fun_special test so it passes with single prec float.Damien George
2016-01-08tests: Allow float tests to run when MATH_SPECIAL_FUNCTIONS is disabled.Damien George