Commit Graph

241 Commits

Author SHA1 Message Date
Oliver Middleton 8e1c6a3c11 bigint: add From implementations
From all primative unsigned ints to BigUint
From all primative ints to BigInt
From BigUint to BigInt

Closes: #117
2015-12-12 23:16:03 +00:00
Homu f2ea30d9f4 Auto merge of #133 - koverstreet:master, r=cuviper
[RFC] Some performance improvements

I added add and subtract methods that take an operand by value, instead of by reference, so they can work in place instead of always allocating new BigInts for the result.

I'd like to hear if anyone knows a better way of doing this, though - with the various wrappers/forwardings doing this for all the operations is going to be a mess and add a ton of boilerplate. I haven't even tried to do a complete job of it yet.

I'm starting to think the sanest thing to do would be to only have in place implements of most of the operations - and have the wrappers clone() if necessary. That way, the only extra work we're doing is a memcpy(), which is a hell of a lot faster than a heap allocation.
2015-12-11 10:13:09 +09:00
Kent Overstreet fa372e230b Multiply/divide torture test 2015-12-10 15:28:01 -09:00
Kent Overstreet 79928b3185 Improve division performance
Before:
test divide_0      ... bench:       4,058 ns/iter (+/- 255)
test divide_1      ... bench:     304,507 ns/iter (+/- 28,063)
test divide_2      ... bench: 668,293,969 ns/iter (+/- 25,383,239)

After:
test divide_0      ... bench:         874 ns/iter (+/- 71)
test divide_1      ... bench:      16,641 ns/iter (+/- 1,205)
test divide_2      ... bench:   1,336,888 ns/iter (+/- 77,450)
2015-12-10 15:25:56 -09:00
Kent Overstreet 08b0022aab Improve multiply performance
The main idea here is to do as much as possible with slices, instead of
allocating new BigUints (= heap allocations).

Current performance:

multiply_0:	10,507 ns/iter (+/- 987)
multiply_1:	2,788,734 ns/iter (+/- 100,079)
multiply_2:	69,923,515 ns/iter (+/- 4,550,902)

After this patch, we get:

multiply_0:	364 ns/iter (+/- 62)
multiply_1:	34,085 ns/iter (+/- 1,179)
multiply_2:	3,753,883 ns/iter (+/- 46,876)
2015-12-10 15:25:42 -09:00
Kent Overstreet 496ae0337c Add add/subtract functions that work in place, on slices
This is needed for the multiply optimizations in the next patch.
2015-12-10 12:33:28 -09:00
Kent Overstreet a1e57a48b2 Add multiplication/division benchmarks
Add benchmarks that test multiplies/divides of different sizes
2015-12-10 12:22:54 -09:00
Kent Overstreet dbd22cfdd8 fix some annoying build warnings 2015-12-10 12:22:54 -09:00
Josh Stone a228385394 num-macros: rustc::plugin -> rustc_plugin
Ref: rust-lang/rust@1430a35000
2015-12-01 17:40:51 -08:00
Josh Stone 659c1a73c3 Publish num 0.1.28 2015-11-21 17:00:15 -08:00
Josh Stone 7fa80f7786 Update intros to better reflect the breadth of num
Closes #132.
2015-11-21 16:39:00 -08:00
Josh Stone 4003fd265b Fix travis on non-nightly
*sigh* sorry for the churn... *fingers crossed*
2015-11-18 22:12:19 -08:00
Josh Stone 03995288d2 fix the new travis nightly line 2015-11-18 21:50:23 -08:00
Josh Stone 658637dcba Use scripts for compound travis commands 2015-11-18 21:33:07 -08:00
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
Josh Stone 327ef3bc92 Start an ssh-agent in travis 2015-11-12 18:30:44 -08:00
Josh Stone 60535e6e60 Fix the path to .travis/deploy 2015-11-12 18:20:03 -08:00
Josh Stone e522b5e363 Update gh-pages from travis 2015-11-12 18:12:28 -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
Homu 43bd642da5 Auto merge of #128 - achanda:cfuncs, r=cuviper
Implement some more functions for the complex type
2015-11-12 02:45:08 +09:00
Murarth d1df121640 Explicitly enable `bigint` benchmarks 2015-11-09 13:54:48 -07: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
Homu d9b72a3366 Auto merge of #114 - achanda:is_nan, r=hauleth
Implement is_nan for the complex type

Also run the associated test
2015-10-31 07:57:55 +09: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 28209688ab num-macros: VariantData no longer needs to be dereferenced 2015-10-27 11:51:35 -07:00
Josh Stone fe99867590 num-macros: port from ast::VariantKind to ast::VariantData 2015-10-23 10:49:01 -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
Josh Stone 1666d1bb04 Merge pull request #124 from dripton/master
Remove extra parentheses to fix a warning
2015-10-19 09:57:40 -07:00
David Ripton f53f62737c Merge pull request #1 from dripton/dripton-extra-parens
Remove extra parentheses to fix a warning
2015-10-19 09:48:53 -04: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
Łukasz Niemier a786adb874 Merge pull request #115 from wrieger93/complex_functions
Add mathematical functions for complex numbers.
2015-10-15 13:24:39 +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