about summary refs log tree commit diff
path: root/src/libstd/num
AgeCommit message (Collapse)AuthorLines
2014-01-25Uppercase numeric constantsChris Wong-272/+272
The following are renamed: * `min_value` => `MIN` * `max_value` => `MAX` * `bits` => `BITS` * `bytes` => `BYTES` Fixes #10010.
2014-01-22Remove the initial and trailing blank doc-comment linesSiegeLord-80/+0
2014-01-22Add LowerExp 'e' and UpperExp 'E' format traits/specifiersSiegeLord-0/+68
2014-01-22float_to_str_bytes_common can now handle exponential notationSiegeLord-17/+77
2014-01-21[std::str] Rename from_utf8_owned_opt() to from_utf8_owned(), drop the old ↵Simon Sapin-1/+1
from_utf8_owned() behavior
2014-01-21[std::vec] Rename .pop_opt() to .pop(), drop the old .pop() behaviorSimon Sapin-1/+1
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-43/+7
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-84/+31
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-18Add FIXME comments regarding issue #11526.Brendan Zabarauskas-0/+22
2014-01-18Simplify std::num::Primitive trait definitionBrendan Zabarauskas-84/+9
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-40/+68
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-15auto merge of #11548 : bjz/rust/bitwise, r=alexcrichtonbors-37/+38
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-37/+38
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-2/+2
2014-01-13Clean up std::num::cmath and remove stale commentsBrendan Zabarauskas-186/+79
2014-01-13Remove RealExtBrendan Zabarauskas-49/+1
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-272/+232
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-106/+23
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-272/+232
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-07Fix remaining cases of leaking importsAlex Crichton-0/+2
2014-01-07std: Fill in all missing importsAlex Crichton-1/+1
Fallout from the previous commits
2014-01-06Remove some unnecessary type castsFlorian Hahn-1/+1
Conflicts: src/librustc/middle/lint.rs
2014-01-03libstd: Remove all support code related to `@mut`Patrick Walton-5/+0
2013-12-27std: uniform modules titles for docLuca Bruno-13/+15
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-13/+18
2013-12-15std: fix spelling in docs.Huon Wilson-2/+2
2013-12-14Dead-code pass now marks and warns foreign itemsKiet Tran-0/+1
2013-12-08Remove dead codesKiet Tran-17/+17
2013-12-05Fix documentation typo (divison operator is not backslash)Alexandros Tasos-2/+2
2013-12-04auto merge of #10803 : vmx/rust/integer-decode, r=cmrbors-0/+60
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 I got the permission to use this code for Rust from Peter Graves (the ABCL copyright holder) . If there's any further IP clearance needed, let me know.
2013-12-04Decode a float into integersVolker Mische-0/+60
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-12-04std::str: remove from_utf8.Huon Wilson-1/+1
This function had type &[u8] -> ~str, i.e. it allocates a string internally, even though the non-allocating version that take &[u8] -> &str and ~[u8] -> ~str are all that is necessary in most circumstances.
2013-11-29Removed module macro workaround for signed and unsigned integersMarvin Löbel-57/+93
2013-11-29Removed useless cmp::{min, max} reexports from the integer modulesMarvin Löbel-4/+0
2013-11-29Removed a few macro-expanding-to-module workaroundsMarvin Löbel-42/+32
Also documented a few issues
2013-11-26libstd: Fix Win32 and other bustage.Patrick Walton-3/+3
2013-11-26test: Remove non-procedure uses of `do` from compiletest, libstd tests,Patrick Walton-5/+5
compile-fail tests, run-fail tests, and run-pass tests.
2013-11-26libstd: Remove all non-`proc` uses of `do` from libstdPatrick Walton-8/+8
2013-11-19libstd: Change all uses of `&fn(A)->B` over to `|A|->B` in libstdPatrick Walton-7/+17
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-11Remove #[fixed_stack_segment] and #[rust_stack]Alex Crichton-2/+2
These two attributes are no longer useful now that Rust has decided to leave segmented stacks behind. It is assumed that the rust task's stack is always large enough to make an FFI call (due to the stack being very large). There's always the case of stack overflow, however, to consider. This does not change the behavior of stack overflow in Rust. This is still normally triggered by the __morestack function and aborts the whole process. C stack overflow will continue to corrupt the stack, however (as it did before this commit as well). The future improvement of a guard page at the end of every rust stack is still unimplemented and is intended to be the mechanism through which we attempt to detect C stack overflow. Closes #8822 Closes #10155
2013-11-03Rename files to match current recommendations.Chris Morgan-0/+0
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.
2013-10-30auto merge of #9613 : jld/rust/enum-discrim-size.r0, r=alexcrichtonbors-1/+2
Allows an enum with a discriminant to use any of the primitive integer types to store it. By default the smallest usable type is chosen, but this can be overridden with an attribute: `#[repr(int)]` etc., or `#[repr(C)]` to match the target's C ABI for the equivalent C enum. Also adds a lint pass for using non-FFI safe enums in extern declarations, checks that specified discriminants can be stored in the specified type if any, and fixes assorted code that was assuming int.
2013-10-29Work around const_eval issues by changing signed integer `min_value`s.Jed Davis-1/+2
Otherwise, run-pass/deriving-primitive.rs breaks on 32-bit platforms, because `int::min_value` is `0xffffffff7fffffff` when evaluated for the discriminant declaration.