Commit Graph

116 Commits

Author SHA1 Message Date
Josh Stone e41016975f bigint: expand op tests to cover all val/ref combinations 2015-11-16 11:06:39 -08:00
Josh Stone 978d14aa56 bigint: refactor BigInt ops
Try to let the underlying BigUint op implement val/ref forwarding as
much as possible, to reduce cloning.
2015-11-16 11:04:41 -08:00
Josh Stone ce3d375b21 bigint: refactor BigUint ops
As much as possible, ops are forwarded to val-ref so the LHS memory can
be reused for the result.  This reduces the number of clones required.
2015-11-16 10:56:30 -08:00
Josh Stone 7781256041 bigint: use a simple let-Some-pop to truncate zeros 2015-11-16 10:20:42 -08:00
Josh Stone c310e5da8e complex: forward ops to val-val
Since the Num constraint only requires val-val ops, we ended up cloning
everything in Complex ops when they were forwarded to ref-ref.  By using
val-val, we can reduce how often clones are needed.
2015-11-16 10:10:59 -08:00
Josh Stone b4026b9fec Update repo and doc links 2015-11-12 18:40:13 -08:00
Homu 93db3998ef Auto merge of #131 - murarth:str-radix, r=cuviper
Improve `to_str_radix` implementation
2015-11-12 03:33:55 +09:00
Homu 879f2c868e Auto merge of #125 - IvanUkhov:real-arithmetic, r=cuviper
Implement arithmetic with real for complex

Hello,

It might be handy to be able to perform basic arithmetic operations in expressions mixing complex numbers and numeric primitives; see #116. I would be grateful for any feedback, especially regarding the subsets of primitives for which certain operations are implemented.

Regards,
Ivan
2015-11-12 03:03:06 +09:00
Murarth 786541bd24 Improve `to_str_radix` implementation
Uses in-place division with `u32` divisor to provide a significant speed
improvement.
2015-11-09 13:50:25 -07:00
Abhishek Chanda 7acad5ac33 Implement some more functions for the complex type 2015-11-05 14:20:37 -08:00
Ivan Ukhov b57e4a4db4 Implement arithmetic with real for complex 2015-10-31 06:38:38 +01:00
Abhishek Chanda e5099930e7 Implement is_nan for the complex type
Also run the associated test
2015-10-30 15:35:04 -07:00
Josh Stone 49237f6f45 integer: expand tests for gcd min_value()
- Use explicit asserts for should-panic tests, since overflow is not
  checked in release mode.
- Add positive tests where gcd min_value() can be represented.
- In all cases, test min_value() in both positions.

Closes #127
2015-10-30 00:40:21 -07:00
Josh Stone 642787fbd2 Merge pull request #121 from wrieger93/issue_120
Add a function that returns the sign of a BigInt.
2015-10-27 12:13:17 -07:00
Josh Stone 9e5a209dcd Merge pull request #123 from murarth/ratio-parse-fix
Check for zero denominator when parsing Ratio
2015-10-23 10:23:18 -07:00
David Ripton e86913924e Remove extra parentheses to fix a warning
Removing extra parentheses in a for loop fixes this warning:

src/bigint.rs:1636:18: 1636:31 warning: unnecessary parentheses around `for` head expression, #[warn(unused_parens)] on by default
2015-10-19 09:43:47 -04:00
Murarth b2767517f4 Check for zero denominator when parsing Ratio
Closes #122
2015-10-16 13:10:16 -07:00
Łukasz Niemier 2e4afbc9ba Merge pull request #112 from Emerentius/master
Implement Stein's algorithm for gcd
2015-10-15 13:25:33 +02:00
William Rieger 1eb3deaca8 Add a function that returns the sign of a BigInt. 2015-10-06 00:32:32 -07:00
William Rieger c715405b30 Add functions and tests. 2015-09-13 18:19:00 -04:00
Emerentius 499def9207 Added tests for gcd
compare gcd with euclidean gcd
test panics on gcd(min_val, min_val) and gcd(min_val, 0) for signed integers
2015-09-11 20:33:39 +02:00
Emerentius 59089d9d5c Made it panic on gcd = min_val in debug mode
The additional call to .abs() causes a panic on the min value. There are
no other negative values it can encounter.
Does nothing in release mode
2015-09-11 20:27:06 +02:00
Emerentius 82a6ab2f30 comment corrected
referenced a,b, which aren't defined
changed to n,m
2015-09-07 16:50:58 +02:00
Emerentius e892054813 implement Stein's algorithm for gcd 2015-09-07 03:15:16 +02:00
William Rieger 50d89519a2 Merge branch 'master' into develop
Conflicts:
	src/complex.rs
