summary refs log tree commit diff
path: root/src/libcore/num
AgeCommit message (Collapse)AuthorLines
2015-10-16Reject "+" and "-" when parsing floats.Robin Kruppe-1/+6
Fixes #29042
2015-09-04Fix for issue #28012: pow overflow inconsistencyPeter Reid-15/+11
Overflows in integer pow() computations would be missed if they preceded a 0 bit of the exponent being processed. This made calls such as 2i32.pow(1024) not trigger an overflow.
2015-09-03Elide lifetimes in libcoreManish Goregaokar-7/+7
2015-08-26Make iter::order functions into methods on IteratorSteven Fackler-3/+1
This does cause some breakage due to deficiencies in resolve - `path::Components` is both an `Iterator` and implements `Eq`, `Ord`, etc. If one calls e.g. `partial_cmp` on a `Components` and passes a `&Components` intending to target the `PartialOrd` impl, the compiler will select the `partial_cmp` from `Iterator` and then error out. I doubt anyone will run into breakage from `Components` specifically, but we should see if there are third party types that will run into issues. `iter::order::equals` wasn't moved to `Iterator` since it's exactly the same as `iter::order::eq` but with an `Eq` instead of `PartialEq` bound, which doensn't seem very useful. I also updated `le`, `gt`, etc to use `partial_cmp` which lets us drop the extra `PartialEq` bound. cc #27737
2015-08-22Auto merge of #27871 - alexcrichton:stabilize-libcore, r=aturonbors-110/+126
These commits move libcore into a state so that it's ready for stabilization, performing some minor cleanup: * The primitive modules for integers in the standard library were all removed from the source tree as they were just straight reexports of the libcore variants. * The `core::atomic` module now lives in `core::sync::atomic`. The `core::sync` module is otherwise empty, but ripe for expansion! * The `core::prelude::v1` module was stabilized after auditing that it is a subset of the standard library's prelude plus some primitive extension traits (char, str, and slice) * Some unstable-hacks for float parsing errors were shifted around to not use the same unstable hacks (e.g. the `flt2dec` module is now used for "privacy"). After this commit, the remaining large unstable functionality specific to libcore is: * `raw`, `intrinsics`, `nonzero`, `array`, `panicking`, `simd` -- these modules are all unstable or not reexported in the standard library, so they're just remaining in the same status quo as before * `num::Float` - this extension trait for floats needs to be audited for functionality (much of that is happening in #27823) and may also want to be renamed to `FloatExt` or `F32Ext`/`F64Ext`. * Should the extension traits for primitives be stabilized in libcore? I believe other unstable pieces are not isolated to just libcore but also affect the standard library. cc #27701
2015-08-18Auto merge of #27823 - eefriedman:float-dep-core, r=alexcrichtonbors-279/+0
There wasn't any particular reason the functions needed to be there anyway, so just get rid of them, and adjust libstd to compensate. With this change, libcore depends on exactly two floating-point functions: fmod and fmodf. They are implicitly referenced because they are used to implement "%". Dependencies of libcore on Linux x86-x64 with this patch: ``` 0000000000000000 *UND* 0000000000000000 __powidf2 0000000000000000 *UND* 0000000000000000 __powisf2 0000000000000000 *UND* 0000000000000000 fmod 0000000000000000 *UND* 0000000000000000 fmodf 0000000000000000 *UND* 0000000000000000 memcmp 0000000000000000 *UND* 0000000000000000 memcpy 0000000000000000 *UND* 0000000000000000 memset 0000000000000000 *UND* 0000000000000000 rust_begin_unwind 0000000000000000 *UND* 0000000000000000 rust_eh_personality ```
2015-08-17core: Shuffle around float parsingAlex Crichton-100/+96
Stop using stability to hide the implementation details of ParseFloatError and instead move the error type into the `dec2flt` module. Also move the implementation blocks of `FromStr for f{32,64}` into `dec2flt` directly.
2015-08-17std: Clean up primitive integer modulesAlex Crichton-10/+30
All of the modules in the standard library were just straight reexports of those in libcore, so remove all the "macro modules" from the standard library and just reexport what's in core directly.
2015-08-17Remove dependencies on libm functions from libcore.Eli Friedman-279/+0
There wasn't any particular reason the functions needed to be there anyway, so just get rid of them, and adjust libstd to compensate. With this change, libcore depends on exactly two floating-point functions: fmod and fmodf. They are implicitly referenced because they are used to implement "%".
2015-08-15std: Add issues to all unstable featuresAlex Crichton-1/+2
2015-08-15core: Fill out issues for unstable featuresAlex Crichton-12/+24
2015-08-14Auto merge of #27641 - nikomatsakis:soundness-rfc-1214, r=nrcbors-2/+2
This PR implements the majority of RFC 1214. In particular, it implements: - the new outlives relation - comprehensive WF checking For the most part, new code receives warnings, not errors, though 3 regressions were found via a crater run. There are some deviations from RFC 1214. Most notably: - we still consider implied bounds from fn ret; this intersects other soundness issues that I intend to address in detail in a follow-up RFC. Fixing this without breaking a lot of code probably requires rewriting compare-method somewhat (which is probably a good thing). - object types do not check trait bounds for fear of encountering `Self`; this was left as an unresolved question in RFC 1214, but ultimately feels inconsistent. Both of those two issues are highlighted in the tracking issue, https://github.com/rust-lang/rust/issues/27579. #27579 also includes a testing matrix with new tests that I wrote -- these probably duplicate some existing tests, I tried to check but wasn't quite sure what to look for. I tried to be thorough in testing the WF relation, at least, but would welcome suggestions for missing tests. r? @nrc (or perhaps someone else?)
2015-08-13Auto merge of #27684 - alexcrichton:remove-deprecated, r=aturonbors-17/+0
This commit removes all unstable and deprecated functions in the standard library. A release was recently cut (1.3) which makes this a good time for some spring cleaning of the deprecated functions.
2015-08-12Fallout in libs -- misc missing bounds uncovered by WF checks.Niko Matsakis-2/+2
2015-08-12Remove all unstable deprecated functionalityAlex Crichton-17/+0
This commit removes all unstable and deprecated functions in the standard library. A release was recently cut (1.3) which makes this a good time for some spring cleaning of the deprecated functions.
2015-08-12Mention that the fast path is broken without SSE.Robin Kruppe-3/+11
2015-08-08Accurate decimal-to-float parsing routines.Robin Kruppe-15/+2420
This commit primarily adds implementations of the algorithms from William Clinger's paper "How to Read Floating Point Numbers Accurately". It also includes a lot of infrastructure necessary for those algorithms, and some unit tests. Since these algorithms reject a few (extreme) inputs that were previously accepted, this could be seen as a [breaking-change]
2015-08-08Add various methods to Bignum:Robin Kruppe-5/+141
- Exposing digits and individual bits - Counting the number of bits - Add small (digit-sized) values - Multiplication by power of 5 - Division with remainder All are necessary for decimal to floating point conversions. All but the most trivial ones come with tests.
2015-08-08Enlarge Bignum type from 1152 to 1280 bits.Robin Kruppe-6/+6
This is necessary for decimal-to-float code (in a later commit) to handle inputs such as 4.9406564584124654e-324 (the smallest subnormal f64). According to the benchmarks for flt2dec::dragon, this does not affect performance measurably. It probably uses slightly more stack space though.
2015-08-08Make core::num::dec2flt::strategy::grisu::Fp methods public.Robin Kruppe-3/+3
The intent is to allow decimal-to-float parsing to use Fp in its fast path. That code is added in a later commit.
2015-08-03syntax: Implement #![no_core]Alex Crichton-8/+11
This commit is an implementation of [RFC 1184][rfc] which tweaks the behavior of the `#![no_std]` attribute and adds a new `#![no_core]` attribute. The `#![no_std]` attribute now injects `extern crate core` at the top of the crate as well as the libcore prelude into all modules (in the same manner as the standard library's prelude). The `#![no_core]` attribute disables both std and core injection. [rfc]: https://github.com/rust-lang/rfcs/pull/1184
2015-07-28Replace occurences of illegal in user facing docsSimonas Kazlauskas-4/+4
2015-07-20std: Create separate docs for the primitivesBrian Anderson-12/+0
Having the primitive and module docs derived from the same source causes problems, primarily that they can't contain hyperlinks cross-referencing each other. This crates dedicated private modules in `std` to document the primitive types, then for all primitives that have a corresponding module, puts hyperlinks in moth the primitive docs and the module docs cross-linking each other. This should help clear up confusion when readers find themselves on the wrong page.
2015-07-19optimize from_str_radixarthurprs-11/+25
2015-07-13Auto merge of #26981 - wthrowe:div_docs, r=Gankrobors-4/+4
This resolves #26845. I'm not entirely satisfied with the placement of the rounding discussion in the docs for the `Div` and `Rem` traits, but I couldn't come up with anywhere better to put it. Suggestions are welcome. I didn't add any discussion of rounding to the `checked_div` (or rem) or `wrapping_div` documentation because those seem to make it pretty clear that they do the same thing as `Div`.
2015-07-11Correct and clarify integer division rounding docsWilliam Throwe-4/+4
2015-07-11Auto merge of #26878 - Esption:master, r=pnkfelixbors-1/+1
I noticed in docs, specifically http://doc.rust-lang.org/std/primitive.u8.html#method.is_power_of_two, that it was like this, and it was apparently in multiple places too. Didn't change any occurrences through the cross-depo things. There's a lot in /src/llvm/ for instance, but I'm not confident on how to go about sending fixes for those, so this is just what's in the base rust depo. r? @steveklabnik
2015-07-08'iff' for docs to 'if and only if'Esption-1/+1
2015-07-08Use wrapping_div call and correct the feature nameMathijs van de Nes-2/+2
2015-07-08Implement Div for Wrapping<T>Mathijs van de Nes-0/+10
Resolves #26867
2015-07-08Fixed some occurrences of 'if' being spelled 'iff'Esption-1/+1
2015-07-05Auto merge of #26473 - Eljay:missing_docs, r=alexcrichtonbors-0/+30
Fixes #24249 I've tagged all items that were missing docs to allow them to compile for now, the ones in core/num should probably be documented at least. This is also a breaking change for any crates using `#[deny(missing_docs)]` that have undocumented constants, not sure there is any way to avoid this without making it a separate lint?
2015-07-04Add missing #[inline] to min_value/max_value on integersUlrik Sverdrup-0/+2
Spotted a compiled function call to num::usize::min_value, I'd prefer the 0 to be inlined.
2015-06-27std: Avoid missing fns on i686-pc-windows-msvcAlex Crichton-6/+54
It turns out that the 32-bit toolchain for MSVC has many of these functions as `static inline` functions in header files so there's not actually a symbol for Rust to call. All of the implementations just cast floats to their 64-bit variants and then cast back to 32-bit at the end, so the standard library now takes this strategy.
2015-06-21Temp fix for all constants that are missing docs.Eljay-0/+30
2015-06-20Update mod.rsWei-Ming Yang-2/+1
`core::num::from_str_radix` can't parse the prefix `+` . http://is.gd/ewo0T2
2015-06-17std: Hide some internal functions more aggressivelyAlex Crichton-2/+4
* Add `#[doc(hidden)]` * Rename away from `Error::description`
2015-06-17std: Stabilize the remaining wrapping_* functionsAlex Crichton-10/+10
This commit stabilizes the remaining `wrapping_*` functions on the primitive integer types as they follow the same conventions as other wrapping methods are were likely just initially unstable to be conservative.
2015-06-17std: Deprecate f{32,64}::consts::PI_2Alex Crichton-0/+2
These constants have been unstable for some time now already
2015-06-17core: Split apart the global `core` featureAlex Crichton-23/+34
This commit shards the broad `core` feature of the libcore library into finer grained features. This split groups together similar APIs and enables tracking each API separately, giving a better sense of where each feature is within the stabilization process. A few minor APIs were deprecated along the way: * Iterator::reverse_in_place * marker::NoCopy
2015-06-10Removed many pointless calls to *iter() and iter_mut()Joshua Landau-3/+3
2015-06-07change some statics to constantsOliver 'ker' Schneider-4/+1
2015-05-27Remove mentions of int / uint from the isize / usize docsJake Goulding-8/+0
2015-05-21Standardize on `$t:ty`Tamir Duberstein-5/+5
2015-05-21Use `Self` to simplifyTamir Duberstein-109/+109
2015-05-19Fix for https://github.com/rust-lang/rust/pull/25583Steve Klabnik-1/+1
2015-05-19Rollup merge of #25583 - steveklabnik:gh25517, r=alexcrichtonSteve Klabnik-8/+4
Fixes #25517
2015-05-18std: Make abs() panic on overflow in debug modeAlex Crichton-3/+12
Debug overflow checks for arithmetic negation landed in #24500, at which time the `abs` method on signed integers was changed to using `wrapping_neg` to ensure that the function never panicked. This implied that `abs` of `INT_MIN` would return `INT_MIN`, another negative value. When this change was back-ported to beta, however, in #24708, the `wrapping_neg` function had not yet been backported, so the implementation was changed in #24785 to `!self + 1`. This change had the unintended side effect of enabling debug overflow checks for the `abs` function. Consequently, the current state of affairs is that the beta branch checks for overflow in debug mode for `abs` and the nightly branch does not. This commit alters the behavior of nightly to have `abs` always check for overflow in debug mode. This change is more consistent with the way the standard library treats overflow as well, and it is also not a breaking change as it's what the beta branch currently does (albeit if by accident). cc #25378
2015-05-18Add example for from_str_radixSteve Klabnik-8/+4
Fixes #25517
2015-05-09Auto merge of #24612 - lifthrasiir:flt2dec, r=pnkfelixbors-0/+2231
This is a direct port of my prior work on the float formatting. The detailed description is available [here](https://github.com/lifthrasiir/rust-strconv#flt2dec). In brief, * This adds a new hidden module `core::num::flt2dec` for testing from `libcoretest`. Why is it in `core::num` instead of `core::fmt`? Because I envision that the table used by `flt2dec` is directly applicable to `dec2flt` (cf. #24557) as well, which exceeds the realm of "formatting". * This contains both Dragon4 algorithm (exact, complete but slow) and Grisu3 algorithm (exact, fast but incomplete). * The code is accompanied with a large amount of self-tests and some exhaustive tests. In particular, `libcoretest` gets a new dependency on `librand`. For the external interface it relies on the existing test suite. * It is known that, in the best case, the entire formatting code has about 30 KBs of binary overhead (judged from strconv experiments). Not too bad but there might be a potential room for improvements. This is rather large code. I did my best to comment and annotate the code, but you have been warned. For the maximal availability the original code was licensed in CC0, but I've also dual-licensed it in MIT/Apache as well so there should be no licensing concern. This is [breaking-change] as it changes the float output slightly (and it also affects the casing of `inf` and `nan`). I hope this is not a big deal though :) Fixes #7030, #18038 and #24556. Also related to #6220 and #20870. ## Known Issues - [x] I've yet to finish `make check-stage1`. It does pass main test suites including `run-pass` but there might be some unknown edges on the doctests. - [ ] Figure out how this PR affects rustc. - [ ] Determine which internal routine is mapped to the formatting specifier. Depending on the decision, some internal routine can be safely removed (for instance, currently `to_shortest_str` is unused).