about summary refs log tree commit diff
path: root/library/core/tests/num
AgeCommit message (Collapse)AuthorLines
2025-01-26Put all coretests in a separate cratebjorn3-5283/+0
2025-01-24Remove a bunch of emscripten test ignoresbjorn3-31/+29
They are either outdated as emscripten now supports i128 or they are subsumed by #[cfg_attr(not(panic = "unwind"), ignore]
2024-12-27Tidy up bigint mul methodsltdk-6/+119
2024-10-26Add test for all midpoint expectationsUrgau-0/+55
2024-10-26Round negative signed integer towards zero in `iN::midpoint`Urgau-2/+2
Instead of towards negative infinity as is currently the case. This done so that the obvious expectations of `midpoint(a, b) == midpoint(b, a)` and `midpoint(-a, -b) == -midpoint(a, b)` are true, which makes the even more obvious implementation `(a + b) / 2` true. https://github.com/rust-lang/rust/issues/110840#issuecomment-2336753931
2024-10-25library: consistently use American spelling for 'behavior'Ralf Jung-2/+2
2024-10-14Run most core::num tests in const context tooltdk-525/+504
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-5/+5
2024-08-31Improve documentation for <integer>::from_str_radixKappa322-0/+2
Two improvements to the documentation: - Document `-` as a valid character for signed integer destinations - Make the documentation even more clear that extra whitespace and non-digit characters is invalid. Many other languages, e.g. c++, are very permissive in string to integer routines and simply try to consume as much as they can, ignoring the rest. This is trying to make the transition for developers who are used to the conversion semantics in these languages a bit easier.
2024-08-31Rollup merge of #129640 - saethlin:unignore-android-in-alloc, r=tgross35Matthias Krüger-13/+5
Re-enable android tests/benches in alloc/core This is basically a revert of https://github.com/rust-lang/rust/pull/73729. These tests better work on android now; it's been 4 years and we don't use dlmalloc on that target anymore. And I've validated that they should pass now with a try-build :)
2024-08-28Improve `isqrt` tests and add benchmarksChai T. Rex-32/+249
* Choose test inputs more thoroughly and systematically. * Check that `isqrt` and `checked_isqrt` have equivalent results for signed types, either equivalent numerically or equivalent as a panic and a `None`. * Check that `isqrt` has numerically-equivalent results for unsigned types and their `NonZero` counterparts. * Reuse `ilog10` benchmarks, plus benchmarks that use a uniform distribution.
2024-08-28Enable some ilog2 tests as wellBen Kimock-13/+5
2024-08-25Remove cfg(test) from library/coreBen Kimock-655/+649
2024-08-20Change neutral element of <fNN as iter::Sum> to neg_zeroArthur Carcano-0/+28
The neutral element used to be positive zero, but +0 + -0 = +0 so -0 seems better indicated.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-13/+10
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-23add `is_multiple_of` for unsigned integer typesFolkert-0/+8
2024-06-21Rollup merge of #126613 - tgross35:log-test-update, r=cuviperMatthias Krüger-13/+13
Print the tested value in int_log tests Tiny change - from the failures in https://github.com/rust-lang/rust/pull/125016, it would have been nice to see what the tested values were. Update the assertion messages.
2024-06-20Add blank lines after module-level `//!` comments.Nicholas Nethercote-0/+1
Most modules have such a blank line, but some don't. Inserting the blank line makes it clearer that the `//!` comments are describing the entire module, rather than the `use` declaration(s) that immediately follows.
2024-06-17Print the tested value in int_log testsTrevor Gross-13/+13
2024-06-02Rollup merge of #121062 - RustyYato:f32-midpoint, r=the8472Jubilee-3/+26
Change f32::midpoint to upcast to f64 This has been verified by kani as a correct optimization see: https://github.com/rust-lang/rust/issues/110840#issuecomment-1942587398 The new implementation is branchless and only differs in which NaN values are produced (if any are produced at all), which is fine to change. Aside from NaN handling, this implementation produces bitwise identical results to the original implementation. Question: do we need a codegen test for this? I didn't add one, since the original PR #92048 didn't have any codegen tests.
2024-06-01Change f32::midpoint to upcast to f64RustyYato-3/+26
This has been verified by kani as a correct optimization see: https://github.com/rust-lang/rust/issues/110840#issuecomment-1942587398 The new implementation is branchless, and only differs in which NaN values are produced (if any are produced at all). Which is fine to change. Aside from NaN handling, this implementation produces bitwise identical results to the original implementation. The new implementation is gated on targets that have a fast 64-bit floating point implementation in hardware, and on WASM.
2024-03-30Make {integer}::from_str_radix constantGeorge Bateman-0/+10
2023-12-10remove redundant importssurechen-5/+0
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-10-22use visibility to check unused imports and delete some stmtsbohan-2/+0
2023-09-28isqrt: disable long running tests in MiriFederico Stra-0/+8
2023-09-26isqrt: add more testsFederico Stra-0/+32
2023-09-22isqrt: add testsFederico Stra-0/+21
2023-05-14Auto merge of #92048 - Urgau:num-midpoint, r=scottmcmbors-3/+105
Add midpoint function for all integers and floating numbers This pull-request adds the `midpoint` function to `{u,i}{8,16,32,64,128,size}`, `NonZeroU{8,16,32,64,size}` and `f{32,64}`. This new function is analog to the [C++ midpoint](https://en.cppreference.com/w/cpp/numeric/midpoint) function, and basically compute `(a + b) / 2` with a rounding towards ~~`a`~~ negative infinity in the case of integers. Or simply said: `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a sufficiently-large signed integral type. Note that unlike the C++ function this pull-request does not implement this function on pointers (`*const T` or `*mut T`). This could be implemented in a future pull-request if desire. ### Implementation For `f32` and `f64` the implementation in based on the `libcxx` [one](https://github.com/llvm/llvm-project/blob/18ab892ff7e9032914ff7fdb07685d5945c84fef/libcxx/include/__numeric/midpoint.h#L65-L77). I originally tried many different approach but all of them failed or lead me with a poor version of the `libcxx`. Note that `libstdc++` has a very similar one; Microsoft STL implementation is also basically the same as `libcxx`. It unfortunately doesn't seems like a better way exist. For unsigned integers I created the macro `midpoint_impl!`, this macro has two branches: - The first one take `$SelfT` and is used when there is no unsigned integer with at least the double of bits. The code simply use this formula `a + (b - a) / 2` with the arguments in the correct order and signs to have the good rounding. - The second branch is used when a `$WideT` (at least double of bits as `$SelfT`) is provided, using a wider number means that no overflow can occur, this greatly improve the codegen (no branch and less instructions). For signed integers the code basically forwards the signed numbers to the unsigned version of midpoint by mapping the signed numbers to their unsigned numbers (`ex: i8 [-128; 127] to [0; 255]`) and vice versa. I originally created a version that worked directly on the signed numbers but the code was "ugly" and not understandable. Despite this mapping "overhead" the codegen is better than my most optimized version on signed integers. ~~Note that in the case of unsigned numbers I tried to be smart and used `#[cfg(target_pointer_width = "64")]` to determine if using the wide version was better or not by looking at the assembly on godbolt. This was applied to `u32`, `u64` and `usize` and doesn't change the behavior only the assembly code generated.~~
2023-04-26Rollup merge of #110419 - jsoref:spelling-library, r=jyn514Matthias Krüger-1/+1
Spelling library Split per https://github.com/rust-lang/rust/pull/110392 I can squash once people are happy w/ the changes. It's really uncommon for large sets of changes to be perfectly acceptable w/o at least some changes. I probably won't have time to respond until tomorrow or the next day
2023-04-26Implement midpoint for all floating point f32 and f64Loïc BRANSTETT-3/+53
2023-04-26Implement midpoint for all signed and unsigned integersLoïc BRANSTETT-0/+52
2023-04-26Spelling library/Josh Soref-1/+1
* advance * aligned * borrowed * calculate * debugable * debuggable * declarations * desugaring * documentation * enclave * ignorable * initialized * iterator * kaboom * monomorphization * nonexistent * optimizer * panicking * process * reentrant * rustonomicon * the * uninitialized Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-19Auto merge of #110393 - fee1-dead-contrib:rm-const-traits, r=oli-obkbors-0/+2
Rm const traits in libcore See [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/.60const.20Trait.60.20removal.20or.20rework) * [x] Bless ui tests * [ ] Re constify some unstable functions with workarounds if they are needed
2023-04-16fix library and rustdoc testsDeadbeef-0/+2
2023-04-16Remove unused unused_macrosest31-1/+0
The macro is always used
2023-04-10remove obsolete testTobias Decking-11/+0
2023-04-10Improve the floating point parser in `dec2flt`.Tobias Decking-1/+1
* Remove all remaining traces of unsafe. * Put `parse_8digits` inside a loop. * Rework parsing of inf/NaN values.
2023-01-21Remove unnecessary `&format!`Nikolai Vazquez-1/+1
These were likely from before the `PartialEq<str>` impl for `&String`.
2023-01-04Update rand in the stdlib tests, and remove the getrandom feature from itThom Chiovoloni-4/+2
2022-11-16Auto merge of #102935 - ajtribick:display-float-0.5-fixed-0, r=scottmcmbors-2/+2
Fix inconsistent rounding of 0.5 when formatted to 0 decimal places As described in #70336, when displaying values to zero decimal places the value of 0.5 is rounded to 1, which is inconsistent with the display of other half-integer values which round to even. From testing the flt2dec implementation, it looks like this comes down to the condition in the fixed-width Dragon implementation where an empty buffer is treated as a case to apply rounding up. I believe the change below fixes it and updates only the relevant tests. Nevertheless I am aware this is very much a core piece of functionality, so please take a very careful look to make sure I haven't missed anything. I hope this change does not break anything in the wider ecosystem as having a consistent rounding behaviour in floating point formatting is in my opinion a useful feature to have. Resolves #70336
2022-10-14more dupe word typosRageking8-1/+1
2022-10-12Rollup merge of #102578 - lukas-code:ilog-panic, r=m-ou-seDylan DPC-0/+30
Panic for invalid arguments of `{integer primitive}::ilog{,2,10}` in all modes Decision made in https://github.com/rust-lang/rust/issues/100422#issuecomment-1245864700 resolves https://github.com/rust-lang/rust/issues/100422 tracking issue: https://github.com/rust-lang/rust/issues/70887 r? `@m-ou-se`
2022-10-11Fix inconsistent rounding of 0.5 when formatted to 0 decimal placesAndrew Tribick-2/+2
2022-10-07make const_err a hard errorRalf Jung-2/+0
2022-10-02add tests for panicking integer logarithmsLukas Markeffsky-0/+30
2022-09-09Auto merge of #93873 - Stovent:big-ints, r=m-ou-sebors-0/+48
Reimplement `carrying_add` and `borrowing_sub` for signed integers. As per the discussion in #85532, this PR reimplements `carrying_add` and `borrowing_sub` for signed integers. It also adds unit tests for both unsigned and signed integers, emphasing on the behaviours of the methods.
2022-08-09Rename integer log* methods to ilog*Eric Holk-78/+78
This reflects the concensus from the libs team as reported at https://github.com/rust-lang/rust/issues/70887#issuecomment-1209513261 Co-authored-by: Yosh Wuyts <github@yosh.is>
2022-05-30Implement carrying_add and borrowing_sub on signed numbersStovent-0/+48
2022-05-04Update `int_roundings` methods from feedbackJacob Pratt-14/+14
2022-04-18Remove unused macro rulesest31-12/+0