summaryrefslogtreecommitdiffstatshomepage
path: root/py/formatfloat.c
Commit message (Collapse)AuthorAge
* all: Fix various spelling mistakes found by codespell 2.2.6.Damien George2023-10-03
| | | | Signed-off-by: Damien George <damien@micropython.org>
* all: Fix spelling mistakes based on codespell check.Damien George2023-04-27
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/formatfloat: Use pow(10, e) instead of pos/neg_pow lookup tables.Dan Ellis2022-08-12
| | | | | | | | | | | | | Rework the conversion of floats to decimal strings so it aligns precisely with the conversion of strings to floats in parsenum.c. This is to avoid rendering 1eX as 9.99999eX-1 etc. This is achieved by removing the power- of-10 tables and using pow() to compute the exponent directly, and that's done efficiently by first estimating the power-of-10 exponent from the power-of-2 exponent in the floating-point representation. Code size is reduced by roughly 100 to 200 bytes by this commit. Signed-off-by: Dan Ellis <dan.ellis@gmail.com>
* py/formatfloat: Format all whole-number floats exactly.Dan Ellis2022-07-26
| | | | | | | | | | | | | Formerly, py/formatfloat would print whole numbers inaccurately with nonzero digits beyond the decimal place. This resulted from its strategy of successive scaling of the argument by 0.1 which cannot be exactly represented in floating point. The change in this commit avoids scaling until the value is smaller than 1, so all whole numbers print with zero fractional part. Fixes issue #4212. Signed-off-by: Dan Ellis dan.ellis@gmail.com
* all: Fix implicit conversion from double to float.stijn2020-04-18
| | | | These are found when building with -Wfloat-conversion.
* all: Reformat C and Python source code with tools/codeformat.py.Damien George2020-02-28
| | | | This is run with uncrustify 0.70.1, and black 19.10b0.
* py/formatfloat: Fix case where floats could render with negative digits.Damien George2018-03-01
| | | | | | 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.
* py/formatfloat: Fix case where floats could render with a ":" character.Damien George2018-03-01
| | | | | | | 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.
* py/formatfloat: Fix rounding of %f format with edge-case FP values.Damien George2018-03-01
| | | | | | | 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.
* py/formatfloat: Use standard isinf, isnan funcs instead of custom ones.Damien George2017-10-10
| | | | Reduces code size by a tiny bit.
* py/formatfloat: Don't print the negative sign of a NaN value.Damien George2017-10-10
| | | | NaN may have the sign bit set but it has no meaning, so don't print it out.
* py/formatfloat: Don't post-increment variable that won't be used again.Damien George2017-08-21
|
* all: Use the name MicroPython consistently in commentsAlexander Steffen2017-07-31
| | | | | There were several different spellings of MicroPython present in comments, when there should be only one.
* all: Remove trailing spaces, per coding conventions.Damien George2017-07-19
|
* py,extmod: Some casts and minor refactors to quiet compiler warnings.Tom Collins2017-07-07
|
* py/formatfloat: Fix number of digits and exponent sign when rounding.Damien George2017-06-13
| | | | | | | 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
* py/formatfloat: Remove unreachable code.Damien George2017-01-19
| | | | | The if-block that this unreachable code is in has a condition "f>=5" so "fp_isless1(f)" will always fail.
* py/formatfloat: Fix further cases of buffer overflow in formatting.Damien George2016-03-29
| | | | | Includes extensive test cases to catch hopefully all cases where buffer might overflow.
* py/formatfloat: Fix case of float format where leading digit was "10".Damien George2016-03-29
| | | | | | | | | | When taking the logarithm of the float to determine the exponent, there are some edge cases that finish the log loop too large. Eg for an input value of 1e32-epsilon, this is actually less than 1e32 from the log-loop table and finishes as 10.0e31 when it should be 1.0e32. It is thus rendered as :e32 (: comes after 9 in ascii). There was the same problem with numbers less than 1.
* py/formatfloat: Fix buffer overflow when formatting tiny numbers.Damien George2016-03-15
|
* py/formatfloat: Add ability to format doubles with exponents > 99.Damien George2016-01-29
| | | | | | | | For single prec, exponents never get larger than about 37. For double prec, exponents can be larger than 99 and need 3 bytes to format. This patch makes the number of bytes needed configurable. Addresses issue #1772.
* py/formatfloat: Handle calculation of integer digit for %f format properly.Paul Sokolovsky2015-11-22
| | | | | %f prints true integer digit, so its calculation should happen before any exponential scaling.
* py/formatfloat: Workaround (fix?) incorrect rounding for %f format.Paul Sokolovsky2015-11-22
|
* py/formatfloat: Convert to fully portable implementation.Paul Sokolovsky2015-11-22
| | | | | | | | | | | This takes previous IEEE-754 single precision float implementation, and converts it to fully portable parametrizable implementation using C99 functions like signbit(), isnan(), isinf(). As long as those functions are available (they can be defined in adhoc manner of course), and compiler can perform standard arithmetic and comparison operations on a float type, this implementation will work with any underlying float type (including types whose mantissa is larger than available intergral integer type).
* stmhal: fix single precision float printing errorDave Hylands2015-09-11
| | | | Fixes #1435.
* py: Implement mp_format_float for doubles and use where appropriatestijn2015-05-17
| | | | | | | This allows using (almost) the same code for printing floats everywhere, removes the dependency on sprintf and uses just snprintf and applies an msvc-specific fix for snprintf in a single place so nan/inf are now printed correctly.
* py/formatfloat.c: Fix format of floating point numbers near 1.0.Dave Hylands2015-04-12
| | | | | | | | | | | In particular, numbers which are less than 1.0 but which round up to 1.0. This also makes those numbers which round up to 1.0 to print with e+00 rather than e-00 for those formats which print exponents. Addresses issue #1178.
* py: Move to guarded includes, everywhere in py/ core.Damien George2015-01-01
| | | | Addresses issue #1022.
* formatfloat.c: Typo fix in comment.Paul Sokolovsky2014-07-17
|
* Add license header to (almost) all files.Damien George2014-05-03
| | | | | | | Blanket wide to all .c and .h files. Some files originating from ST are difficult to deal with (license wise) so it was left out of those. Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
* Enhance str.format supportDave Hylands2014-04-01
| | | | | | | | | | | This adds support for almost everything (the comma isn't currently supported). The "unspecified" type with floats also doesn't behave exactly like python. Tested under unix with float and double Spot tested on stmhal
* py: Clean up includes.xbe2014-03-17
| | | | Remove unnecessary includes. Add includes that improve portability.
* Rename formatfloat file; remove MICROPY_ENABLE_FLOAT from mpconfigport.h.Damien George2014-03-10
MICROPY_ENABLE_FLOAT is automatically set in mpconfig.h if MICROPY_FLOAT_IMPL is set to a non-zero value.