about summary refs log tree commit diff
path: root/src/libstd/num
AgeCommit message (Collapse)AuthorLines
2015-03-08Auto merge of #22984 - carols10cents:tests-for-float, r=huonwbors-345/+925
Building on #22076, I've added some tests for stable methods in f32 and f64 that didn't have any before. Please let me know if there are any improvements I can make, and I am happy to make them! :mailbox_with_mail:
2015-03-07Use assert_eq! rather than assert!Ryan Prichard-1/+1
The previous code was passing "true" as the panic! error value.
2015-03-05Removing unnecessary pub from a test functionCarol Nichols-2/+2
2015-03-05Add tests to stable f32 and f64 methods that didn't have anyCarol Nichols-0/+580
2015-03-05Rearrange tests to be in the same order as implementationCarol Nichols-345/+345
I was having trouble figuring out which functions had tests and which didn't. This commit is just moving tests around and does not change anything.
2015-03-05Remove integer suffixes where the types in compiled code are identical.Eduard Burtescu-31/+31
2015-03-03Auto merge of #22532 - pnkfelix:arith-overflow, r=pnkfelix,eddybbors-12/+14
Rebase and follow-through on work done by @cmr and @aatch. Implements most of rust-lang/rfcs#560. Errors encountered from the checks during building were fixed. The checks for division, remainder and bit-shifting have not been implemented yet. See also PR #20795 cc @Aatch ; cc @nikomatsakis
2015-03-03Rollup merge of #22876 - Florob:const, r=nikomatsakisManish Goregaokar-2/+2
This changes the type of some public constants/statics in libunicode. Notably some `&'static &'static [(char, char)]` have changed to `&'static [(char, char)]`. The regexp crate seems to be the sole user of these, yet this is technically a [breaking-change]
2015-03-03Accommodate arith-overflow in `core::num`, `std::num`, `coretest::num`.Felix S. Klock II-12/+13
* `core::num`: adjust `UnsignedInt::is_power_of_two`, `UnsignedInt::next_power_of_two`, `Int::pow`. In particular for `Int::pow`: (1.) do not panic when `base` overflows if `acc` never observes the overflowed `base`, and (2.) if `acc` does observe the overflowed `base`, make sure we only panic if we would have otherwise (e.g. during a computation of `base * base`). * also in `core::num`: avoid underflow during computation of `uint::MAX`. * `std::num`: adjust tests `uint::test_uint_from_str_overflow`, `uint::test_uint_to_str_overflow`, `strconv` * `coretest::num`: adjust `test::test_int_from_str_overflow`.
2015-03-03Add `core::num::wrapping` and fix overflow errors.James Miller-0/+1
Many of the core rust libraries have places that rely on integer wrapping behaviour. These places have been altered to use the wrapping_* methods: * core::hash::sip - A number of macros * core::str - The `maximal_suffix` method in `TwoWaySearcher` * rustc::util::nodemap - Implementation of FnvHash * rustc_back::sha2 - A number of macros and other places * rand::isaac - Isaac64Rng, changed to use the Wrapping helper type Some places had "benign" underflow. This is when underflow or overflow occurs, but the unspecified value is not used due to other conditions. * collections::bit::Bitv - underflow when `self.nbits` is zero. * collections::hash::{map,table} - Underflow when searching an empty table. Did cause undefined behaviour in this case due to an out-of-bounds ptr::offset based on the underflowed index. However the resulting pointers would never be read from. * syntax::ext::deriving::encodable - Underflow when calculating the index of the last field in a variant with no fields. These cases were altered to avoid the underflow, often by moving the underflowing operation to a place where underflow could not happen. There was one case that relied on the fact that unsigned arithmetic and two's complement arithmetic are identical with wrapping semantics. This was changed to use the wrapping_* methods. Finally, the calculation of variant discriminants could overflow if the preceeding discriminant was `U64_MAX`. The logic in `rustc::middle::ty` for this was altered to avoid the overflow completely, while the remaining places were changed to use wrapping methods. This is because `rustc::middle::ty::enum_variants` now throws an error when the calculated discriminant value overflows a `u64`. This behaviour can be triggered by the following code: ``` enum Foo { A = U64_MAX, B } ``` This commit also implements the remaining integer operators for Wrapped<T>.
2015-03-02core: Audit num module for int/uintBrian Anderson-2/+2
* count_ones/zeros, trailing_ones/zeros return u32, not usize * rotate_left/right take u32, not usize * RADIX, MANTISSA_DIGITS, DIGITS, BITS, BYTES are u32, not usize Doesn't touch pow because there's another PR for it. [breaking-change]
2015-03-02Use `const`s instead of `static`s where appropriateFlorian Zeitz-2/+2
This changes the type of some public constants/statics in libunicode. Notably some `&'static &'static [(char, char)]` have changed to `&'static [(char, char)]`. The regexp crate seems to be the sole user of these, yet this is technically a [breaking-change]
2015-03-01Make Int::pow() take exp as u32 instead usizeGuillaume Gomez-1/+1
2015-02-23Rollup merge of #22658 - glacjay:issue-22535, r=GankroManish Goregaokar-62/+66
fix issue #22535
2015-02-22shift int/uint tests around to avoid code repetitionGlacJAY-62/+66
2015-02-20make int/uint modules just re-exportsAlexis-149/+105
2015-02-18Convert required suffixes into a use of `as`.Niko Matsakis-39/+39
2015-02-18Remove `i`, `is`, `u`, or `us` suffixes that are not necessary.Niko Matsakis-16/+16
2015-02-16Document std::num::Float with examplesmdinger-42/+777
2015-02-15Rollup merge of #22339 - petrochenkov:int, r=huonwManish Goregaokar-21/+21
Some function signatures have changed, so this is a [breaking-change]. In particular, radixes and numerical values of digits are represented by `u32` now. Part of #22240
2015-02-15Fix the falloutVadim Petrochenkov-21/+21
2015-02-13Remove `_VALUE` from the float extremes constants.Huon Wilson-0/+2
In `std::f32` and `std::f64`: - `MIN_VALUE` → `MIN` - `MAX_VALUE` → `MAX` - `MIN_POS_VALUE` → `MIN_POSITIVE` This matches the corresponding integer constants. [breaking-change]
2015-02-11Auto merge of #22076 - carols10cents:exp2-calling-exp, r=huonwbors-2/+56
I was working on adding examples to the documentation in `std::num::Float`. I got to `exp2`, which says "Returns 2 raised to the power of the number, `2^(self)`." So I tried running this code: ``` use std::num::Float; #[test] fn test_exp2() { assert_eq!(32.0, 5.0.exp2()); } ``` and it resulted in a failure of `(left: `32`, right: `148.413159`)`. That 148.413159 is the value for e^5, which is `exp()`, not `exp2()`. Sure enough, `exp2` is calling `exp` and shouldn't be, looks like a copy-paste error. I haven't added any tests for this since it's unlikely to break again, but I will happily do so if people think that would be a good idea. The doc examples are coming :) I scanned through the other functions in these files for similar sorts of errors and didn't notice any.
2015-02-10Auto merge of #21937 - alexcrichton:issue-21929, r=aturonbors-1/+1
These were forgotten reexports from #21718 Closes #21929
2015-02-08Correct fns exp2 that were calling expCarol Nichols-2/+56
Fixes #22080.
2015-02-04remove all kind annotations from closuresJorge Aparicio-2/+2
2015-02-04std: Add reexports for core parse errorsAlex Crichton-1/+1
These were forgotten reexports from #21718 Closes #21929
2015-02-04Deprecate in-tree `rand`, `std::rand` and `#[derive(Rand)]`.Huon Wilson-0/+1
Use the crates.io crate `rand` (version 0.1 should be a drop in replacement for `std::rand`) and `rand_macros` (`#[derive_Rand]` should be a drop-in replacement). [breaking-change]
2015-01-30rollup merge of #21631: tbu-/isize_policeAlex Crichton-23/+23
Conflicts: src/libcoretest/iter.rs
2015-01-30std: Stabilize FromStr and parseAlex Crichton-10/+10
This commits adds an associated type to the `FromStr` trait representing an error payload for parses which do not succeed. The previous return value, `Option<Self>` did not allow for this form of payload. After the associated type was added, the following attributes were applied: * `FromStr` is now stable * `FromStr::Err` is now stable * `FromStr::from_str` is now stable * `StrExt::parse` is now stable * `FromStr for bool` is now stable * `FromStr for $float` is now stable * `FromStr for $integral` is now stable * Errors returned from stable `FromStr` implementations are stable * Errors implement `Display` and `Error` (both impl blocks being `#[stable]`) Closes #15138
2015-01-30Remove all `i` suffixesTobias Bucher-23/+23
2015-01-29s/Show/Debug/gJorge Aparicio-1/+1
2015-01-29`range(a, b).foo()` -> `(a..b).foo()`Jorge Aparicio-2/+2
sed -i 's/ range(\([^,]*\), *\([^()]*\))\./ (\1\.\.\2)\./g' **/*.rs
2015-01-25Merge remote-tracking branch 'rust-lang/master'Brian Anderson-4/+4
Conflicts: mk/tests.mk src/liballoc/arc.rs src/liballoc/boxed.rs src/liballoc/rc.rs src/libcollections/bit.rs src/libcollections/btree/map.rs src/libcollections/btree/set.rs src/libcollections/dlist.rs src/libcollections/ring_buf.rs src/libcollections/slice.rs src/libcollections/str.rs src/libcollections/string.rs src/libcollections/vec.rs src/libcollections/vec_map.rs src/libcore/any.rs src/libcore/array.rs src/libcore/borrow.rs src/libcore/error.rs src/libcore/fmt/mod.rs src/libcore/iter.rs src/libcore/marker.rs src/libcore/ops.rs src/libcore/result.rs src/libcore/slice.rs src/libcore/str/mod.rs src/libregex/lib.rs src/libregex/re.rs src/librustc/lint/builtin.rs src/libstd/collections/hash/map.rs src/libstd/collections/hash/set.rs src/libstd/sync/mpsc/mod.rs src/libstd/sync/mutex.rs src/libstd/sync/poison.rs src/libstd/sync/rwlock.rs src/libsyntax/feature_gate.rs src/libsyntax/test.rs
2015-01-23grandfathered -> rust1Brian Anderson-51/+51
2015-01-23Deprecated attributes don't take 'feature' names and are paired with ↵Brian Anderson-9/+18
stable/unstable Conflicts: src/libcore/atomic.rs src/libcore/finally.rs src/test/auxiliary/inherited_stability.rs src/test/auxiliary/lint_stability.rs
2015-01-23Set unstable feature names appropriatelyBrian Anderson-45/+45
* `core` - for the core crate * `hash` - hashing * `io` - io * `path` - path * `alloc` - alloc crate * `rand` - rand crate * `collections` - collections crate * `std_misc` - other parts of std * `test` - test crate * `rustc_private` - everything else
2015-01-21Remove 'since' from unstable attributesBrian Anderson-45/+45
2015-01-21Add 'feature' and 'since' to stability attributesBrian Anderson-105/+129
2015-01-21rollup merge of #21258: aturon/stab-3-indexAlex Crichton-2/+2
Conflicts: src/libcore/ops.rs src/librustc_typeck/astconv.rs src/libstd/io/mem.rs src/libsyntax/parse/lexer/mod.rs
2015-01-21Fallout from stabilization.Aaron Turon-2/+2
2015-01-20std: Rename Show/String to Debug/DisplayAlex Crichton-2/+2
This commit is an implementation of [RFC 565][rfc] which is a stabilization of the `std::fmt` module and the implementations of various formatting traits. Specifically, the following changes were performed: [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0565-show-string-guidelines.md * The `Show` trait is now deprecated, it was renamed to `Debug` * The `String` trait is now deprecated, it was renamed to `Display` * Many `Debug` and `Display` implementations were audited in accordance with the RFC and audited implementations now have the `#[stable]` attribute * Integers and floats no longer print a suffix * Smart pointers no longer print details that they are a smart pointer * Paths with `Debug` are now quoted and escape characters * The `unwrap` methods on `Result` now require `Display` instead of `Debug` * The `Error` trait no longer has a `detail` method and now requires that `Display` must be implemented. With the loss of `String`, this has moved into libcore. * `impl<E: Error> FromError<E> for Box<Error>` now exists * `derive(Show)` has been renamed to `derive(Debug)`. This is not currently warned about due to warnings being emitted on stage1+ While backwards compatibility is attempted to be maintained with a blanket implementation of `Display` for the old `String` trait (and the same for `Show`/`Debug`) this is still a breaking change due to primitives no longer implementing `String` as well as modifications such as `unwrap` and the `Error` trait. Most code is fairly straightforward to update with a rename or tweaks of method calls. [breaking-change] Closes #21436
2015-01-17Register new snapshots.Eduard Burtescu-28/+14
2015-01-08Improvements to feature stagingBrian Anderson-18/+18
This gets rid of the 'experimental' level, removes the non-staged_api case (i.e. stability levels for out-of-tree crates), and lets the staged_api attributes use 'unstable' and 'deprecated' lints. This makes the transition period to the full feature staging design a bit nicer.
2015-01-07rollup merge of #20708: aturon/new-int-modulesAlex Crichton-6/+56
Conflicts: src/libserialize/lib.rs
2015-01-08Rename `target_word_size` to `target_pointer_width`Nick Cameron-14/+28
Closes #20421 [breaking-change]
2015-01-07Add isize, usize modules, deprecate int, uint modulesAaron Turon-6/+56
This PR introduces `isize` and `usize` modules to `core` and `std`, and deprecates the existing `int` and `uint` modules. The rustdoc primitive type links now point to these new modules. Due to deprecation this is a: [breaking-change]
2015-01-07markers -> markerNick Cameron-1/+1
2015-01-07Change `std::kinds` to `std::markers`; flatten `std::kinds::marker`Nick Cameron-1/+1
[breaking-change]
2015-01-06Apply stability attributes to std::num::Float.Huon Wilson-30/+56