-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replaced the numeric string conversion functions, and made the api for them consistent #4656
Conversation
This looks fantastic. Thanks for trying to sort it out. I'm going to run the tests here and see if I can reproduce that assert failure. |
Just noticed an issue with |
When I ran Can you run it through |
Those are probably cases where the testsuite crashed on me before reaching them. Have to do an rebase to see if |
Okay, a rebase still gave me the same error while running coretest... Trying with a fresh clone right now. |
Even a fresh clone and build of incoming without any of my changes produces
while running coretest. Either my system broke in general, or something recent broke 32bit linux |
That is a new test case. I'll try a 32-bit build and see if I can reproduce. |
I wasn't able to reproduce on i686-unknown-linux-gnu with optimizations on. @Kimundi have you run There's no reason to delay because of this mystery, I think. I'll make sure everything passes here and push to the try bots. |
@brson Thanks for fixing it on my behalf. It was a completely fresh directory, |
I opened #4711 about this test failure. I have an idea of what the problem might be. If my hunch is right then the pointers in that failing assert will be pointers to two different functions, both called 'exit_runner'. |
@Kimundi I started working through this and found that the errors in |
For your reference, the function used by |
Gonna look into it. |
@brson Fixed all remaining errors, I'm going to rebase it one more time and then it's hopefully done. |
Reason: Better grouping of related modules, future-proving for a more extensive math library.
…k to char::to_digit().
Also fixes previous commit not compiling due to not finding Option.
They unify the different implementations that exists in int-template.rs, uint-template.rs and float.rs into one pair of functions, which are also in principle usable for anything that implements the necessary numeric traits. Their usage is somewhat complex due to the large amount of arguments each one takes, but as they're not meant to be used directly that shouldn't be a problem.
- Moved ToStr implementation of integers to int-template.rs. - Marked the `str()` function as deprecated. - Forwarded all conversion functions to `core::num::to_str_common()` and `core::num::from_str_common()`. - Fixed most places in the codebase where `to_str()` is being used. - Added int-template to_str and from_str overflow tests.
- Moved ToStr implementation of unsigned integers to uint-template.rs. - Marked the `str()` function as deprecated. - Forwarded all conversion functions to `core::num::to_str_common()` and `core::num::from_str_common()`. - Fixed most places in the codebase where `to_str()` is being used. - Added uint-template to_str and from_str overflow tests.
Fixed integer tests
…ions. Also fixed all conflicting calls of the old functions in the rest of the codebase. The set of string conversion functions for each float type now consists of those items: - to_str(), converts to number in base 10 - to_str_hex(), converts to number in base 16 - to_str_radix(), converts to number in given radix - to_str_exact(), converts to number in base 10 with a exact number of trailing digits - to_str_digits(), converts to number in base 10 with a maximum number of trailing digits - implementations for to_str::ToStr and num::ToStrRadix - from_str(), parses a string as number in base 10 including decimal exponent and special values - from_str_hex(), parses a string as a number in base 16 including binary exponent and special values - from_str_radix(), parses a string as a number in a given base excluding any exponent and special values - implementations for from_str::FromStr and num::FromStrRadix
Rebased it and made it pass make check. This should be good to merge now. |
Calling it on a special value now causes a failure, however `to_str_radix_special()` is provided which can be used if those values are expected, and which returns a tupel to allow differentating them.
Merged. Thanks and great work, Kimundi. |
Right now, the string conversion functions for floats and integers are inconsistent with each other and the rest of the library, eg integers had
str(n)
for converting to base 10 andto_str(n, radix)
for converting to a special base, while float hadto_str(n, digits)
which emitted a number in base 10 with up todigits
trailing fractional digits etc. Additionally, float.rs had it's own conversion functions that parsed/emitted a~str
, uint-template.rs had an own implementation that used an stack allocated[u8]
, int-template simply delegated to the uint function, and f32 and f64 had no functions at all, instead relying on the user casting to/from float. This is my attempt at untangling this:to_str_bytes()
andfrom_str_bytes()
functions to num.rs, along with some enums.from_str_bytes
takes a&[u8]
andto_str_bytes
returns a~[u8]
from_str()
andto_str()
wrappers are provided to make working with&str
and~str
easier.to_str()
just takes the number itself, and returns an as-exact-as-possible base 10 representationfrom_str()
just takes a string, and returns Some(n) if it parses as a number in base 10, accepting also valid variations like an decimal exponent on floating point values, inf, Nan, or an explicit leading '+'.to_str_radix()
emits the number in a given base as exact as possiblefrom_str_radix()
parses as a number in a given base but doesn't accept any special formats that could conflict (for example"inf"
).to_str_digits()
returns a string with up to n fractional digitsto_str_exact()
returns an string with exactly n fractional digitsto_str_hex()
returns an hexadecimal floating point representationfrom_str_hex()
accepts an hexadecimal floating point representation with an optional binary exponentFor backward compatibility, int-template.rs and uint-template.rs still have definitions for
str()
and some of the old functions for the local implementations that all now direct to the new generic ones. These should probably get thrown out in the long term, especially since half the other definitions changed anyway.Also, all places changed by the floating point conversion should probably checked on whether they should uses limited digits, or the maximum calculable digits, especially the part of repr.rs that I had to change looks strange.
Additionally, while debugging I noticed that when librustc gets compiled somewhere
to_str()
gets called on an int or uint that gets counted up the powers of twos until it overflows (at least on 32bit), not sure if thats intentional. The behavior of the old functions in such a case was just to overflow silently and emit an wrong string, so...As far as I know,
make check
passes completely, but after the rebase the test suite errors ontest private::at_exit::test_at_exit ...
withand doesn't complete because of that, so I can't be totally sure.
This should close the Issues #2608, #2649 (those functions no longer exits), #4126, #1784, #4314 and #4288.
I haven't looked at bigints yet, so I don't know if it would be useful there.
Lastly, as the new string conversion functions grew over time till they worked in all corner cases, performance might be considerably worse compared to the original versions, but I'm not sure if that's even a problem or how to tell.