about summary refs log tree commit diff
path: root/src/libcore/num
AgeCommit message (Collapse)AuthorLines
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).
2015-05-09Auto merge of #25159 - inrustwetrust:wrapping_inline, r=alexcrichtonbors-0/+1
This was causing function calls to be emitted for bitwise complements, even with optimizations on. Steps to reproduce: ``` $ cat wrapping.rs fn main() { let a = std::num::Wrapping(std::env::args().len() as u32); let b = !a; println!("{}", b.0); } $ rustc -O wrapping.rs --emit=asm,link $ grep Not wrapping.s callq _ZN3num8wrapping23Wrapping$LT$u32$GT$.Not3not20hba4b266232e02b1dHkbE ```
2015-05-06Add missing inline attribute to Not impl for Wrapping<T>inrustwetrust-0/+1
2015-05-06core: use banker's rounding for the exact mode in flt2dec.Kang Seonghoon-1/+5
For the shortest mode the IEEE 754 decoder already provides an exact rounding range accounting for banker's rounding, but it was not the case for the exact mode. This commit alters the exact mode algorithm for Dragon so that any number ending at `...x5000...` with even `x` and infinite zeroes will round to `...x` instead of `...(x+1)` as it was. Grisu is not affected by this change because this halfway case always results in the failure for Grisu.
2015-05-06core: updated for the master changes.Kang Seonghoon-0/+5
The master no longer has `std::num::Float`, so a generic `ldexp` is not readily available. `DecodableFloat::ldexpi` works around this.
2015-05-06core: fixed a slight bug.Kang Seonghoon-6/+6
The bug involves the incorrect logic for `core::num::flt2dec::decoder`. This makes some numbers in the form of 2^n missing one final digits, which breaks the bijectivity criterion. The regression tests have been added, and f32 exhaustive test is rerun to get the updated result.
2015-05-06core: fixed typos and revised comments in flt2dec.Kang Seonghoon-14/+17
2015-05-06core: tweaked flt2dec to match the casing of the older formatting code.Kang Seonghoon-18/+18
2015-05-06core: added core::num::flt2dec for floating-point formatting.Kang Seonghoon-0/+2219
This is a fork of the flt2dec portion of rust-strconv [1] with a necessary relicensing (the original code was licensed CC0-1.0). Each module is accompanied with large unit tests, integrated in this commit as coretest::num::flt2dec. This module is added in order to replace the existing core::fmt::float method. The forked revision of rust-strconv is from 2015-04-20, with a commit ID 9adf6d3571c6764a6f240a740c823024f70dc1c7. [1] https://github.com/lifthrasiir/rust-strconv/
2015-05-01std: Don't use a wrapper for the float error typeAlex Crichton-12/+16
Ensures that the same error type is propagated throughout. Unnecessary leakage of the internals is prevented through the usage of stability attributes. Closes #24748
2015-05-01Rollup merge of #25010 - huonw:inline-int-extremes, r=alexcrichtonManish Goregaokar-0/+2
These compile down to `mov $CONSTANT, register; ret`, but the lack of `#[inline]` meant they have a full `call ...` when used from external crates.
2015-05-01Mark the {min,max}_value functions on integers #[inline].Huon Wilson-0/+2
These compile down to `mov $CONSTANT, register; ret`, but the lack of `#[inline]` meant they have a full `call ...` when used from external crates.
2015-04-29Currently, LLVM lowers a cttz8 on x86_64 to these instructions:Björn Steinbrink-1/+14
```asm movzbl %dil, %eax bsfl %eax, %eax movl $32, %ecx cmovnel %eax, %ecx cmpl $32, %ecx movl $8, %eax cmovnel %ecx, %eax ``` which has some unnecessary overhead, having two conditional moves. To improve the codegen, we can zero extend the 8 bit integer, then set bit 8 and perform a cttz operation on the extended value. That way there's no conditional operation involved at all.
2015-04-21std: Bring back f32::from_str_radix as an unstable APIAlex Crichton-237/+173
This API was exercised in a few tests and mirrors the `from_str_radix` functionality of the integer types.
2015-04-21std: Remove deprecated/unstable num functionalityAlex Crichton-1691/+103
This commit removes all the old casting/generic traits from `std::num` that are no longer in use by the standard library. This additionally removes the old `strconv` module which has not seen much use in quite a long time. All generic functionality has been supplanted with traits in the `num` crate and the `strconv` module is supplanted with the [rust-strconv crate][rust-strconv]. [rust-strconv]: https://github.com/lifthrasiir/rust-strconv This is a breaking change due to the removal of these deprecated crates, and the alternative crates are listed above. [breaking-change]
2015-04-21Model lexer: Fix remaining issuesPiotr Czarnecki-2/+0
2015-04-17side-step potentially panic'ing negate in `fn abs`.Felix S. Klock II-1/+5
2015-04-17Auto merge of #24420 - pnkfelix:oflo-api, r=alexcrichtonbors-1/+156
Fill in missing parts of Integer overflow API See todo list at #22020
2015-04-14Fix bug in `wrapping_div`Felix S. Klock II-1/+1
See discussion, albeit one-sided, in: https://github.com/rust-lang/rfcs/issues/964
2015-04-14Remaining API additions for int overflow:Felix S. Klock II-0/+155
`wrapping_div`, `wrapping_rem`, `wrapping_neg`, `wrapping_shl`, `wrapping_shr`. All marked unstable under `core` feature for now (with expectation of being marked as stable by 1.0 release).
2015-04-13pluralize doc comment verbs and add missing periodsAndrew Paseltiner-43/+43
2015-04-12mod.rs documentary fixIgor Strebezhev-2/+2
Docs meant that Option is returned though the function returns Result.
2015-04-11Rollup merge of #24298 - White-Oak:master, r=alexcrichtonManish Goregaokar-11/+8
Fixes 'fn from_str_radix' documentation where docs meant that Option is returned, though the function returns Result.
2015-04-11Rollup merge of #24291 - xamgore:patch-1, r=steveklabnikManish Goregaokar-6/+6
From [here](http://doc.rust-lang.org/nightly/std/primitive.i8.html): > `fn rotate_right(self, n: u32) -> i8` > Shifts the bits to the right by a specified __amount amount__, n, wrapping the truncated bits to the beginning of the resulting integer.
2015-04-11Rollup merge of #24274 - steveklabnik:fix_pow_docs, r=nikomatsakisManish Goregaokar-4/+3
This is very confusing now that these are inherent methods.