2015-09-04 18:56:40 -04:00
William Rieger ff6a40cc88 Remove reduntant Num trait from an impl. 2015-09-04 17:48:31 -04:00
William Rieger 98b9df622f Add mathematical functions for complex numbers.
For Complex<T: Clone + Float>, the following functions along with
corresponding tests were added:
- exp
- sin, cos, tan
- sinh, cosh, tanh
2015-09-04 02:08:31 -04:00
Gustorn 3ccb4bd6c5 Added Sized trait bound for traits that requite it
See rust-lang/rfcs#1214
2015-08-19 19:11:55 +02:00
Alex Crichton b57accf314 Update to rust nightly 2015-08-10 12:11:56 -07:00
root 4c123a9e71 Make rustc-serialize, bignum, rational, complex into opt-out features
Making bignum optional allows skipping the rustc-serialize and rand
dependencies too, and it makes a big difference in num's build time.

With default (all) features, clean build time including dependencies: 27
seconds.

With no default features, clean build time including dependencies (none):
5 seconds.
2015-06-02 23:48:06 +02:00
Alex Crichton 0a7847cd65 Merge pull request #99 from b52/issue-93-float-min-positive
Provide generic around f32/f64::MIN_POSITIVE
2015-05-26 07:23:41 -07:00
Oliver Mader 785e07d83c Re-export `cast` for ergonomic reasons 2015-05-26 15:03:34 +02:00
Oliver Mader 6c9f457712 Provide generic around f32/f64::MIN_POSITIVE 2015-05-26 14:56:43 +02:00
Alex Crichton a6a399d52e Enable testing on stable Rust 2015-05-19 09:22:06 -07:00
runarberg 505eb86c18 Added the power method for rational numbers 2015-05-17 18:22:32 +00:00
Josh Triplett 6f2db9b631 Factor out more generic macro to run a macro on each tuple type 2015-04-25 17:03:05 -07:00
Josh Triplett c6163dac40 traits.rs: Implement Bounded for tuples of Bounded types
For example, the following will print (4294967295, 65535):

extern crate num;
use num::traits::Bounded;

fn main() {
    let t : (u32, u16) = Bounded::max_value();
    println!("{:?}", t);
}
2015-04-25 16:50:03 -07:00
mitchmindtree 63d2e79c1e Added temporary fix for unstable std from_str_radix method 2015-04-24 15:17:42 +10:00
mitchmindtree 3028d602e6 Fixed issue where unstable version of from_str_radix was being called instead of the local Num trait version 2015-04-24 04:57:37 +10:00
mitchmindtree f0af39dfae Removed deprecation attributes that can no longer be used outside of std 2015-04-22 22:27:20 +10:00
Nick Hamann 82aa7c7864 Improve bigint docs.
Convert instances of <string literal>.as_bytes() to byte string
literals. Also, add examples for from_bytes_le() and to_bytes_be().
2015-04-15 14:46:07 -05:00
kennytm fd86a2c531 Make sure PrimInt is actually implemented for the primitive types. 2015-04-05 03:10:40 +08:00
kennytm 24d2f15ccf Avoid and remove some unstable features.
The only #[feature] left for now is the bencher.
2015-04-05 03:09:29 +08:00
Anders Kaseorg 7fb887bffc Require Neg for Complex conj and inv
If T is an unsigned integer type, these methods are guaranteed to
overflow unless the result is actually real, so we should disallow
them for the same reason that Neg was removed from these types.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2015-04-03 15:10:44 -04:00
Alex Crichton 996128bd4b Fix some doc tests 2015-04-03 10:26:37 -07:00
Aaron Turon 63c7a25ed9 Update to 1.0.0-beta (stable only)
Along the way, this commit also rationalizes the traits a bit more.

Moving to stable required vendoring a couple of minor things (notably,
radix formatting).
2015-04-03 10:17:39 -07:00
Aaron Turon 03db5c9d1b Vendor deprecated/unstable traits from std::num
This commit brings in a load of unstable and/or deprecated traits from
the `std::num` module. These traits provide for some degree of generic
programming over numeric types. They are not stable in `std` mostly
because we want more time to iterate on their design. Moving them to the
`num` crate allows existing code to keep using this functionality as we
do so.

Closes #74
2015-04-02 20:04:38 -07:00
Alex Crichton fcd3760625 Get tests passing again 2015-04-02 09:37:32 -07:00
Anders Kaseorg a00fe8b700 Replace FromError with From
As per https://github.com/rust-lang/rust/pull/23879.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2015-04-02 06:37:57 -04:00
Alex Crichton 1841c8ace4 Update to rust master 2015-03-29 10:05:02 -07:00