Commit Graph

295 Commits

Author SHA1 Message Date
Josh Stone 7a33808b07 Publish num 0.1.31 2016-02-17 00:44:20 -08:00
Josh Stone ebed6756de impl Debug for ParseFloatError
Fixes #165.
2016-02-16 15:37:06 -08:00
Homu 1a15d33560 Auto merge of #163 - gmorenz:update_nightly, r=hauleth
Update num_macros to current nightly

Fixes num_macros build for current nightly, broken by [this](https://github.com/rust-lang/rust/pull/31487/files) PR on rust.
2016-02-16 07:44:46 +09:00
Greg Morenz 4c379ff4c7 Update ast::BiEq to BinOpKind::Eq 2016-02-15 16:44:51 -05:00
Josh Stone 9b2116d78f Fix spelling of "occurred". 2016-02-05 16:04:34 -08:00
Homu d1adf45389 Auto merge of #162 - est31:add_checked_pow, r=cuviper
Add checked_pow function

Implements a `checked_pow` function which does the same as `pow`, just with overflow checks.

And, similar to #152 and #153, the function uses references instead of cloning.

Adds a little macro to spare code repetition. Its scoped to the function so nothing gets polluted.
2016-02-06 09:01:32 +09:00
est31 3c5ecdc636 Add checked_pow function 2016-02-03 06:43:40 +01:00
Homu e074e865ae Auto merge of #161 - cuviper:shifty-ints, r=hauleth
Add signed/unsigned shifts to PrimInt

None
2016-01-29 19:37:34 +09:00
Josh Stone afee4e4662 Change PrimInt shift names to signed/unsigned 2016-01-28 22:37:18 -08:00
Josh Stone d798bd4fb8 Add arithmetic/logical shifts to PrimInt 2016-01-27 23:30:33 -08:00
Josh Stone b454a14bc4 bigint: avoid new allocations for small shifts
Before:
    test shl               ... bench:       7,312 ns/iter (+/- 218)
    test shr               ... bench:       5,282 ns/iter (+/- 243)

After:
    test shl               ... bench:       4,946 ns/iter (+/- 88)
    test shr               ... bench:       4,121 ns/iter (+/- 52)
2016-01-27 23:08:47 -08:00
Josh Stone 1ebcc77513 Expand bigint shl/shr benchmarking 2016-01-27 22:53:10 -08:00
Homu 494fce7dd3 Auto merge of #160 - ollie27:bigint_more_fmt, r=cuviper
bigint: Improve fmt traits

* Make them take into account formatting parameters.
* ~~Make Debug match Display.~~
2016-01-21 18:06:03 -08:00
Oliver Middleton 95d8ccdb24 bigint: Make fmt traits take into account formatting parameters 2016-01-22 00:35:35 +00:00
Homu 516587ce2e Auto merge of #159 - anchovieshat:master, r=cuviper
Add Binary, Octal to BigUint. Add UpperHex, LowerHex, Binary, Octal to BigInt

Is the testing for these enough? Any suggestions to improve them?
2016-01-18 23:27:35 -08:00
Colin Davidson 3c7441ab0a Add Binary, Octal to BigUint. Add UpperHex, LowerHex, Binary, Octal to BigInt 2016-01-18 21:19:21 -08:00
Homu e3bc794ca4 Auto merge of #158 - anchovieshat:master, r=cuviper
Add LowerHex and UpperHex formatting

These were mysteriously missing from BigUint.
2016-01-18 10:47:39 -08:00
Colin Davidson a89a2e82e6 Fix test names
Upper and Lower test names were swapped
2016-01-17 12:17:52 -08:00
Colin Davidson d5d7c855b0 Add tests for UpperHex and LowerHex 2016-01-17 12:13:45 -08:00
Colin Davidson 04000436b1 Switch to ascii uppercase function 2016-01-16 22:27:56 -08:00
Colin Davidson 80c4d01b7f Add LowerHex and UpperHex formatting 2016-01-16 21:52:47 -08:00
Homu 010f562a62 Auto merge of #157 - durka:patch-1, r=hauleth
remove stale #[deriving(Zero)] docs

Fixes #156.
2016-01-15 10:30:29 -08:00
Alex Burka 5962dd29c9 remove stale #[deriving(Zero)] docs
Fixes #156.
2016-01-15 13:29:34 -05:00
Homu e65fd4e5b2 Auto merge of #150 - ollie27:bigint_to_str, r=cuviper
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-13 08:59:01 +09:00
Josh Stone 838b4e42b3 Publish num 0.1.30 2016-01-08 15:22:54 -08:00
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