summary refs log tree commit diff
path: root/src/libstd/num/uint_macros.rs
AgeCommit message (Collapse)AuthorLines
2014-03-28Convert most code to new inner attribute syntax.Brian Anderson-2/+2
Closes #2569
2014-02-24Remove std::num::ToStrRadix from the preludeBrendan Zabarauskas-0/+1
2014-02-23Remove all ToStr impls, add Show implsAlex Crichton-8/+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-21auto merge of #12382 : bjz/rust/fmt-int, r=alexcrichtonbors-1/+1
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-1/+1
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-22Move std::num::Integer to libnumBrendan Zabarauskas-111/+0
2014-02-17Rename Bitwise::population_count to Bitwise::count_ones and add ↵Brendan Zabarauskas-7/+18
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-13Removed num::OrderableMichael Darakananda-33/+0
2014-02-01Move int and uint overflow tests into macrosBrendan Zabarauskas-0/+7
2014-01-30Remove unused imports.OGINO Masanori-1/+0
Signed-off-by: OGINO Masanori <masanori.ogino@gmail.com>
2014-01-25Uppercase numeric constantsChris Wong-8/+8
The following are renamed: * `min_value` => `MIN` * `max_value` => `MAX` * `bits` => `BITS` * `bytes` => `BYTES` Fixes #10010.
2014-01-18Simplify std::num::Primitive trait definitionBrendan Zabarauskas-17/+1
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-15auto merge of #11548 : bjz/rust/bitwise, r=alexcrichtonbors-3/+2
One less trait in `std::num` and three less exported in the prelude. cc. #10387
2014-01-16Merge Bitwise and BitCount traits and remove from prelude, along with BoundedBrendan Zabarauskas-3/+2
One less trait in std::num, and three less exported in the prelude.
2014-01-15Use the least significant beat to determine if int/uint is evenFlavio Percoco-1/+1
2014-01-07Fix remaining cases of leaking importsAlex Crichton-0/+1
2013-12-05Fix documentation typo (divison operator is not backslash)Alexandros Tasos-1/+1
2013-11-29Removed module macro workaround for signed and unsigned integersMarvin Löbel-15/+2
2013-11-29Removed useless cmp::{min, max} reexports from the integer modulesMarvin Löbel-2/+0
2013-11-29Removed a few macro-expanding-to-module workaroundsMarvin Löbel-1/+3
Also documented a few issues
2013-11-26libstd: Remove all non-`proc` uses of `do` from libstdPatrick Walton-4/+4
2013-11-19libstd: Change all uses of `&fn(A)->B` over to `|A|->B` in libstdPatrick Walton-1/+1
2013-10-17std: Move size/align functions to std::mem. #2240Brian Anderson-3/+3
2013-10-05std: add Primitive.is_signedErick Tryzelaar-0/+3
2013-09-20Implement a web backend for rustdoc_ngAlex Crichton-0/+1
This large commit implements and `html` output option for rustdoc_ng. The executable has been altered to be invoked as "rustdoc_ng html <crate>" and it will dump everything into the local "doc" directory. JSON can still be generated by changing 'html' to 'json'. This also fixes a number of bugs in rustdoc_ng relating to comment stripping, along with some other various issues that I found along the way. The `make doc` command has been altered to generate the new documentation into the `doc/ng/$(CRATE)` directories.
2013-09-18Remove and replace cond! Closes #9282.Jimmy Zelinskie-5/+5
2013-09-15Remove {uint,int,u64,i64,...}::from_str,from_str_radixblake2-ppc-43/+28
Remove these in favor of the two traits themselves and the wrapper function std::from_str::from_str. Add the function std::num::from_str_radix in the corresponding role for the FromStrRadix trait.
2013-09-15std::num: Remove `range_step` for each numeric typeblake2-ppc-151/+0
Replaced by `std::iter::range_step`
2013-09-12std: Add a bunch of Default implsErick Tryzelaar-0/+6
2013-09-08auto merge of #8988 : cmr/rust/fromstr_fn, r=brsonbors-1/+1
It just calls out to the associated function on the trait.
2013-09-08Fix import order which caused the wrong from_str to be in scopeCorey Richardson-1/+1
2013-09-05Rename str::from_bytes to str::from_utf8, closes #8985Florian Hahn-1/+1
2013-08-30remove several 'ne' methodsEric Martin-2/+0
2013-08-27librustc: Ensure that type parameters are in the right positions in paths.Patrick Walton-4/+5
This removes the stacking of type parameters that occurs when invoking trait methods, and fixes all places in the standard library that were relying on it. It is somewhat awkward in places; I think we'll probably want something like the `Foo::<for T>::new()` syntax.
2013-08-22Enabled unit tests in std and extra.Vadim Chugunov-4/+0
2013-08-21auto merge of #8610 : kballard/rust/mod_floor, r=alexcrichtonbors-2/+15
`mod_floor()` was incorrectly defined for uint types as `a / b` instead of `a % b`.
2013-08-20rm obsolete integer to_str{,_radix} free functionsDaniel Micay-38/+27
2013-08-19Fix mod_floor() for uint primitive typesKevin Ballard-2/+15
2013-08-11num: implement CheckedDivDaniel Micay-1/+18
2013-08-09Remove redundant Ord method impls.OGINO Masanori-6/+0
Basically, generic containers should not use the default methods since a type of elements may not guarantees total order. str could use them since u8's Ord guarantees total order. Floating point numbers are also broken with the default methods because of NaN. Thanks for @thestinger. Timespec also guarantees total order AIUI. I'm unsure whether extra::semver::Identifier does so I left it alone. Proof needed. Signed-off-by: OGINO Masanori <masanori.ogino@gmail.com>
2013-08-07Implement DoubleEndedIterator on RangeKevin Ballard-16/+1
Range is now invertable as long as its element type conforms to Integer. Remove int::range_rev() et al in favor of range().invert().
2013-08-03replace all remaining `for` with `foreach` or `do`Daniel Micay-22/+29
2013-08-02replace `range` with an external iteratorDaniel Micay-14/+1
2013-07-24Change 'print(fmt!(...))' to printf!/printfln! in src/lib*Birunthan Mohanathas-1/+1
2013-07-10Switch over to new range_rev semantics; fix #5270.Felix S. Klock II-3/+4
2013-07-10Refactored int/uint range code in preparation for change to range_rev semantics.Felix S. Klock II-17/+76
Also added unit tests of range code to test refactoring. The num-range-rev.rs test will need to be updated when the range_rev semantics change.
2013-07-08 Replaces the free-standing functions in f32, &c.Jens Nockert-42/+0
The free-standing functions in f32, f64, i8, i16, i32, i64, u8, u16, u32, u64, float, int, and uint are replaced with generic functions in num instead. If you were previously using any of those functions, just replace them with the corresponding function with the same name in num. Note: If you were using a function that corresponds to an operator, use the operator instead.
2013-07-01rustc: add a lint to enforce uppercase statics.Huon Wilson-0/+2
2013-06-30Specialize to_str_common for floats/integers in strconvAlex Crichton-9/+18
This allows the integral paths to avoid allocations on the heap Closes #4424, #4423
2013-06-28librustc: Disallow "mut" from distributing over bindings.Patrick Walton-1/+2
This is the backwards-incompatible part of per-binding-site "mut".