summaryrefslogtreecommitdiff
path: root/numeric.c
Commit message (Collapse)AuthorAgeFilesLines
* numeric.c: Silence compiler warningKarl Williamson2021-07-251-1/+3
| | | | | | 'negative' is now only used when Perl_strtod() is not available. Recent commits e79f3c064561c5843af40cda89f98bb44f956729 and 7035863f5fa4306e58c8157b2a5893ba5e0f1eaf removed its other uses.
* numeric.c: White-space onlyKarl Williamson2021-07-251-7/+7
| | | | Properly indent some nested preprocessor directives in my_atof2()
* Perl_my_atof3: disallow double signs for Inf/NaNTAKAI Kousuke2021-07-251-13/+11
| | | | | | | | Perl_my_atof3 used to call S_my_atof_infnan after parsing sign character, but this led Inf/NaN with double signs (e.g. "+-Inf") to be wrongly accepted because S_my_atof_infnan will also parse sign itself. Also improved comment per suggestion from @hvds.
* Perl_my_atof3: disallow double signs and spaces between a sign and numberTAKAI Kousuke2021-07-251-2/+7
| | | | | | | | | | Perl_my_atof3 used to pass a substring after the first (optional) sign to (S_)strtod, which causes wrong numifications for strings like "-+3" or "+ 0x123" (for the latter case, while Perl_my_atof3 already had the code to block "0x" prefixes, this string will slip through due to the space character in it). For GH #18584.
* style: Detabify indentation of the C code maintained by the core.Michael G. Schwern2021-01-171-110/+110
| | | | | | | | | | | This just detabifies to get rid of the mixed tab/space indentation. Applying consistent indentation and dealing with other tabs are another issue. Done with `expand -i`. * vutil.* left alone, it's part of version. * Left regen managed files alone for now.
* perlapi: Add markupKarl Williamson2020-12-101-1/+1
|
* autodoc.pl: Specify scn for single-purpose filesKarl Williamson2020-11-061-3/+0
| | | | | | | | Many of the files in perl are for one thing only, and hence their embedded documentation will be for that one thing. By creating a hash here of them, those files don't have to worry about what section that documentation goes under, and so it can be completely changed without affecting them.
* remove dead code when using Perl_strtod for numeric conversionTony Cook2020-10-261-1/+7
| | | | | | | | | | | | | | | which is the common case. If strtod() is disabled, (and USE_PERL_ATOF isn't also disabled) this code is used, so I moved it into the #elif block. It's also possible to Configure disabling both strtod() and USE_PERL_ATOF with: ./Configure ... -Ud_strtod -Accflags=-DUSE_PERL_ATOF=0 ... which resulted in a build with a broken Perl_my_atof3(), so fail the build early with #error in that case.
* Document my_atofKarl Williamson2020-09-131-1/+12
|
* Reorganize perlapiKarl Williamson2020-09-041-1/+1
| | | | | This uses a new organization of sections that I came up with. I asked for comments on p5p, but there were none.
* perlapi: Don't display certain flag valuesKarl Williamson2020-08-271-6/+6
| | | | | These were not intended to go into perlapi, but the flag indicating so was mistakenly left off.
* Add missing boundary check to grok_infnanJohn Lightsey2020-08-211-3/+3
| | | | | | The grok_infnan() function was walking past the end of the string while skipping over trailing '0' characters. This is another variation of #17370.
* Fix a bunch of repeated-word typosDagfinn Ilmari Mannsåker2020-05-221-1/+1
| | | | | Mostly in comments and docs, but some in diagnostic messages and one case of 'or die die'.
* perlapi: Clarify grok_atoUV()Karl Williamson2020-04-041-2/+3
|
* grok_bin_oct_hex: Add some branch predictionsKarl Williamson2020-01-231-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This led to about a 7% improvement, number of branches went 2.3kk->1.9kk in perf, thanks to Sergey Aleynikov. cachegrind shows: Key: Ir Instruction read Dr Data read Dw Data write COND conditional branches IND indirect branches _m branch predict miss The numbers represent raw counts per loop iteration. eight_hex_digits 87654321 blead latest Ratio % ----- ------ ------- Ir 306.0 297.0 103.0 Dr 76.0 76.0 100.0 Dw 41.0 39.0 105.1 COND 26.0 26.0 100.0 IND 2.0 2.0 100.0 COND_m 0.1 0.0 Inf IND_m 3.0 3.0 100.0
* grok_bin_oct_hex: Fix overflow approximationKarl Williamson2020-01-231-4/+4
| | | | | | The multiplcation factor was itself overflowing, so need to change it to an NV. Also, the first time through this factor is not needed as what it is multiplying is 0, so set it to 0.
* Add two more flags to grok_bin_oct_hexKarl Williamson2020-01-231-2/+12
| | | | | | | | | | | | | | | | | | | | | | These add enough functionality so that other code that rolled its own version of this can call it instead and get the desired functionality. One flag silences warnings about overflow. It would be more consistent to use the existing flag that gets set when overflow is detected to silence the warnings if set on input. But that would be a change in (undocumented) behavior, and I thought it better to not chance breaking something. The other flag forbids an initial underscore when medial underscores are allowed. I wasn't aware until I examined the code and documentation carefully that the flag that I thought allowed single underscores between digits, actually also allows for an initial underscore. I can't imagine why that was the case, but \N{U+...} never allowed initial underscores, and adding a flag to grok_hex to allow just medial underscores allows \N{} in a future commit to change to use grok_hex() without changing behavior. Neither flag is currently exposed outside of the core or extensions
* numeric.c: White-space onlyKarl Williamson2020-01-191-20/+20
| | | | | | | Indent code that the previous commit added an enclosing block surrounding it. And vertically align some comments
* grok_bin_oct_hex: Add two output flagsKarl Williamson2020-01-191-4/+11
| | | | | | | | | | | | | | | | | | | | | | This commit adds two output flags returned from this function to the one previously existing, so that the caller can be informed of the problems found and take its own action. This involves the behavior of two existing flags, whose being set suppresses the warning if particular conditions exist in the input being parsed. Both flags were currently always cleared upon return. One of those flags is non-public. I changed it so that it isn't cleared upon return if the condition it describes is found. The other flag is public. I thought that some existing code, though unlikely, might be relying on the flag being always cleared. So I added a completely new flag from a previously unused bit that, if clear on input there is no change in behavior; but if set on input, it will remain set on output if the condition is met; otherwise cleared. The only code that could possibly be affected is that which sets this unused bit, but expects it to be cleared after the return. This is very unlikely.
* grok_bin_oct_hex: Unroll loop one more iterationKarl Williamson2020-01-181-4/+8
| | | | | | | | Earlier I was confused when I thought that 7 hex digits were the max before we needed to start worrying about overflow. That's true for signed results where everything above 7FFF_FFFF won't fit in a 32-bit signed integer. But these functions return unsigned, and so any 8 digits will fit in a 32-bit word.
* Refactor grok_number_flags to speed it upKarl Williamson2020-01-181-98/+148
| | | | | | | | | | | | | | | | | | | | | | This uses a variety of techniques to improve the performance. The chief one is to switch on the input length for the unrolled part of the loop, like is done in grok_bin_oct_hex(). This eliminates having to check if we are at the end of the string each time we process and advance a digit through it. Explicit branch predictions were added. One assumes that the input won't have a sign more frequently than it does have one. Some setup conditionals were eliminated. One way is that this ignores leading spaces. Previously, it just advanced through any and then checked if we are at the end of the string after having done so. That check can be eliminated if we didn't advance. Also, I check for a sign with a single conditional, eliminating a check for minus, then, if not found, one for plus. Instead, if it is a sign, there is an extra check for which one. Thus it rewards unsigned input, and penalizes signed, by a single conditional each way.
* Improve performance of grok_bin_oct_hex()Karl Williamson2020-01-131-45/+126
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit uses a variety of techniques for speeding this up. It is now faster than blead, and has less maintenance cost than before. Most of the checks that the current character isn't NUL are unnecssary. The logic works on that character, even if, for some reason, you can't trust the input length. A special test is added to not output the illegal character message if that character is a NUL. This is simply for backcompat. And a switch statement is used to unroll the loop for the leading digits in the number. This should handle most common cases. Beyond these, and one has to start worrying about overflow. So this version has removed that worrying from the common cases. Extra conditionals are avoided for large numbers by extracting the portability warning message code into a separate static function called from two different places. Simplifying this logic led me to see that if it overflowed, it must be non-portable, so another conditional could be removed. Other conditionals were removed at the expense of adding parameters to the function. This function isn't public, but is called from the grok_hex, et. al. macros. grok_hex knows, for example, that it is looking for an 'x' prefix and not a 'b'. Previously the code had a conditional to determine that. Similarly in pp.c, we look for the prefix. Having found it we can start the parse after the prefix, and tell this function not to look for it. Previously, this work was duplicated. The previous changes had left this function slower than blead. That is in part due to the fact that the loop doesn't go through that many iterations per function call, and the gcc compiler managed to optimize away the conditionals in XDIGIT_VALUE in the call of it from the loop. (The other call in this function did have the conditionals.) Thanks to Sergey Aleynikov for his help on this
* numeric.c: Slight restructure grok_bin_oct_hexKarl Williamson2020-01-131-5/+9
| | | | | | | This saves the input flags into a local variable and uses that in the rest of the function, and initializes the output flags at the beginning of the functions. This is in preparation for more output flags to be set, as we go along.
* numeric.c: White-space onlyKarl Williamson2020-01-131-10/+14
| | | | | Outdent code whose enclosing block was removed by the previous commit. A few other white space fixups.
* grok_bin_oct_hex: better ovrflw accuracy; rmv loop cond.Karl Williamson2020-01-131-16/+34
| | | | | This removes a conditional in the loop, and improves the accuracy of the overflow NV returned that approximates the desired input.
* perlapi: Move documentationKarl Williamson2020-01-131-1/+2
| | | | | | This flag doesn't actually occur in the functions in which the documentation for it is mentioned. Instead, move it to a function that does mention it.
* perlapi: Update grok_bin, _oct, _hexKarl Williamson2020-01-131-34/+42
| | | | | In examining these functions in detail, I found some things in the pod that were unclear or misleading. This is an attempt to clarify things.
* numeric.c: Move function in the fileKarl Williamson2020-01-131-37/+37
| | | | This makes adjacent all similar functions and their docs
* numeric.c: Fix typos in commentsKarl Williamson2020-01-131-2/+2
|
* grok_bin_oct_hex(): Add branch predictionKarl Williamson2020-01-131-2/+4
|
* Collapse grok_bin, _oct, _hex into one functionKarl Williamson2020-01-131-187/+92
| | | | | | | | | | These functions are identical in logic in the main loop, the difference being which digits they accept. The rest of the code had slight variations. This commit unifies the functions. I presume the reason they were kept separate was because of speed. Future commits will make this unified function faster than blead, and the reduced maintenance cost makes this worthwhile.
* perlapi: Perl_isinfnan: fix typoKarl Williamson2020-01-071-1/+1
|
* Add memCHRs() macro and use itKarl Williamson2019-12-181-1/+1
| | | | | | | This replaces strchr("list", c) calls throughout the core. They don't work properly when 'c' is a NUL, returning the position of the terminating NUL in "list" instead of failure. This could lead to segfaults or even security issues.
* Actually fix GH #17370Karl Williamson2019-12-171-0/+3
| | | | | | I only added a test, but not the change in 9f16475a53933d1d9c547f871b97b3b12160cece. The test passes except when run under address sanitizer or valgrind.
* PATCH: GH #17367 read 1 beyond end of bufferKarl Williamson2019-12-171-0/+3
| | | | | This is a bug in grok_infnan() in which in one place it failed to check that it was reading within bounds.
* Fix wrong apidoc lineKarl Williamson2019-11-301-1/+1
|
* handle s being updated without len being updatedTony Cook2019-11-121-1/+1
| | | | fix #17279
* The VC6 Chainsaw MassacreSteve Hay2019-10-171-7/+0
| | | | | Remove MS Visual C++ 6.0 support as agreed in the thread starting here: https://www.nntp.perl.org/group/perl.perl5.porters/2019/07/msg255625.html
* numeric.c: Note that flag bit names are documentedKarl Williamson2019-09-021-0/+13
|
* (perl #134230) don't interpret 0x, 0b when numifying stringsTony Cook2019-08-261-0/+9
|
* numeric.c: Fix typo in podKarl Williamson2019-07-311-1/+1
|
* numeric.c: Use full name of function in definitionKarl Williamson2019-05-241-1/+1
| | | | | | The prefix 'Perl_' was omitted, but this did not matter because there was a macro that expanded to include the prefix. But it's customary to have the expansion at the point of definition.
* numeric.c: Add #error caseKarl Williamson2019-05-241-0/+2
| | | | | It's best to have a #error case when nothing in the #if #else series is true, as it catches the problem at compile time.
* Create Strtod()Karl Williamson2019-04-191-2/+101
| | | | | | | | | | | | | | | | | | | | | | | | | | This commit creates my_strod() and a synonym, Strtod(), to emulate strtod() using the most precise function known to us that is available on the platform. strtod() is not in K&R, but is in C90, so atof() may be silently substituted instead on those few platforms without it. This function also correctly handles locale issues, such as if the radix character should be a dot or comma (or something else) depending on the parent perl code is using locale or not, and which locale. The symbol Perl_strtod continues to be defined on platforms which have some version of strtod(), for backward compatibility, and can be called as a function (or rather macro) but most applications should just use Strtod() and not sweat the details. This commit also fixes the problems with the prior commit: commit 4ac6fab20b8950ee14756c6f2438809c572082cd Author: Karl Williamson <khw@cpan.org> Date: Mon Apr 15 11:10:31 2019 -0600 PATCH: [perl #133945] Perl_strtod failures This commit wraps Perl_strtod() in macros that cause the proper radix character to be used.
* numeric.c: Change formal parameter to be constKarl Williamson2019-04-031-1/+1
| | | | as embed.fnc says it should be
* numeric.c: use new inRANGE macroKarl Williamson2019-03-291-10/+10
| | | | This commit halves the number of conditionals needed in this hot code.
* my_atof3() Fix uncommon bug where it wrongly failsKarl Williamson2019-01-181-0/+1
| | | | | | | | | | | | | | | | | | | | This bug showed up only on -Dusemymalloc without Debugging, and without various other common Configure options. It causes my_atof3() to return failure where in fact success was achieved. It apparently got triggered due to slight differences in malloc behaviors. The bug is that it changed a string pointer to new memory and forgot to change it back to the original value when that memory got freed. The test that fails is an equal/not equal of two pointers, and usually two pointers aren't the same, meaning the bug doesn't appear. The only case where my_atof3() is called is in parsing certain \p{nv=...} where "..." is not a rational number. So the scope of this bug is limited. Spotted by Ryan Voots.
* Fix preprocessor directive indentationDagfinn Ilmari Mannsåker2018-09-121-2/+2
|
* PATCH: [perl #41202] text->float gives wrong answersisyphus2018-08-091-8/+8
| | | | | | | | | | | | | This changes to use Perl_strtod() when available, and that turns out to be the key to fixing this bug. S_mulexp10() is removed from embed.fnc to avoid repeating the complicated prerequisites for defining Perl_strtod(). This works because this static function already was defined before use in numeric.c, and always called in full form without using a macro. James Keenan fixed a file permissions problem originally introduced by this commit, but the fix has been squashed into it.
* numeric.c: Move some code aroundKarl Williamson2018-08-091-4/+4
| | | | | | | | | | For readability, this changes if (f00) { MANY LINES } else { FEW LINES } to if (! f00) { FEW LINES } else { MANY LINES }