Commit Graph

17456 Commits

Author SHA1 Message Date
bors
88dd53a754 auto merge of #6081 : brson/rust/out-of-stack, r=thestinger
People hit the recursion depth limit too often, it's not possible
to unwind reliably from out-of-stack.

Issues #3555, #3695
2013-04-27 16:24:34 -07:00
bors
9f118865a2 auto merge of #6072 : cmr/rust/better_import_error, r=graydon 2013-04-27 14:24:36 -07:00
bors
aa38867e4e auto merge of #6071 : bjz/rust/numeric-traits, r=graydon
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-27 13:09:35 -07:00
bors
5de74f3e75 auto merge of #6070 : thestinger/rust/tutorial, r=pcwalton 2013-04-27 12:09:35 -07:00
bors
9ea32a380d auto merge of #6066 : djui/rust/patch-1, r=graydon 2013-04-27 10:24:35 -07:00
bors
47dbcdc455 auto merge of #6064 : thestinger/rust/char, r=catamorphism 2013-04-27 09:27:36 -07:00
bors
46806b7ae0 auto merge of #6059 : Kimundi/rust/nice-fail, r=pcwalton
r? @brson

Unwinding through macros now happens as a call to the trait function `FailWithCause::fail_with()`, which consumes self, allowing to use a more generic failure object in the future.
2013-04-26 22:45:36 -07:00
bors
8804b13bd2 auto merge of #6058 : huonw/rust/rt-isaac-update, r=graydon
The "unsigned 4 byte" `ub4`s are actually 8 bytes on 64-bit platforms
which mean that some bits > 2**32 were retained in calculations, these
would then "reappear" after a right shift and so the stream of random numbers
would differ on 32 bit vs 64 bit platforms.

http://burtleburtle.net/bob/c/randport.c
2013-04-26 21:57:35 -07:00
Brendan Zabarauskas
9cdf402c80 Propagate NaNs for Orderable methods impled on floating-point primitives 2013-04-27 13:13:28 +10:00
Brendan Zabarauskas
c9d099d60d Fix copy-paste mistakes 2013-04-27 12:42:34 +10:00
bors
7c1696b529 auto merge of #6057 : cmr/rust/map_zip, r=graydon
I think the name is more clear, and fits with filter_map etc.
2013-04-26 17:42:36 -07:00
Brendan Zabarauskas
35f33c17f7 Remove unnecessary fallbacks
The `target_word_size` attribute is always available at compile time, so there is no need for a fallback.
2013-04-27 10:34:29 +10:00
Brendan Zabarauskas
32df8ed877 Rename nextafter to next_after to match method name in Float 2013-04-27 10:16:09 +10:00
bors
b67a7b9004 auto merge of #6077 : brson/rust/valgrind, r=brson 2013-04-26 16:54:35 -07:00
Brendan Zabarauskas
4cc9d0ba7e Add additional constants to primitive floating point numbers
These follow the values defined in the C99 standard
2013-04-27 09:07:40 +10:00
Tim Chevalier
848641fcb5 core: Move mkdir_recursive from rustpkg into core::os
mkdir_recursive creates a directory as well as any of its
parent directories that don't exist already. Seems like a useful
thing to have in core.
2013-04-26 15:51:22 -07:00
Brian Anderson
149047e55d rt: Set the stack depth limit to 1GB. Abort on error.
People hit the recursion depth limit too often, it's not possible
to unwind reliably from out-of-stack.

