about summary refs log tree commit diff
path: root/src/libcore/num
AgeCommit message (Collapse)AuthorLines
2020-05-05Rollup merge of #71845 - steveklabnik:add-const-examples, r=dtolnayDylan DPC-2/+318
Add const examples I only added them to `std::f32` to get feedback on this approach before adding the other constants. When looking at https://github.com/rust-lang/rust/pull/68952, I found the docs a little confusing. Unless you're intimately aware of what's going on here, I don't think it's super clear what is deprecated and what you're supposed to do instead. I think short examples really clarify what's meant here, so that's what I did.
2020-05-04Use f64 in f64 examplesSteve Klabnik-2/+2
I believe that this is a copy/paste error; this example was using f32, but it's the docs for f64.
2020-05-04Add examples to int macrosSteve Klabnik-2/+24
2020-05-04f64 examplesSteve Klabnik-0/+147
2020-05-04correct -> intendedSteve Klabnik-14/+14
2020-05-04add some whitespaceSteve Klabnik-0/+7
2020-05-04Add examples for std::f32 constants.Steve Klabnik-0/+140
And also point people to use the associated constants of f32 instead.
2020-04-26Fix since attribute for nonzero_bitor impl'sJonas Platte-5/+5
2020-04-25Rollup merge of #69813 - thomcc:nonzero-bitor, r=AmanieuDylan DPC-0/+52
Implement BitOr and BitOrAssign for the NonZero integer types This provides overloaded operators for `NonZero$Int | NonZero$Int`, `NonZero$Int | $Int`, and `$Int | NonZero$Int`. It also provides `BitOrAssign` where `self` is `NonZero$Int`, for symmetry. It's a pretty small conceptual addition, but is good becasue but avoids a case where the operation is obviously sound, but you'd otherwise need unsafe to do it. In crates trying to minimize `unsafe` usage, this is unfortunate and makes working with `NonZero` types often not worth it, even if the operations you're doing are clearly sound. I've marked these as stable as I've been told in the past that trait impls are automatically stable. I'm happy to change it to unstable if this wasn't correct information. I'm not entirely confident what version I should have put down, so I followed https://www.whatrustisit.com. Hopefully it's correct for this. Apologies in advance if this has come up before, but I couldn't find it.
2020-04-20Use assoc float consts instead of module levelLinus Färnstrand-5/+4
2020-04-20Define module level int consts from assoc constsLinus Färnstrand-2/+2
2020-04-20Stop accessing module level int consts via crate::<Ty>Linus Färnstrand-1/+0
2020-04-16Dogfood or_patterns in the standard libraryJosh Stone-4/+4
2020-04-05Make libcore float constant examples similar to libstdLinus Färnstrand-12/+4
2020-04-03Make documentation examples use new integer assoc constsLinus Färnstrand-3/+3
2020-04-03Rollup merge of #70708 - Pocakking:fix-ascii-case-conv-typo, r=sfacklerMazdak Farrokhzad-2/+2
Fix typo in u8::to_ascii_uppercase and u8::to_ascii_lowercase Corrects misspelling of fifth.
2020-04-02Fix typo in u8::to_ascii_uppercase and u8::to_ascii_lowercasePocakking-2/+2
fith => fifth
2020-03-29Stabilize float::to_int_uncheckedMark Rousskov-14/+10
This renames and stabilizes unsafe floating point to integer casts, which are intended to be the substitute for the currently unsound `as` behavior, once that changes to safe-but-slower saturating casts.
2020-03-26Rename asm! to llvm_asm!Amanieu d'Antras-2/+2
asm! is left as a wrapper around llvm_asm! to maintain compatibility.
2020-03-13update stable-since version for const_int_conversionTrevor Spiteri-12/+12
2020-03-11Rollup merge of #69373 - tspiteri:const_int_conversion, r=oli-obkMazdak Farrokhzad-16/+48
Stabilize const for integer {to,from}_{be,le,ne}_bytes methods All of these functions can be implemented simply and naturally as const functions, e.g. `u32::from_le_bytes` can be implemented as ```rust (bytes[0] as u32) | (bytes[1] as u32) << 8 | (bytes[2] as u32) << 16 | (bytes[3] as u32) << 24 ``` So stabilizing the constness will not expose that internally they are implemented using transmute which is not const in stable.
2020-03-07Implement BitOr and BitOrAssign for the NonZero integer typesThom Chiovoloni-0/+52
2020-03-04Auto merge of #68952 - faern:stabilize-assoc-int-consts, r=dtolnaybors-210/+255
Stabilize assoc_int_consts associated int/float constants The next step in RFC https://github.com/rust-lang/rfcs/pull/2700 (tracking issue #68490). Stabilizing the associated constants that were added in #68325. * Stabilize all constants under the `assoc_int_consts` feature flag. * Update documentation on old constants to say they are soft-deprecated and the new ones should be preferred. * Update documentation examples to use new constants. * Remove `uint_macro` and use `int_macro` for all integer types since the macros were identical anyway. r? @LukasKalbertodt
2020-02-26Rollup merge of #69209 - Mark-Simulacrum:strip-unsafe, r=dtolnayDylan DPC-17/+15
Miscellaneous cleanup to formatting Each commit stands alone. This pull request will also resolve #58320.
2020-02-26use unions instead of transmute and add const safety commentsTrevor Spiteri-8/+36
2020-02-22Rollup merge of #68984 - ecstatic-morse:const-u8-is-ascii, r=sfacklerDylan DPC-1/+2
Make `u8::is_ascii` a stable `const fn` `char::is_ascii` was already stabilized as `const fn` in #55278, so there is no reason for `u8::is_ascii` to go through an unstable period. cc @rust-lang/libs
2020-02-22Stabilize const for integer {to,from}_{be,le,ne}_bytes methodsTrevor Spiteri-12/+16
All of these functions can be implemented simply and naturally as const functions, e.g. u32::from_le_bytes can be implemented as (bytes[0] as u32) | (bytes[1] as u32) << 8 | (bytes[2] as u32) << 16 | (bytes[3] as u32) << 24 So stabilizing the constness will not expose that internally they are implemented using transmute which is not const in stable.
2020-02-20Rollup merge of #68978 - ecstatic-morse:const-int-pow, r=oli-obkDylan DPC-23/+46
Make integer exponentiation methods unstably const cc #53718 This makes the following inherent methods on integer primitives into unstable `const fn`: - `pow` - `checked_pow` - `wrapping_pow` - `overflowing_pow` - `saturating_pow` - `next_power_of_two` - `checked_next_power_of_two` - `wrapping_next_power_of_two` Only two changes were made to the implementation of these methods. First, I had to switch from the `?` operator, which is not yet implemented in a const context, to a `try_opt` macro. Second, `next_power_of_two` was using `ops::Add::add` (see the first commit) to "get overflow checks", so I switched to `#[rustc_inherit_overflow_checks]`. I'm not quite sure why the attribute wasn't used in the first place.
2020-02-17Drop unused argument to float functionsMark Rousskov-2/+0
2020-02-16Stabilize {f32, f64}::{LOG2_10, LOG10_2}LeSeulArtichaut-4/+4
2020-02-15Formatter::sign is &'static strMark Rousskov-15/+15
The contents were always UTF-8 anyway, and &str has an equivalent representation to &[u8], so this should not affect performance while removing unsafety at edges. It may be worth exploring a further adjustment that stores a single byte (instead of 16) as the contents are always "", "-", or "+".
2020-02-12Add usage recommendation to old float constantsLinus Färnstrand-0/+28
2020-02-12Update float documentation to use associated constsLinus Färnstrand-22/+2
2020-02-12Add notice about using new consts in new code on int modulesLinus Färnstrand-0/+36
2020-02-12Add notice about using new consts in new code on float modulesLinus Färnstrand-0/+6
2020-02-12Remove uint_macros that was identical to int_macrosLinus Färnstrand-41/+13
2020-02-12Replace min/max_value() with MIN/MAX in integer docsLinus Färnstrand-52/+52
2020-02-12Use new preferred consts in int docsLinus Färnstrand-35/+13
2020-02-12Add "soft deprecation" notice to old MIN/MAX docsLinus Färnstrand-12/+41
2020-02-12Add "soft deprecation" notice to old min/max_value() docsLinus Färnstrand-40/+60
2020-02-12Stabilize assoc_int_constsLinus Färnstrand-36/+32
2020-02-10Rollup merge of #68986 - ecstatic-morse:const-ascii-ctype, r=CentrilDylan DPC-10/+20
Make ASCII ctype functions unstably const Makes the following inherent methods on `u8` and `char` unstable `const fn`: * `is_ascii_alphabetic` * `is_ascii_uppercase` * `is_ascii_lowercase` * `is_ascii_alphanumeric` * `is_ascii_digit` * `is_ascii_hexdigit` * `is_ascii_punctuation` * `is_ascii_graphic` * `is_ascii_whitespace` * `is_ascii_control` cc #68983
2020-02-08Make `u8::is_ascii` a stable `const fn`Dylan MacKenzie-1/+2
`char::is_ascii` is already a stable `const fn`, so there is no reason for `u8::is_ascii` to be unstable.
2020-02-08Make the ASCII ctype inherent methods constDylan MacKenzie-10/+20
2020-02-08Make integer power methods constDylan MacKenzie-14/+28
2020-02-08Use bespoke macro instead of `?` inside const fnsDylan MacKenzie-6/+16
2020-02-08[!] Use `rustc_inherit_overflow_checks` in `next_power_of_two`Dylan MacKenzie-3/+2
I believe the previous code was calling `ops::Add::add` instead of the `+` operator to get this behavior.
2020-02-08Make `num::NonZeroX::new` an unstable `const fn`Dylan MacKenzie-1/+2
2020-02-04Use consistent feature namingDylan MacKenzie-45/+45
2020-02-04Make saturating arithmetic using intrinsics `const`Dylan MacKenzie-2/+4