summary refs log tree commit diff
path: root/src/libcore/num
AgeCommit message (Collapse)AuthorLines
2019-12-15use Self alias in place of macrosLzu Tao-2/+2
2019-12-15Rollup merge of #67305 - kappa:patch-1, r=jonas-schievinkMazdak Farrokhzad-1/+1
Doc typo
2019-12-14Doc typoAlex Kapranoff-1/+1
2019-12-14Auto merge of #67224 - nikomatsakis:revert-stabilization-of-never-type, ↵bors-0/+11
r=centril Revert stabilization of never type Fixes https://github.com/rust-lang/rust/issues/66757 I decided to keep the separate `never-type-fallback` feature gate, but tried to otherwise revert https://github.com/rust-lang/rust/pull/65355. Seemed pretty clean. ( cc @Centril, author of #65355, you may want to check this over briefly )
2019-12-14Revert "Stabilize the `never_type`, written `!`."Niko Matsakis-1/+1
This reverts commit 15c30ddd69d6cc3fffe6d304c6dc968a5ed046f1.
2019-12-14Revert "Redefine `core::convert::Infallible` as `!`."Niko Matsakis-0/+11
This reverts commit 089229a1935fa9795cfdefa518c8f8c3beb66db8.
2019-12-13Require stable/unstable annotations for the constness of all stable ↵Oliver Scherer-17/+329
functions with a `const` modifier
2019-12-10Auto merge of #66277 - peter-wilkins:impl-from-wider-non-zeros, r=SimonSapinbors-85/+96
From<NonZero*> impls for wider NonZero types Closes: https://github.com/rust-lang/rust/issues/66291
2019-12-08move from non zero impls to `libcore/convert/num.rs`Peter-2058/+1955
2019-12-06Format libcore with rustfmt (including tests and benches)David Tolnay-1/+4
2019-12-06Move numeric `From` and `TryFrom` impls to `libcore/convert/num.rs`Simon Sapin-330/+1
This makes `libcore/num/mod.rs` slightly smaller. It’s still 4911 lines and not easy to navigate. This doesn’t change any public API.
2019-12-06Add `{f32,f64}::approx_unchecked_to<Int>` unsafe methodsSimon Sapin-2/+62
As discussed in https://github.com/rust-lang/rust/issues/10184 Currently, casting a floating point number to an integer with `as` is Undefined Behavior if the value is out of range. `-Z saturating-float-casts` fixes this soundness hole by making `as` “saturate” to the maximum or minimum value of the integer type (or zero for `NaN`), but has measurable negative performance impact in some benchmarks. There is some consensus in that thread for enabling saturation by default anyway, but provide an `unsafe fn` alternative for users who know through some other mean that their values are in range.
2019-11-29Make dec2flt_table compatible with rustfmtDavid Tolnay-1225/+1231
2019-11-28Clarify `{f32,f64}::EPSILON` docsOhad Ravid-2/+2
2019-11-27Rollup merge of #66769 - fusion-engineering-forks:tau-constant, r=dtolnayTyler Mandry-0/+12
Add core::{f32,f64}::consts::TAU. ### **`τ`**
2019-11-26Format libcore with rustfmtDavid Tolnay-334/+551
This commit applies rustfmt with default settings to files in src/libcore *that are not involved in any currently open PR* to minimize merge conflicts. The list of files involved in open PRs was determined by querying GitHub's GraphQL API with this script: https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8 With the list of files from the script in `outstanding_files`, the relevant commands were: $ find src/libcore -name '*.rs' | xargs rustfmt --edition=2018 $ rg libcore outstanding_files | xargs git checkout -- Repeating this process several months apart should get us coverage of most of the rest of libcore.
2019-11-26Add tracking issue number.Mara Bos-2/+2
2019-11-26Add core::{f32,f64}::consts::TAU.Mara Bos-0/+12
2019-11-21Redefine `core::convert::Infallible` as `!`.Mazdak Farrokhzad-11/+1
2019-11-21Stabilize the `never_type`, written `!`.Mazdak Farrokhzad-1/+1
2019-11-12update version metadataPeter-35/+35
2019-11-11add NonZeroU16 -> NonZeroUsize and NonZeroI16 -> NonZeroIsizePeter-0/+2
2019-11-10remove irrelevant Safety sectionPeter-38/+34
2019-11-10From<NonZero*> impls for wider NonZero typesPeter-0/+70
issue: https://github.com/rust-lang/rust/issues/66196
2019-11-08remove vestigial comments referring to defunct numeric trait hierarchyAlexander Nye-2/+0
see also https://github.com/rust-lang/rust/pull/23104/files
2019-11-06Have tidy ensure that we document all `unsafe` blocks in libcoreOliver Scherer-2/+31
2019-10-31Stabilize float_to_from_bytes featureLzu Tao-24/+12
2019-10-22Apply clippy::useless_let_if_seq suggestionMateusz Mikuła-5/+4
2019-10-21Rollup merge of #65092 - tspiteri:const-is-pow2, r=oli-obkMazdak Farrokhzad-2/+2
make is_power_of_two a const function This makes `is_power_of_two` a const function by using `&` instead of short-circuiting `&&`; Rust supports bitwise `&` for `bool` and short-circuiting is not required in the existing expression. I don't think this needs a const-hack label as I don't find the changed code less readable, if anything I prefer that it is clearer that short circuiting is not used. @oli-obk
2019-10-21improve readability of is_power_of_twoTrevor Spiteri-1/+1
2019-10-18Rollup merge of #65549 - t-rapp:tr-wrapping-rotate-docs, r=jonas-schievinkTyler Mandry-2/+2
Fix left/right shift typo in wrapping rotate docs This makes the note similar to the one found on rotate functions for primitive types like i32/u32.
2019-10-18Fix left/right shift typo in wrapping rotate docsTobias Rapp-2/+2
This makes the note similar to the one found on rotate functions for primitive types like i32/u32.
2019-10-17properly document panics in div_euclid and rem_euclidTrevor Spiteri-2/+10
2019-10-11improve performance of signed saturating_mulTrevor Spiteri-1/+1
Reciprocal throughput is improved from 2.3 to 1.7. https://godbolt.org/z/ROMiX6
2019-10-04make is_power_of_two a const functionTrevor Spiteri-2/+2
2019-10-03Rollup merge of #64941 - lzutao:inline-max_min_value, r=nnethercoteMazdak Farrokhzad-4/+4
Inline `{min,max}_value` even in debug builds I think it is worth to inline `{min,max}_value` even in debug builds. See this godbolt link: https://godbolt.org/z/-COkVS
2019-10-01Add lower bound doctests for `saturating_{add,sub}` signed intsLzu Tao-3/+6
2019-10-01Inline `{min,max}_value` even in debug buildsLzu Tao-4/+4
2019-09-25Rollup merge of #64764 - Mark-Simulacrum:snap, r=CentrilMazdak Farrokhzad-42/+6
Master is now 1.40 r? @pietroalbini
2019-09-25Rollup merge of #64386 - tspiteri:const-abs2, r=oli-obkMazdak Farrokhzad-3/+26
use `sign` variable in abs and wrapping_abs methods This also makes the code easier to understand by hinting at the significance of `self >> ($BITS - 1)`. Also, now `overflowing_abs` simply uses `wrapping_abs`, which is clearer and avoids a potential performance regression in the LLVM IR. This PR follows from the discussion from #63786. r? @eddyb cc @nikic
2019-09-25Snap cfgs to new betaMark Rousskov-42/+6
2019-09-23Move `--cfg bootstrap` out of `rustc.rs`Alex Crichton-12/+12
Instead let's do this via `RUSTFLAGS` in `builder.rs`. Currently requires a submodule update of `stdarch` to fix a problem with previous compilers.
2019-09-18doc: Format some primitives examplesLzu Tao-12/+18
2019-09-13use `sign` variable in abs and wrapping_abs methodsTrevor Spiteri-3/+26
This also makes the code easier to understand by hinting at the significance of `self >> ($BITS - 1)` and by including an explanation in the comments. Also, now overflowing_abs simply uses wrapping_abs, which is clearer and avoids a potential performance regression in the LLVM IR.
2019-09-10Rollup merge of #63786 - tspiteri:const-abs, r=alexcrichtonMazdak Farrokhzad-21/+9
Make `abs`, `wrapping_abs`, `overflowing_abs` const functions This makes `abs`, `wrapping_abs` and `overflowing_abs` const functions like #58044 makes `wrapping_neg` and `overflowing_neg` const functions. `abs` is made const by returning `(self ^ -1) - -1` = `!self + 1` = `-self` for negative numbers and `(self ^ 0) - 0` = `self` for non-negative numbers. The subexpression `self >> ($BITS - 1)` evaluates to `-1` for negative numbers and `0` otherwise. The subtraction overflows when `self` is `min_value()`, as we would be subtracting `max_value() - -1`; this is when `abs` should overflow. `wrapping_abs` and `overflowing_abs` make use of `wrapping_sub` and `overflowing_sub` instead of the subtraction operator.
2019-09-02Auto merge of #63692 - iluuu1994:issue-49660, r=sfacklerbors-0/+8
Test that Wrapping arithmetic ops are implemented for all int types Closes #49660
2019-08-22Change code formatting for readability.Tomasz Różański-2/+2
2019-08-21make abs, wrapping_abs, and overflowing_abs const functionsTrevor Spiteri-21/+9
2019-08-20Test that Wrapping arithmetic ops are implemented for all int typesIlija Tovilo-0/+8
2019-08-16rustbuild: work around the stdarch cfg(bootstrap) bug.Eduard-Mihai Burtescu-12/+12