about summary refs log tree commit diff
path: root/src/libstd
AgeCommit message (Collapse)AuthorLines
2013-04-29libstd: Fix merge fallout.Patrick Walton-2/+0
2013-04-29librustc: Fix merge fallout.Patrick Walton-0/+1
2013-04-29test: Fix more tests.Patrick Walton-1/+1
2013-04-29librustc: Forbid type implementations on typedefs.Patrick Walton-12/+14
2013-04-29test: Fix tests.Patrick Walton-20/+28
2013-04-29librustc: Remove `ptr::addr_of`.Patrick Walton-108/+98
2013-04-29auto merge of #6110 : bjz/rust/numeric-traits, r=pcwaltonbors-2/+20
As discussed on issue #4819, I have created four new traits: `Algebraic`, `Trigonometric`, `Exponential` and `Hyperbolic`, and moved the appropriate methods into them from `Real`. ~~~rust pub trait Algebraic { fn pow(&self, n: Self) -> Self; fn sqrt(&self) -> Self; fn rsqrt(&self) -> Self; fn cbrt(&self) -> Self; fn hypot(&self, other: Self) -> Self; } pub trait Trigonometric { fn sin(&self) -> Self; fn cos(&self) -> Self; fn tan(&self) -> Self; fn asin(&self) -> Self; fn acos(&self) -> Self; fn atan(&self) -> Self; fn atan2(&self, other: Self) -> Self; } pub trait Exponential { fn exp(&self) -> Self; fn exp2(&self) -> Self; fn expm1(&self) -> Self; fn log(&self) -> Self; fn log2(&self) -> Self; fn log10(&self) -> Self; } pub trait Hyperbolic: Exponential { fn sinh(&self) -> Self; fn cosh(&self) -> Self; fn tanh(&self) -> Self; } ~~~ There was some discussion over whether we should shorten the names, for example `Trig` and `Exp`. No abbreviations have been agreed on yet, but this could be considered in the future. Additionally, `Integer::divisible_by` has been renamed to `Integer::is_multiple_of`.
2013-04-29Rename 'divisible_by' method to 'is_multiple_of', add tests for 'is_odd' and ↵Brendan Zabarauskas-2/+2
'is_even'
2013-04-29Implement Fractional for RatioBrendan Zabarauskas-0/+18
2013-04-29libstd: modify wrong shift width.gifnksm-1/+2
borrow = *elem << (uint::bits - n_bits); The code above contains a bug that the value of the right operand of the shift operator exceeds the size of the left operand, because sizeof(*elem) == 32, and 0 <= n_bits < 32 in 64bit architecture. If `--opt-level` option is not given to rustc, the code above runs as if the right operand is `(uint::bits - n_bits) % 32`, but if --opt-level is given, `borrow` is always zero. I wonder why this bug is not catched in the libstd's testsuite (I try the `rustc --test --opt-level=2 bigint.rs` before fixing the bug, but the unittest passes normally.)
2013-04-29libstd: remove implicit copying of BigInt/BigUintgifnksm-20/+37
2013-04-28core: Use a better termination condition in os::mkdir_recursiveTim Chevalier-6/+59
Instead of checking whether the parent is "." or "/", check the number of components. Also, more tests.
2013-04-28make way for a new iter moduleDaniel Micay-17/+17
2013-04-28auto merge of #6092 : gifnksm/rust/impl-integer-bigint, r=graydonbors-144/+383
This is a follow-up commit for #6041 (and depending on #6048). Also adding `#[inline(always)]` for almost every methods in `std::bigint`.
2013-04-28libstd: inlining almost every methods in bigint module.gifnksm-1/+86
2013-04-28libstd: impl Integer for BigUint/BigInt.gifnksm-143/+297
Also remove abs() method from the non-trait impl for BigInt/BigUint. That method is provided in the Signed trait.
2013-04-27only use #[no_core] in libcoreDaniel Micay-142/+0
2013-04-27auto merge of #6071 : bjz/rust/numeric-traits, r=graydonbors-19/+27
As part of the numeric trait reform (see issue #4819), I have added the following traits to `core::num` and implemented them for Rust's primitive numeric types: ~~~rust pub trait Bitwise: Not<Self> + BitAnd<Self,Self> + BitOr<Self,Self> + BitXor<Self,Self> + Shl<Self,Self> + Shr<Self,Self> {} pub trait BitCount { fn population_count(&self) -> Self; fn leading_zeros(&self) -> Self; fn trailing_zeros(&self) -> Self; } pub trait Bounded { fn min_value() -> Self; fn max_value() -> Self; } pub trait Primitive: Num + NumCast + Bounded + Neg<Self> + Add<Self,Self> + Sub<Self,Self> + Mul<Self,Self> + Quot<Self,Self> + Rem<Self,Self> { fn bits() -> uint; fn bytes() -> uint; } pub trait Int: Integer + Primitive + Bitwise + BitCount {} pub trait Float: Real + Signed + Primitive { fn NaN() -> Self; fn infinity() -> Self; fn neg_infinity() -> Self; fn neg_zero() -> Self; fn is_NaN(&self) -> bool; fn is_infinite(&self) -> bool; fn is_finite(&self) -> bool; fn mantissa_digits() -> uint; fn digits() -> uint; fn epsilon() -> Self; fn min_exp() -> int; fn max_exp() -> int; fn min_10_exp() -> int; fn max_10_exp() -> int; fn mul_add(&self, a: Self, b: Self) -> Self; fn next_after(&self, other: Self) -> Self; } ~~~ Note: I'm not sure my implementation for `BitCount::trailing_zeros` and `BitCount::leading_zeros` is correct for uints. I also need some assistance creating appropriate unit tests for them. More work needs to be done in implementing specialized primitive floating-point and integer methods, but I'm beginning to reach the limits of my knowledge. Please leave your suggestions/critiques/ideas on #4819 if you have them – I'd very much appreciate hearing them. I have also added an `Orderable` trait: ~~~rust pub trait Orderable: Ord { fn min(&self, other: &Self) -> Self; fn max(&self, other: &Self) -> Self; fn clamp(&self, mn: &Self, mx: &Self) -> Self; } ~~~ This is a temporary trait until we have default methods. We don't want to encumber all implementors of Ord by requiring them to implement these functions, but at the same time we want to be able to take advantage of the speed of the specific numeric functions (like the `fmin` and `fmax` intrinsics).
2013-04-27auto merge of #6064 : thestinger/rust/char, r=catamorphismbors-55/+37
2013-04-26Add is_zero method to ZeroBrendan Zabarauskas-19/+27
2013-04-25implement Ord, TotalEq and TotalOrd for charDaniel Micay-55/+37
Closes #6063
2013-04-25Update impl of Round for RatioBrendan Zabarauskas-20/+22
2013-04-25Use #[cfg(not(stage0))] to exclude items from stage0Brendan Zabarauskas-12/+4
As requested on the mailing list: https://mail.mozilla.org/pipermail/rust-dev/2013-April/003713.html
2013-04-25Fix incorrect replacement of `modulo` with `rem`Brendan Zabarauskas-1/+1
2013-04-24Fixed typo... And a billion other things.Marvin Löbel-2/+2
2013-04-24Removed ascii functions from other modulesMarvin Löbel-3/+7
Replaced str::to_lowercase and str::to_uppercase
2013-04-24auto merge of #6036 : huonw/rust/core-less-at, r=nikomatsakisbors-61/+27
From a cursory `git grep` this removes the last part of `core` that requires on `@` (other than `io` and the task local data section). It renames `RandRes` to ~~StdRng~~ `IsaacRng` and `XorShiftState` to `XorShiftRng` as well as moving their constructors to static methods. To go with this, it adds `rng()` which is designed to be used when the programmer just wants a random number generator, without caring about which exact algorithm is being used. It also removes all the `gen_int`, `gen_uint`, `gen_char` (etc) methods on `RngUtil` (by moving the defintions to the actual `Rand` instances). The replacement is using `RngUtil::gen`, either type-inferred or with an annotation (`rng.gen::<uint>()`). I tried to have the `Rng` and `RngUtil` traits exported by `core::prelude` (since `core::rand` (except for `random()`) is useless without them), but this caused [an explosion of (seemingly unrelated) `error: unresolved import`'s](https://gist.github.com/5451839).
2013-04-24libcore: unify `gen_<type>` methods on `rand::RngUtil` into the generic `gen`.Huon Wilson-50/+15
This moves all the basic random value generation into the Rand instances for each type and then removes the `gen_int`, `gen_char` (etc) methods on RngUtil, leaving only the generic `gen` and the more specialised methods. Also, removes some imports that are redundant due to a `use core::prelude::*` statement.
2013-04-24libcore: remove @Rng from rand, and use traits instead.Huon Wilson-12/+13
Also, rename RandRes -> IsaacRng, and make the constructors static methods.
2013-04-24Implement Signed and Unsigned traits and remove related predicate functionsBrendan Zabarauskas-8/+25
2013-04-23Removing more unnecessary unsafe blocks throughoutAlex Crichton-19/+15
2013-04-22auto merge of #6013 : gifnksm/rust/bigint-quot-rem, r=graydonbors-56/+57
BigInt had been supported quot/rem and div/mod correctly, but after merging #5990 they have been broken. This commit fixes it.
2013-04-22auto merge of #5966 : alexcrichton/rust/issue-3083, r=graydonbors-22/+20
Closes #3083. This takes a similar approach to #5797 where a set is present on the `tcx` of used mutable definitions. Everything is by default warned about, and analyses must explicitly add mutable definitions to this set so they're not warned about. Most of this was pretty straightforward, although there was one caveat that I ran into when implementing it. Apparently when the old modes are used (or maybe `legacy_modes`, I'm not sure) some different code paths are taken to cause spurious warnings to be issued which shouldn't be issued. I'm not really sure how modes even worked, so I was having a lot of trouble tracking this down. I figured that because they're a legacy thing that I'd just de-mode the compiler so that the warnings wouldn't be a problem anymore (or at least for the compiler). Other than that, the entire compiler compiles without warnings of unused mutable variables. To prevent bad warnings, #5965 should be landed (which in turn is waiting on #5963) before landing this. I figured I'd stick it out for review anyway though.
2013-04-23libstd: correct bigint's quot/rem, div/modulogifnksm-56/+57
2013-04-22libstd: denominator isn't quotientHuon Wilson-1/+1
2013-04-22Rename Div operator trait to Quot and Modulo operator trait to RemBrendan Zabarauskas-75/+73
2013-04-20std: remove unused 'mut' variablesAlex Crichton-22/+20
2013-04-20Replaced many instances of reinterpret_cast with transmuteMatthijs Hofstra-24/+24
2013-04-19std: clean up tests (mostly unused unsafe blocks)Alex Crichton-132/+116
2013-04-19librustc: WIP patch for using the return value.Patrick Walton-10/+22
2013-04-19libstd: Micro-optimize vuint_atPatrick Walton-4/+53
2013-04-18core::comm: Modernize constructors to use `new`Brian Anderson-31/+31
2013-04-18Small typos, year date and URL of the fbuild system for reference.Olivier Saut-6/+7
2013-04-15auto merge of #5901 : thestinger/rust/iterator, r=sanxiynbors-3/+3
Can now use them like `x.transform(|i| i + 3).zip(y.filter(|i| i % 2)`.
2013-04-15auto merge of #5895 : huonw/rust/no-pub-tests, r=thestingerbors-254/+254
This patch is a sledge hammer that moves all tests into `#[cfg(test)] mod test { .. }`, and makes them private, there were several instances of `pub mod tests { #[test] pub fn ... } `. (The reason for this is I was playing with using `syntax` to index code ([result so far](http://www.ug.it.usyd.edu.au/~hwil7821/rust-api/)) and it was getting some junk from the tests.) The rustdoc commit is particularly brutal, so it's fine if that one isn't landed.
2013-04-15iterator: use an IteratorUtil traitDaniel Micay-3/+3
2013-04-16libcore,std,syntax,rustc: move tests into `mod tests`, make them private (no ↵Huon Wilson-254/+254
pub mod or pub fn).
2013-04-15auto merge of #5879 : astrieanna/rust/document_std_base64, r=catamorphismbors-1/+79
This adds examples for the methods in std::base64. Each example is complete in the sense that you can copy-paste it into a file and compile it successfully without adding anything (imports, etc). The hardest part of figuring out how to use this was figuring out the right import statements to put at the top.
2013-04-14Change to 4-space indents in code examplesLeah Hanson-14/+14
2013-04-14update copyright notice on base64.rsLeah Hanson-1/+1