Commit Graph

570 Commits

Author SHA1 Message Date
Josh Stone 9ec4106a99 Merge pull request #154 from briansmith/optional-rand-rustc_serialize
Make `rand` and `rustc-serialize` dependencies optional.
2016-01-08 09:52:51 -08:00
Brian Smith 9e3e8552ac Make `rand` and `rustc-serialize` dependencies optional.
Previously, the `rand` and `rustc-serialize` dependencies were optional
except they were required for the `bigint` feature.

Make the dependency on the `rand` crate optional in all cases.
including when the `bigint` feature is selected. Some of the tests for
the bigint feature are randomized so, while `rand` is now an optional
dependency, it is a non-optional dev-dependency.

Similarly, make the dependency on the `rustc-serialize` crate optional
in all cases, including when the `bigint` feature is selected.
2016-01-07 16:30:50 -10:00
Josh Stone 22722ac55d pow: shift exp powers of 2 before accumulating
We can save a multiplication if we start the accumulation basically at
the first set bit of the exponent, rather than starting at one and
waiting to multiply.  We only need one itself if the exponent is zero,
which is easy to pre-check.

Before:
    test pow_bench         ... bench:   8,267,370 ns/iter (+/- 93,319)

After:
    test pow_bench         ... bench:   7,506,463 ns/iter (+/- 116,311)