Issues #3555, #3695
2013-04-26 15:39:54 -07:00
Brian Anderson
2c99e3dc3e Suppress all 'cond' errors in valgrind. #5856 2013-04-26 13:41:33 -07:00
Daniel Micay
195911fca4 tutorial-ffi: add example of a custom destructor 2013-04-26 14:07:57 -04:00
Daniel Micay
721e1143a5 tutorial: rework the section on destructors
This removes the comparison to manual memory management examples,
because it requires too much existing knowledge. Implementing custom
destructors can be covered in the FFI tutorial, where `unsafe` is
already well explained.
2013-04-26 14:07:47 -04:00
Brendan Zabarauskas
b7cf89f6e8 Add mul_add and next_after methods to Float 2013-04-27 01:02:30 +10:00
Brendan Zabarauskas
6cc7107aa6 Add Orderable trait
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-27 01:01:53 +10:00
Huon Wilson
1fc8a2f2a4 rt: use the [u]int[nn]_t types in the RNG.
This means that `ub4`s are always 4 bytes, rather than being 8 bytes on
x64. (Suggested but not implemented by upstream: "Porting it to a 64-bit
machine [...] may just need an adjustment of the definition of ub4")
2013-04-26 22:13:24 +10:00
Uwe Dauernheim
d314090b85 Fix typo 2013-04-26 14:47:15 +03:00
Brendan Zabarauskas
6efbbf2e14 Combine PrimitiveInt, Int, and Uint traits into one single trait
Having three traits for primitive ints/uints seemed rather excessive. If users wish to specify between them they can simply combine Int with either the Signed and Unsigned traits. For example: fn foo<T: Int + Signed>() { … }
2013-04-26 19:56:11 +10:00
Corey Richardson
8dd9dc995e add comment 2013-04-26 05:28:43 -04:00
Corey Richardson
b085b51357 Offer a hint on some unresolved imports
I didn't know how to use "use" initially, and an error message like this would
have solved quite a bit of frustration. I think this properly handles cases
where it's not appropriate but I'm not sure.
2013-04-26 04:59:28 -04:00
Marvin Löbel
928a07e9cb Added test cases for all fail message formats 2013-04-26 10:23:12 +02:00
Brendan Zabarauskas
faaf3bf149 Fix failing test 2013-04-26 17:25:17 +10:00
Brendan Zabarauskas
d0737451fc Add BitCount trait 2013-04-26 16:27:51 +10:00
Brendan Zabarauskas
4c07f5e457 Add Int, Uint and Float traits for primitive numbers 2013-04-26 10:22:08 +10:00
Brendan Zabarauskas
b62421000c Add Bitwise, Bounded, Primitive, and PrimitiveInt traits 2013-04-26 10:02:00 +10:00
Brendan Zabarauskas
f40be999ca Minor style improvements for test functions
Use argument pattern-matching for test_division_rule and remove visibility specifier for test_signed
2013-04-26 09:58:40 +10:00
Brendan Zabarauskas
dbc2e99693 Use /// doc-comment form instead of /** */ 2013-04-26 09:55:49 +10:00
Uwe Dauernheim
7a9037bfde Allow customization of indent offset 2013-04-26 00:06:57 +03:00
bors
64412eca10 auto merge of #6055 : cmr/rust/incoming, r=graydon,brson 2013-04-25 13:30:36 -07:00
Brendan Zabarauskas
ad0b337036 Add is_zero method to Zero 2013-04-26 05:55:26 +10:00
Daniel Micay
6d589f88f7 implement Ord, TotalEq and TotalOrd for char
Closes #6063
2013-04-25 15:43:16 -04:00
bors
0604468fd5 auto merge of #6054 : catamorphism/rust/rustpkg, r=graydon
r? @graydon

Sorry, this pull request is a few different things at once, but I tried to make them separate commits.

First, as before, this should do file searching the way that's described in the doc now.

Second, there's also some preliminary work on the install command (really just tests for it).
2013-04-25 12:42:41 -07:00
bors
ac69ee418b auto merge of #6048 : bjz/rust/numeric-traits, r=pcwalton
As part of the numeric trait reform (see issue #4819), I have added the following traits to `core::num` and implemented them for floating point types:

~~~rust
pub trait Round {
    fn floor(&self) -> Self;
    fn ceil(&self) -> Self;
    fn round(&self) -> Self;
    fn trunc(&self) -> Self;
    fn fract(&self) -> Self;
}

pub trait Fractional: Num
                    + Ord
                    + Round
                    + Quot<Self,Self> {
    fn recip(&self) -> Self;
}

pub trait Real: Signed
              + Fractional {
    // Common Constants
    fn pi() -> Self;
    fn two_pi() -> Self;
    fn frac_pi_2() -> Self;
    fn frac_pi_3() -> Self;
    fn frac_pi_4() -> Self;
    fn frac_pi_6() -> Self;
    fn frac_pi_8() -> Self;
    fn frac_1_pi() -> Self;
    fn frac_2_pi() -> Self;
    fn frac_2_sqrtpi() -> Self;
    fn sqrt2() -> Self;
    fn frac_1_sqrt2() -> Self;
    fn e() -> Self;
    fn log2_e() -> Self;
    fn log10_e() -> Self;
    fn log_2() -> Self;
    fn log_10() -> Self;

    // Exponential functions
    fn pow(&self, n: Self) -> Self;
    fn exp(&self) -> Self;
    fn exp2(&self) -> Self;
    fn expm1(&self) -> Self;
    fn ldexp(&self, n: int) -> Self;
    fn log(&self) -> Self;
    fn log2(&self) -> Self;
    fn log10(&self) -> Self;
    fn log_radix(&self) -> Self;
    fn ilog_radix(&self) -> int;
    fn sqrt(&self) -> Self;
    fn rsqrt(&self) -> Self;
    fn cbrt(&self) -> Self;

    // Angular conversions
    fn to_degrees(&self) -> Self;
    fn to_radians(&self) -> Self;

    // Triganomic functions
    fn hypot(&self, other: Self) -> Self;
    fn sin(&self) -> Self;
    fn cos(&self) -> Self;
    fn tan(&self) -> Self;

    // Inverse triganomic functions
    fn asin(&self) -> Self;
    fn acos(&self) -> Self;
    fn atan(&self) -> Self;
    fn atan2(&self, other: Self) -> Self;

    // Hyperbolic triganomic functions
    fn sinh(&self) -> Self;
    fn cosh(&self) -> Self;
    fn tanh(&self) -> Self;
}

/// Methods that are harder to implement and not commonly used.
pub trait RealExt: Real {
    // Gamma functions
    fn lgamma(&self) -> (int, Self);
    fn tgamma(&self) -> Self;

    // Bessel functions
    fn j0(&self) -> Self;
    fn j1(&self) -> Self;
    fn jn(&self, n: int) -> Self;
    fn y0(&self) -> Self;
    fn y1(&self) -> Self;
    fn yn(&self, n: int) -> Self;
} 
~~~

The constants in `Real` could be [associated items](http://smallcultfollowing.com/babysteps/blog/2013/04/03/associated-items-continued/) in the future (see issue #5527). At the moment I have left the constants in `{float|f32|f64}::consts` in case folks need to access these at compile time. There are also instances of `int` in `Real` and `RealExt`. In the future these could be replaced with an associated `INTEGER` type on `Real`.

`Natural` has also been renamed to `Integer`. This is because `Natural` normally means 'positive integer' in mathematics. It is therefore strange to implement it on signed integer types. `Integer` is probably a better choice.

I have also switched some of the `Integer` methods to take borrowed pointers as arguments. This brings them in line with the `Quot` and `Rem` traits, and is be better for large Integer types like `BigInt` and `BigUint` because they don't need to be copied unnecessarily.

There has also been considerable discussion on the mailing list and IRC about the renaming of the `Div` and `Modulo` traits to `Quot` and `Rem`. Depending on the outcome of these discussions they might be renamed again.
2013-04-25 11:36:36 -07:00
Marvin Löbel
e1be9ae224 Made fail! and assert! accept both &'static str and ~str, as well as a fmt! like format list.
Unwinding through macros now happens as a call to the trait function `FailWithCause::fail_with()`, which consumes self, allowing to use a more generic failure object in the future.
2013-04-25 17:32:25 +02:00
Huon Wilson
106fd12423 rt: pull upstream ISAAC code for consistency between 32/64 bit platforms
The "unsigned 4 byte" `ub4`s are actually 8 bytes on 64-bit platforms
which mean that some bits > 2**32 were retained in calculations, these
would then "reappear" after a shift and so the stream of random numbers
would differ on 32 bit vs 64 bit platforms.
2013-04-25 17:59:42 +10:00
Corey Richardson
d53e686f4f Rename vec::mod2 to vec::mod_zip 2013-04-25 01:38:44 -04:00
Corey Richardson
91fb7b282d Move documentation for vec::windowed where it will be generated 2013-04-24 22:33:48 -04:00
Corey Richardson
92bf9b68da Add basic documentation for with_capacity 2013-04-24 22:33:13 -04:00
Brendan Zabarauskas
225ac21615 Update impl of Round for Ratio 2013-04-25 11:53:51 +10:00
Brendan Zabarauskas
48c24188f9 Restore Round trait and move appropriate methods out of Real 2013-04-25 11:53:04 +10:00
bors
1d53babd2f auto merge of #6051 : thestinger/rust/iterator, r=catamorphism,pcwalton 2013-04-24 18:36:30 -07:00
Tim Chevalier
4e2c8f422a rustpkg: Preliminary work on install command
Mostly just tests (that are ignored); install command is still
stubbed out.
2013-04-24 17:51:31 -07:00
Tim Chevalier
f945e57bd0 rustpkg: Correct directory structure in test scenarios 2013-04-24 17:51:31 -07:00