about summary refs log tree commit diff
path: root/src/libstd/num/mod.rs
AgeCommit message (Collapse)AuthorLines
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-24/+140
* 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-2/+2
Closes #12702
2014-03-08Removed DeepClone. Issue #12698.Michael Darakananda-2/+1
2014-03-05add correct floating point `min` and `max` methods.Daniel Micay-0/+3
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-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-2/+10
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-22Decouple integer formatting from std::num::strconvBrendan Zabarauskas-1/+7
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-27/+7
2014-02-20move extra::test to libtestLiigo Zhuang-1/+2
2014-02-17auto merge of #12321 : bjz/rust/remove-real, r=alexcrichtonbors-172/+166
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-6/+25
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-172/+166
This is part of the effort to simplify `std::num`, as tracked in issue #10387.
2014-02-14Fix all code examplesAlex Crichton-2/+4
2014-02-14Enable 64-bit checked multiplication on 32-bitAlex Crichton-1/+1
This was just waiting for compiler-rt support, which was added in #12027 Closes #8449
2014-02-13Removed num::OrderableMichael Darakananda-20/+3
2014-02-01Make next_power_of_two generic for unsigned integersBrendan Zabarauskas-1/+75
Also rename `next_power_of_two_opt` to `checked_next_power_of_two`.
2014-01-31auto merge of #11918 : omasanori/rust/reduce-warnings, r=alexcrichtonbors-1/+0
Moving forward to green waterfall.
2014-01-30Remove Times traitBrendan Zabarauskas-12/+0
`Times::times` was always a second-class loop because it did not support the `break` and `continue` operations. Its playful appeal was then lost after `do` was disabled for closures. It's time to let this one go.
2014-01-30Remove unused imports.OGINO Masanori-1/+0
Signed-off-by: OGINO Masanori <masanori.ogino@gmail.com>
2014-01-25Uppercase numeric constantsChris Wong-245/+245
The following are renamed: * `min_value` => `MIN` * `max_value` => `MAX` * `bits` => `BITS` * `bytes` => `BYTES` Fixes #10010.
2014-01-20Improve std::num::pow implementationBrendan Zabarauskas-42/+30
The implementation has been made more succinct and no longer requires Clone. The coverage of the associated unit test has also been increased to check more combinations of bases, exponents, and expected results.
2014-01-20Add operator trait constraints to std::num::{Zero, One} and document their ↵Brendan Zabarauskas-16/+46
appropriate use Zero and One have precise definitions in mathematics. Documentation has been added to describe the appropriate uses for these traits and the laws that they should satisfy. For more information regarding these identities, see the following wikipedia pages: - http://wikipedia.org/wiki/Additive_identity - http://wikipedia.org/wiki/Multiplicative_identity
2014-01-18Replace old pow_with_uint with the new pow funcFlavio Percoco-37/+0
There was an old and barely used implementation of pow, which expected both parameters to be uint and required more traits to be implemented. Since a new implementation for `pow` landed, I'm proposing to remove this old impl in favor of the new one. The benchmark shows that the new implementation is faster than the one being removed: test num::bench::bench_pow_function ..bench: 9429 ns/iter (+/- 2055) test num::bench::bench_pow_with_uint_function ...bench: 28476 ns/iter (+/- 2202)
2014-01-18Added benchmark for pow and pow_with_uintFlavio Percoco-0/+21
2014-01-18auto merge of #11622 : bjz/rust/simplify-primitive-trait, r=brsonbors-16/+5
As part of #10387, this removes the `Primitive::{bits, bytes, is_signed}` methods and removes the trait's operator trait constraints for the reasons outlined below: - The `Primitive::{bits, bytes}` associated functions were originally added to reflect the existing `BITS` and `BYTES`statics included in the numeric modules. These statics are only exist as a workaround for Rust's lack of CTFE, and should be deprecated in the future in favor of using the `std::mem::size_of` function (see #11621). - `Primitive::is_signed` seems to be of little utility and does not seem to be used anywhere in the Rust compiler or libraries. It is also rather ugly to call due to the `Option<Self>` workaround for #8888. - The operator trait constraints are already covered by the `Num` trait.
2014-01-18Simplify std::num::Primitive trait definitionBrendan Zabarauskas-16/+5
This removes the `Primitive::{bits, bytes, is_signed}` methods and removes the operator trait constraints, for the reasons outlined below: - The `Primitive::{bits, bytes}` associated functions were originally added to reflect the existing `BITS` and `BYTES` statics included in the numeric modules. These statics are only exist as a workaround for Rust's lack of CTFE, and should probably be deprecated in the future in favor of using the `std::mem::size_of` function (see #11621). - `Primitive::is_signed` seems to be of little utility and does not seem to be used anywhere in the Rust compiler or libraries. It is also rather ugly to call due to the `Option<Self>` workaround for #8888. - The operator trait constraints are already covered by the `Num` trait.
2014-01-17Add a generic power functionFlavio Percoco-4/+64
The patch adds a `pow` function for types implementing `One`, `Mul` and `Clone` trait. The patch also renames f32 and f64 pow into powf in order to still have a way to easily have float powers. It uses llvms intrinsics. The pow implementation for all num types uses the exponentiation by square. Fixes bug #11499
2014-01-16Merge Bitwise and BitCount traits and remove from prelude, along with BoundedBrendan Zabarauskas-14/+17
One less trait in std::num, and three less exported in the prelude.
2014-01-13Remove RealExtBrendan Zabarauskas-18/+0
These functions are of little utility outside a small subset of use cases. If people need them for their own projects then they can use their own bindings for libm (which aren't hard to make).
2014-01-09auto merge of #11412 : bjz/rust/num-cleanups, r=alexcrichtonbors-113/+93
The methods contained in `std::num::{Algebraic, Trigonometric, Exponential, Hyperbolic}` have now been moved into `std::num::Real`. This is part of an ongoing effort to simplify `std::num` (see issue #10387). `std::num::RealExt` has also been removed from the prelude because it is not a commonly used trait. r? @alexcrichton
2014-01-09Remove ApproxEq and assert_approx_eq!Brendan Zabarauskas-56/+3
This trait seems to stray too far from the mandate of a standard library as implementations may vary between use cases.
2014-01-09Merge some numeric traits with Real and don't re-export RealExtBrendan Zabarauskas-113/+93
The methods contained in `std::num::{Algebraic, Trigonometric, Exponential, Hyperbolic}` have now been moved into `std::num::Real`. This is part of an ongoing effort to simplify `std::num` (see issue #10387). `std::num::RealExt` has also been removed from the prelude because it is not a commonly used trait.
2014-01-03libstd: Remove all support code related to `@mut`Patrick Walton-5/+0
2013-12-27std: uniform modules titles for docLuca Bruno-1/+1
This commit uniforms the short title of modules provided by libstd, in order to make their roles more explicit when glancing at the index. Signed-off-by: Luca Bruno <lucab@debian.org>
2013-12-23std: Fix all code examplesAlex Crichton-11/+14
2013-12-15std: fix spelling in docs.Huon Wilson-2/+2
2013-12-04Decode a float into integersVolker Mische-0/+2
The `integer_decode()` function decodes a float (f32/f64) into integers containing the mantissa, exponent and sign. It's needed for `rationalize()` implementation of #9838. The code got ported from ABCL [1]. [1] http://abcl.org/trac/browser/trunk/abcl/src/org/armedbear/lisp/FloatFunctions.java?rev=14465#L94
2013-11-26libstd: Fix Win32 and other bustage.Patrick Walton-1/+1
2013-11-19libstd: Change all uses of `&fn(A)->B` over to `|A|->B` in libstdPatrick Walton-1/+1
2013-11-11Use constants instead of raw values.Jay Anderson-4/+2
2013-11-11Got directions backwards in to_degrees and to_radians docs.Jay Anderson-2/+2
2013-11-11Add docs for traits Exponential, Hyperbolic, BitCount.Jay Anderson-2/+44
2013-11-11Update docs for Fractional, Algebraic, Round, and Trigonometric traits.Jay Anderson-0/+89
2013-11-03Rename files to match current recommendations.Chris Morgan-0/+1596
New standards have arisen in recent months, mostly for the use of rustpkg, but the main Rust codebase has not been altered to match these new specifications. This changeset rectifies most of these issues. - Renamed the crate source files `src/libX/X.rs` to `lib.rs`, for consistency with current styles; this affects extra, rustc, rustdoc, rustpkg, rustuv, std, syntax. - Renamed `X/X.rs` to `X/mod.rs,` as is now recommended style, for `std::num` and `std::terminfo`. - Shifted `src/libstd/str/ascii.rs` out of the otherwise unused `str` directory, to be consistent with its import path of `std::ascii`; libstd is flat at present so it's more appropriate thus. While this removes some `#[path = "..."]` directives, it does not remove all of them, and leaves certain other inconsistencies, such as `std::u8` et al. which are actually stored in `src/libstd/num/` (one subdirectory down). No quorum has been reached on this issue, so I felt it best to leave them all alone at present. #9208 deals with the possibility of making libstd more hierarchical (such as changing the crate to match the current filesystem structure, which would make the module path `std::num::u8`). There is one thing remaining in which this repository is not rustpkg-compliant: rustpkg would have `src/std/` et al. rather than `src/libstd/` et al. I have not endeavoured to change that at this point as it would guarantee prompt bitrot and confusion. A change of that magnitude needs to be discussed first.