2016-01-06 18:32:01 -08:00
Josh Stone e8d948a3d2 Reduce the size of the BigUint pow benchmark
If a benchmark takes very long to run, it's harder to iterate on changes
to see their effect.  Even reduced to 100, this pow_bench takes around 8
seconds on my machine, and still shows meaningful optimization effects.
2016-01-06 18:32:01 -08:00
David Hewson 71b2e0627c Benchmark pow on BigUint (from #152) 2016-01-06 18:32:01 -08:00
Oliver Middleton d2b23d0f29 bigint: small to_str_radix optimization
Before:

test fac_to_string     ... bench:       1,630 ns/iter (+/- 34)
test fib_to_string     ... bench:         359 ns/iter (+/- 11)
test to_str_radix_02   ... bench:       3,097 ns/iter (+/- 19)
test to_str_radix_08   ... bench:       1,146 ns/iter (+/- 38)
test to_str_radix_10   ... bench:       4,248 ns/iter (+/- 36)
test to_str_radix_16   ... bench:         881 ns/iter (+/- 44)
test to_str_radix_36   ... bench:       8,073 ns/iter (+/- 75)

After:

test fac_to_string     ... bench:       1,492 ns/iter (+/- 20)
test fib_to_string     ... bench:         368 ns/iter (+/- 7)
test to_str_radix_02   ... bench:       2,038 ns/iter (+/- 47)
test to_str_radix_08   ... bench:         812 ns/iter (+/- 9)
test to_str_radix_10   ... bench:       3,919 ns/iter (+/- 40)
test to_str_radix_16   ... bench:         703 ns/iter (+/- 58)
test to_str_radix_36   ... bench:       7,852 ns/iter (+/- 81)
2016-01-05 18:01:12 +00:00
Homu fe513cc079 Auto merge of #149 - rust-num:i-complex-constant, r=cuviper
Add complex `i` constant function

None
2015-12-31 04:04:45 +09:00
Łukasz Jan Niemier 8e267ee4cb Fix docs and function position 2015-12-30 10:57:54 +01:00
Łukasz Jan Niemier 458e9594d4 Add complex `i` constant function 2015-12-29 16:36:08 +01:00
Homu 661e225862 Auto merge of #145 - ollie27:bigint_float, r=cuviper
bigint: fix float conversions

The default implementations of to_f32, to_f64, from_32 and from_f64 are
limited to numbers fitting in i64 but BigInt can of course be much bigger.
The default to_f32 also has double rounding.
from_f32 and from_f64 have undefined behaviour if the float is too big to
fit in an i64.

This fixes these issues and keeps the rounding consistant with other float
to int conversions.

Also add ToBigUint and ToBigInt implementations for f32 and f64.

Currently this returns None if the BigInt is too big for to_f32 and to_f64 but it might make more sense to return Some(INFINITY) but I've decided to match f64::to_f32() for now.
2015-12-28 06:57:52 +09:00
Oliver Middleton 2c235d2dde bigint: cleanup float conversions 2015-12-24 18:15:56 +00:00
Oliver Middleton a480c7ca6c bigint: fix float conversions
The default implementations of to_f32, to_f64, from_32 and from_f64 are
limited to numbers fitting in i64 but BigInt can of course be much bigger.
The default to_f32 also has double rounding.
from_f32 and from_f64 have undefined behaviour if the float is too big to
fit in an i64.

This fixes these issues and keeps the rounding consistant with other float
to int conversions.

Also add ToBigUint and ToBigInt implementations for f32 and f64.
2015-12-23 07:30:40 +00:00
Homu 283a2e192d Auto merge of #144 - bluss:syntax-ext, r=cuviper
Fix num_macros for syntax/syntax_ext crate split
2015-12-22 05:35:51 +09:00
Josh Stone ddc0b1ce0e Add a simple multirust script for local "CI" 2015-12-21 12:26:32 -08:00
Josh Stone 2e3e575117 Fix the feature masks in the approx_sqrt doc example
The hidden "mod test" layout of the first example has been broken for a
while, but it wasn't noticed because rustdoc wasn't passing any features
at all.  That was fixed in rust-lang/rust#30372, and now we need to get
our ducks in a row too.
2015-12-21 12:21:47 -08:00
bluss 4d237003ec Fix num_macros for syntax/syntax_ext crate split 2015-12-19 10:57:26 +01:00
Josh Stone 477cbc87c9 Publish num 0.1.29 2015-12-16 22:48:45 -08:00
Josh Stone b84142fc28 bigint: add a Hash test 2015-12-16 22:32:00 -08:00
Homu 9b45e6dd9b Auto merge of #139 - ollie27:bigint_hash, r=cuviper
bigint: simplify Hash

There cannot be any leading zeros in a BigUint so just derive Hash which will just hash the Vec directly.
Add Hash to Sign so we can derive it for BigInt as well.
2015-12-17 15:25:49 +09:00
Josh Stone 7593c17fa7 More bigint str_radix performance tweaks 2015-12-16 21:49:18 -08:00
Oliver Middleton e152bbcb46 bigint: simplify Hash
There cannot be any leading zeros in a BigUint so just derive Hash which will just hash the Vec directly.
Add Hash to Sign so we can derive it for BigInt as well.
2015-12-16 19:08:24 +00:00
Josh Stone c9e15aef2d bigint: use full cmp results for checked_sub 2015-12-15 22:31:46 -08:00
Josh Stone 4a8752274c bigint: slightly improve multiply/divide performance
Using `vec![0; len]` initialization is a little faster.

Before:
     test multiply_0        ... bench:         354 ns/iter (+/- 6)
     test multiply_1        ... bench:      33,966 ns/iter (+/- 1,508)
     test multiply_2        ... bench:   3,663,686 ns/iter (+/- 60,880)
     test divide_0          ... bench:         891 ns/iter (+/- 51)
     test divide_1          ... bench:      17,316 ns/iter (+/- 387)
     test divide_2          ... bench:   1,290,378 ns/iter (+/- 73,016)

After:
     test multiply_0        ... bench:         351 ns/iter (+/- 39)
     test multiply_1        ... bench:      30,827 ns/iter (+/- 680)
     test multiply_2        ... bench:   3,692,968 ns/iter (+/- 91,146)
     test divide_0          ... bench:         902 ns/iter (+/- 14)
     test divide_1          ... bench:      16,981 ns/iter (+/- 102)
     test divide_2          ... bench:   1,146,367 ns/iter (+/- 60,152)
2015-12-15 22:07:34 -08:00
Josh Stone b7724a6650 Simplify BigInt Mul forwarding 2015-12-15 22:06:59 -08:00
Josh Stone 22ff3f918d bigint: improve from_str_radix performance
Before:
    test from_str_radix_02 ... bench:       8,432 ns/iter (+/- 280)
    test from_str_radix_08 ... bench:       7,397 ns/iter (+/- 95)
    test from_str_radix_10 ... bench:       7,344 ns/iter (+/- 142)
    test from_str_radix_16 ... bench:       6,753 ns/iter (+/- 157)
    test from_str_radix_36 ... bench:       7,093 ns/iter (+/- 60)

After:
    test from_str_radix_02 ... bench:       3,295 ns/iter (+/- 81)
    test from_str_radix_08 ... bench:       1,377 ns/iter (+/- 56)
    test from_str_radix_10 ... bench:       1,583 ns/iter (+/- 16)
    test from_str_radix_16 ... bench:       1,483 ns/iter (+/- 53)
    test from_str_radix_36 ... bench:       1,628 ns/iter (+/- 27)
2015-12-15 21:59:51 -08:00
Josh Stone 49529895a2 bigint: greatly improve to_str_radix performance
Before:
     test fac_to_string     ... bench:      18,183 ns/iter (+/- 310)
     test fib_to_string     ... bench:         819 ns/iter (+/- 8)
     test to_str_radix_02   ... bench:     204,479 ns/iter (+/- 2,826)
     test to_str_radix_08   ... bench:      68,275 ns/iter (+/- 769)
     test to_str_radix_10   ... bench:      61,809 ns/iter (+/- 907)
     test to_str_radix_16   ... bench:      51,438 ns/iter (+/- 539)
     test to_str_radix_36   ... bench:      39,939 ns/iter (+/- 976)

After:
     test fac_to_string     ... bench:       1,204 ns/iter (+/- 16)
     test fib_to_string     ... bench:         269 ns/iter (+/- 3)
     test to_str_radix_02   ... bench:       2,428 ns/iter (+/- 80)
     test to_str_radix_08   ... bench:         820 ns/iter (+/- 38)
     test to_str_radix_10   ... bench:       2,984 ns/iter (+/- 303)
     test to_str_radix_16   ... bench:         689 ns/iter (+/- 25)
     test to_str_radix_36   ... bench:       7,995 ns/iter (+/- 100)
2015-12-15 21:57:27 -08:00
Josh Stone 84542e6e03 Add benchmarks for bigint to/from_str_radix 2015-12-15 21:31:05 -08:00
Homu f8351af572 Auto merge of #138 - ollie27:bigint_from, r=cuviper
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-14 07:25:56 +09:00
Oliver Middleton 9c7c995631 bigint: add tests for From implementations 2015-12-12 23:17:37 +00:00
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