about summary refs log tree commit diff
path: root/src/libstd/num
AgeCommit message (Collapse)AuthorLines
2014-04-19Merge the Round trait into the Float traitBrendan Zabarauskas-77/+70
Move the rounding functions into the `std::num::Float` trait and then remove `std::num::Round`. This continues the flattening of the numeric traits tracked in #10387. The aim is to make `std::num` very simple and tied to the built in types, leaving the definition of more complex numeric towers to third-party libraries. [breaking-change]
2014-04-18Replace all ~"" with "".to_owned()Richo Healey-28/+30
2014-04-18Reduce HashMap allocations.Clark Gaebel-0/+6
2014-04-18std: Make ~[T] no longer a growable vectorAlex Crichton-26/+27
This removes all resizability support for ~[T] vectors in preparation of DST. The only growable vector remaining is Vec<T>. In summary, the following methods from ~[T] and various functions were removed. Each method/function has an equivalent on the Vec type in std::vec unless otherwise stated. * slice::OwnedCloneableVector * slice::OwnedEqVector * slice::append * slice::append_one * slice::build (no replacement) * slice::bytes::push_bytes * slice::from_elem * slice::from_fn * slice::with_capacity * ~[T].capacity() * ~[T].clear() * ~[T].dedup() * ~[T].extend() * ~[T].grow() * ~[T].grow_fn() * ~[T].grow_set() * ~[T].insert() * ~[T].pop() * ~[T].push() * ~[T].push_all() * ~[T].push_all_move() * ~[T].remove() * ~[T].reserve() * ~[T].reserve_additional() * ~[T].reserve_exect() * ~[T].retain() * ~[T].set_len() * ~[T].shift() * ~[T].shrink_to_fit() * ~[T].swap_remove() * ~[T].truncate() * ~[T].unshift() * ~str.clear() * ~str.set_len() * ~str.truncate() Note that no other API changes were made. Existing apis that took or returned ~[T] continue to do so. [breaking-change]
2014-04-15std: Un-ignore some float tests on windowsAlex Crichton-2/+2
These were fixed in the upgrade from mingw32 to mingw64. Closes #8663
2014-04-15Use the unsigned integer types for bitwise intrinsics.Huon Wilson-12/+12
Exposing ctpop, ctlz, cttz and bswap as taking signed i8/i16/... is just exposing the internal LLVM names pointlessly (LLVM doesn't have "signed integers" or "unsigned integers", it just has sized integer types with (un)signed *operations*). These operations are semantically working with raw bytes, which the unsigned types model better.
2014-04-13auto merge of #13470 : Manishearth/rust/docnum, r=brsonbors-0/+4
See #7511
2014-04-12Document traits in std::num (#7511)Manish Goregaokar-0/+4
2014-04-11libtest: rename `BenchHarness` to `Bencher`Liigo Zhuang-27/+27
Closes #12640
2014-04-08rustc: Remove f{32,64} % from the languageAlex Crichton-2/+8
This commit removes the compiler support for floating point modulus operations, as well as from the language. An implementation for this operator is now required to be provided by libraries. Floating point modulus is rarely used, doesn't exist in C, and is always lowered to an fmod library call by LLVM, and LLVM is considering removing support entirely. Closes #12278
2014-04-04Removed cmath and instrinsic wrapper.Michael Darakananda-205/+84
2014-04-02Fix fallout of requiring uint indicesAlex Crichton-8/+8
2014-04-01auto merge of #13225 : thestinger/rust/num, r=cmrbors-276/+126
The `Float` trait methods will be usable as functions via UFCS, and we came to a consensus to remove duplicate functions like this a long time ago. It does still make sense to keep the duplicate functions when the trait methods are static, unless the decision to leave out the in-scope trait name resolution for static methods changes.
2014-04-01auto merge of #13115 : huonw/rust/rand-errors, r=alexcrichtonbors-11/+11
move errno -> IoError converter into std, bubble up OSRng errors Also adds a general errno -> `~str` converter to `std::os`, and makes the failure messages for the things using `OSRng` (e.g. (transitively) the task-local RNG, meaning hashmap initialisation failures aren't such a black box).
2014-04-01remove the cmath moduleDaniel Micay-203/+126
This is an implementation detail of the `f32` and `f64` modules and it should not be public. It renames many functions and leaves out any provided by LLVM intrinsics, so it is not a sensible binding to the C standard library's math library and will never be a stable target. This also removes the abuse of link_name so that this can be switched to using automatically generated definitions in the future. This also removes the `scalbn` binding as it is equivalent to `ldexp` when `FLT_RADIX` is 2, which must always be true for Rust.
2014-04-01rand: bubble up IO messages futher.Huon Wilson-11/+11
The various ...Rng::new() methods can hit IO errors from the OSRng they use, and it seems sensible to expose them at a higher level. Unfortunately, writing e.g. `StdRng::new().unwrap()` gives a much poorer error message than if it failed internally, but this is a problem with all `IoResult`s.
2014-03-31num: rm wrapping of `Float` methods as functionsDaniel Micay-73/+0
The `Float` trait methods will be usable as functions via UFCS, and we came to a consensus to remove duplicate functions like this a long time ago. It does still make sense to keep the duplicate functions when the trait methods are static, unless the decision to leave out the in-scope trait name resolution for static methods changes.
2014-03-28Convert most code to new inner attribute syntax.Brian Anderson-22/+22
Closes #2569
2014-03-28Rename Pod into CopyFlavio Percoco-2/+2
Summary: So far, we've used the term POD "Plain Old Data" to refer to types that can be safely copied. However, this term is not consistent with the other built-in bounds that use verbs instead. This patch renames the Pod kind into Copy. RFC: 0003-opt-in-builtin-traits Test Plan: make check Reviewers: cmr Differential Revision: http://phabricator.octayn.net/D3
2014-03-25std: Touch various I/O documentation blocksAlex Crichton-5/+5
These are mostly touchups from the previous commit.
2014-03-25libstd: Document the following modules:Patrick Walton-46/+183
* native::io * std::char * std::fmt * std::fmt::parse * std::io * std::io::extensions * std::io::net::ip * std::io::net::udp * std::io::net::unix * std::io::pipe * std::num * std::num::f32 * std::num::f64 * std::num::strconv * std::os
2014-03-20rename std::vec -> std::sliceDaniel Micay-4/+4
Closes #12702
2014-03-08Removed DeepClone. Issue #12698.Michael Darakananda-2/+1
2014-03-05add tests for `min` and `max` from `Float`Daniel Micay-0/+24
2014-03-05consistently use LLVM floating point intrinsicsDaniel Micay-87/+18
2014-03-05add correct floating point `min` and `max` methods.Daniel Micay-2/+24
The `std::cmp` functions are not correct for floating point types. `min(NaN, 2.0)` and `min(2.0, NaN)` return different values, because these functions assume a total order. Floating point types need special `min`, `max` and `clamp` functions.
2014-02-28std: Change assert_eq!() to use {} instead of {:?}Alex Crichton-3/+3
Formatting via reflection has been a little questionable for some time now, and it's a little unfortunate that one of the standard macros will silently use reflection when you weren't expecting it. This adds small bits of code bloat to libraries, as well as not always being necessary. In light of this information, this commit switches assert_eq!() to using {} in the error message instead of {:?}. In updating existing code, there were a few error cases that I encountered: * It's impossible to define Show for [T, ..N]. I think DST will alleviate this because we can define Show for [T]. * A few types here and there just needed a #[deriving(Show)] * Type parameters needed a Show bound, I often moved this to `assert!(a == b)` * `Path` doesn't implement `Show`, so assert_eq!() cannot be used on two paths. I don't think this is much of a regression though because {:?} on paths looks awful (it's a byte array). Concretely speaking, this shaved 10K off a 656K binary. Not a lot, but sometime significant for smaller binaries.
2014-02-28std: Avoid using "{:?}" in format stringsAlex Crichton-5/+5
This removes all usage of Poly in format strings from libstd. This doesn't prevent more future strings from coming in, but it at least removes the ones for now.
2014-02-24Remove std::num::ToStrRadix from the preludeBrendan Zabarauskas-1/+3
2014-02-24Remove std::from_str::FromStr from the preludeBrendan Zabarauskas-0/+12
2014-02-24auto merge of #12445 : huonw/rust/less-unsafe, r=alexcrichtonbors-8/+4
Commits for details. Highlights: - `flate` returns `CVec<u8>` to save reallocating a whole new `&[u8]` - a lot of `transmute`s removed outright or replaced with `as` (etc.)
2014-02-23Remove all ToStr impls, add Show implsAlex Crichton-28/+0
This commit changes the ToStr trait to: impl<T: fmt::Show> ToStr for T { fn to_str(&self) -> ~str { format!("{}", *self) } } The ToStr trait has been on the chopping block for quite awhile now, and this is the final nail in its coffin. The trait and the corresponding method are not being removed as part of this commit, but rather any implementations of the `ToStr` trait are being forbidden because of the generic impl. The new way to get the `to_str()` method to work is to implement `fmt::Show`. Formatting into a `&mut Writer` (as `format!` does) is much more efficient than `ToStr` when building up large strings. The `ToStr` trait forces many intermediate allocations to be made while the `fmt::Show` trait allows incremental buildup in the same heap allocated buffer. Additionally, the `fmt::Show` trait is much more extensible in terms of interoperation with other `Writer` instances and in more situations. By design the `ToStr` trait requires at least one allocation whereas the `fmt::Show` trait does not require any allocations. Closes #8242 Closes #9806
2014-02-24arena,std,serialize: remove some unnecessary transmutes.Huon Wilson-8/+4
`as`-able transmutes, duplication and manual slice decomposition are silly.
2014-02-23auto merge of #12416 : alexcrichton/rust/highlight, r=huonwbors-2/+2
This adds simple syntax highlighting based off libsyntax's lexer to be sure to stay up to date with rust's grammar. Some of the highlighting is a bit ad-hoc, but it definitely seems to get the job done! This currently doesn't highlight rustdoc-rendered function signatures and structs that are emitted to each page because the colors already signify what's clickable and I think we'd have to figure out a different scheme before colorizing them. This does, however, colorize all code examples and source code. Closes #11393
2014-02-23std: Move intrinsics to std::intrinsics.Brian Anderson-12/+12
Issue #1457
2014-02-23rustdoc: Add syntax highlightingAlex Crichton-2/+2
This adds simple syntax highlighting based off libsyntax's lexer to be sure to stay up to date with rust's grammar. Some of the highlighting is a bit ad-hoc, but it definitely seems to get the job done! This currently doesn't highlight rustdoc-rendered function signatures and structs that are emitted to each page because the colors already signify what's clickable and I think we'd have to figure out a different scheme before colorizing them. This does, however, colorize all code examples and source code. Closes #11393
2014-02-21auto merge of #12382 : bjz/rust/fmt-int, r=alexcrichtonbors-21/+93
This is PR is the beginning of a complete rewrite and ultimate removal of the `std::num::strconv` module (see #6220), and the removal of the `ToStrRadix` trait in favour of using the `std::fmt` functionality directly. This should make for a cleaner API, encourage less allocation, and make the implementation more comprehensible . The `Formatter::{pad_integral, with_padding}` methods have also been refactored make things easier to understand. The formatting tests for integers have been moved out of `run-pass/ifmt.rs` in order to provide more immediate feedback when building using `make check-stage2-std NO_REBUILD=1`. Arbitrary radixes are now easier to use in format strings. For example: ~~~rust assert_eq!(format!("{:04}", radix(3, 2)), ~"0011"); ~~~ The benchmarks have been standardised between `std::num::strconv` and `std::num::fmt` to make it easier to compare the performance of the different implementations. ~~~ type | radix | std::num::strconv | std::num::fmt ======|=======|========================|====================== int | bin | 1748 ns/iter (+/- 150) | 321 ns/iter (+/- 25) int | oct | 706 ns/iter (+/- 53) | 179 ns/iter (+/- 22) int | dec | 640 ns/iter (+/- 59) | 207 ns/iter (+/- 10) int | hex | 637 ns/iter (+/- 77) | 205 ns/iter (+/- 19) int | 36 | 446 ns/iter (+/- 30) | 309 ns/iter (+/- 20) ------|-------|------------------------|---------------------- uint | bin | 1724 ns/iter (+/- 159) | 322 ns/iter (+/- 13) uint | oct | 663 ns/iter (+/- 25) | 175 ns/iter (+/- 7) uint | dec | 613 ns/iter (+/- 30) | 186 ns/iter (+/- 6) uint | hex | 519 ns/iter (+/- 44) | 207 ns/iter (+/- 20) uint | 36 | 418 ns/iter (+/- 16) | 308 ns/iter (+/- 32) ~~~
2014-02-22Reduce reliance on `to_str_radix`Brendan Zabarauskas-2/+2
This is in preparation to remove the implementations of ToStrRadix in integers, and to remove the associated logic from `std::num::strconv`. The parts that still need to be liberated are: - `std::fmt::Formatter::runplural` - `num::{bigint, complex, rational}`
2014-02-22Decouple integer formatting from std::num::strconvBrendan Zabarauskas-18/+88
This works towards a complete rewrite and ultimate removal of the `std::num::strconv` module (see #6220), and the removal of the `ToStrRadix` trait in favour of using the `std::fmt` functionality directly. This should make for a cleaner API, encourage less allocation, and make the implementation far more comprehensible. The `Formatter::pad_integral` method has also been refactored make it easier to understand. The formatting tests for integers have been moved out of `run-pass/ifmt.rs` in order to provide more immediate feedback when building using `make check-stage2-std NO_REBUILD=1`. The benchmarks have been standardised between std::num::strconv and std::num::fmt to make it easier to compare the performance of the different implementations. Arbitrary radixes are now easier to use in format strings. For example: ~~~ assert_eq!(format!("{:04}", radix(3, 2)), ~"0011"); ~~~
2014-02-22Add Pod trait bound to std::num::PrimitiveBrendan Zabarauskas-1/+3
2014-02-22Move std::num::Integer to libnumBrendan Zabarauskas-407/+18
2014-02-20move extra::test to libtestLiigo Zhuang-4/+4
2014-02-17auto merge of #12321 : bjz/rust/remove-real, r=alexcrichtonbors-500/+490
This is part of the effort to simplify `std::num`, as tracked in issue #10387. It is also a step towards a proper IEEE-754 trait (see #12281).
2014-02-17Rename Bitwise::population_count to Bitwise::count_ones and add ↵Brendan Zabarauskas-39/+89
Bitwise::count_zeros These are inspired by the [functions in the Julia standard library](http://docs.julialang.org/en/release-0.2/stdlib/base/#Base.count_ones).
2014-02-17Remove Real trait and move methods into FloatBrendan Zabarauskas-500/+490
This is part of the effort to simplify `std::num`, as tracked in issue #10387.
2014-02-15auto merge of #12302 : alexcrichton/rust/issue-12295, r=brsonbors-2/+0
The previous code erroneously assumed that 'steals > cnt' was always true, but that was a false assumption. The code was altered to decrement steals to a minimum of 0 instead of taking all of cnt into account. I didn't include the exact test from #12295 because it could run for quite awhile, and instead set the threshold for MAX_STEALS to much lower during testing. I found that this triggered the old bug quite frequently when running without this fix. Closes #12295
2014-02-15Silence some unused import warningsAlex Crichton-2/+0
2014-02-14Fix all code examplesAlex Crichton-21/+26
2014-02-14Enable 64-bit checked multiplication on 32-bitAlex Crichton-5/+1
This was just waiting for compiler-rt support, which was added in #12027 Closes #8449
2014-02-13Removed num::OrderableMichael Darakananda-210/+3