Skip to content

Commit 17cabf9

Browse files
committed
Release v0.2.1
2 parents fc797c3 + 6a5189f commit 17cabf9

File tree

9 files changed

+248
-111
lines changed

9 files changed

+248
-111
lines changed

.circleci/config.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
version: 2.1
2+
orbs:
3+
# codecov: codecov/[email protected]
4+
rust: circleci/[email protected]
5+
6+
jobs:
7+
build-and-test:
8+
parameters:
9+
rust-version:
10+
type: string
11+
debian-version:
12+
type: string
13+
default: "buster"
14+
docker:
15+
- image: rust:<< parameters.rust-version >>-<< parameters.debian-version >>
16+
environment:
17+
RUSTFLAGS: '-D warnings'
18+
steps:
19+
- checkout
20+
- run:
21+
name: Rust Version
22+
command: rustc --version; cargo --version
23+
- restore_cache:
24+
keys:
25+
- bigdecimal-cargo-<< parameters.rust-version >>-{{ checksum "Cargo.toml" }}
26+
- bigdecimal-cargo-
27+
- run:
28+
name: Check
29+
command: cargo check
30+
- save_cache:
31+
paths:
32+
- /usr/local/cargo
33+
key: bigdecimal-cargo-<< parameters.rust-version >>-{{ checksum "Cargo.toml" }}
34+
- run:
35+
name: Build
36+
command: cargo build
37+
- run:
38+
name: Test
39+
command: cargo test
40+
41+
upload-coverage:
42+
parameters:
43+
rust-version:
44+
type: string
45+
debian-version:
46+
type: string
47+
default: "buster"
48+
machine: true
49+
steps:
50+
- checkout
51+
- run:
52+
name: Generate Coverage
53+
command: >
54+
docker run
55+
--security-opt seccomp=unconfined
56+
-v "${PWD}:/home"
57+
-e CI=true
58+
$(bash <(curl -s https://codecov.io/env))
59+
akubera/rust-codecov:<< parameters.rust-version >>-<< parameters.debian-version >>
60+
sh -c 'cargo test -q && kcov-rust && upload-kcov-results-to-codecov'
61+
- store_artifacts:
62+
path: target/cov
63+
- store_test_results:
64+
path: target/cov
65+
66+
lint-check:
67+
docker:
68+
- image: cimg/rust:1.54.0
69+
steps:
70+
- checkout
71+
- rust/build
72+
- rust/format
73+
- rust/clippy
74+
- rust/test
75+
- run:
76+
name: Build examples
77+
command: cargo build --examples
78+
79+
workflows:
80+
version: 2
81+
build-and-test:
82+
jobs:
83+
- build-and-test:
84+
name: build-and-test-1.34.0
85+
rust-version: "1.34.0"
86+
debian-version: "stretch"
87+
- build-and-test:
88+
matrix:
89+
parameters:
90+
rust-version:
91+
- "1.40.0"
92+
- "1.50.0"
93+
- "1.54.0"
94+
- upload-coverage:
95+
rust-version: "1.54.0"
96+
requires:
97+
- build-and-test-1.54.0
98+
- lint-check

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ target
33

44
.vscode/
55

6+
.*cache/

.rustfmt.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
reorder_imports = false
3+
max_width = 120

.travis.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bigdecimal"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
authors = ["Andrew Kubera"]
55
description = "Arbitrary precision decimal numbers"
66
documentation = "https://docs.rs/bigdecimal"
@@ -10,8 +10,8 @@ keywords = ["mathematics", "numerics", "decimal", "arbitrary-precision", "floati
1010
license = "MIT/Apache-2.0"
1111

1212
[dependencies]
13-
num-bigint = "0.3"
14-
num-integer = "0.1.43"
13+
num-bigint = "0.4"
14+
num-integer = "0.1"
1515
num-traits = "0.2"
1616
serde = { version = "1.0", optional = true }
1717

examples/repeated_squares.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
21
extern crate bigdecimal;
32

43
use bigdecimal::BigDecimal;
54
use std::time::Instant;
65
use std::str::FromStr;
76

8-
fn main()
9-
{
10-
// let mut x = BigDecimal::from(1.1);
7+
fn main() {
8+
// let mut x = BigDecimal::from(1.1);
119
let mut x = BigDecimal::from_str("1.1").unwrap();
1210
// for iter in 0..1_000_000 {
13-
for iter in 0..1_000 {
11+
for iter in 0..26 {
1412
let start = Instant::now();
1513
x = x.clone() * x;
1614
// x = x.take_and_square();
1715
let end = Instant::now();
1816
let usage = end - start;
19-
println!("iter {} takes {} secs", iter, usage.as_secs() as f32 + usage.subsec_nanos() as f32 / 1.0e9);
17+
println!(
18+
"iter {} takes {} secs",
19+
iter,
20+
usage.as_secs() as f32 + usage.subsec_nanos() as f32 / 1.0e9
21+
);
2022
}
2123
}
22-
23-

examples/simple-math.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
extern crate bigdecimal;
2+
use bigdecimal::*;
3+
use std::str::FromStr;
4+
5+
/* Default example output:
6+
7+
Hello, Big Decimals!
8+
Input (0.8) with 10 decimals: 0.8 vs 0.8)
9+
square 0.64
10+
From Prim: 3.300000000000000
11+
match test 33.90000000000000
12+
24.00000000000000 + 34.00000000000000 = 58.00000000000000
13+
sum mut: 48.00000000000000
14+
0.000000000000000 IS equal to zero
15+
24.00000000000000 / 1.000000000000000 = 24.00000000000000
16+
24.0 / 1.000000000000000 = 24.0
17+
24.0 / 1.5 = 16
18+
24.000 / 1.50 = 16.0
19+
*/
20+
21+
fn main() {
22+
println!("Hello, Big Decimals!");
23+
let input = "0.8";
24+
let dec = BigDecimal::from_str(&input).unwrap();
25+
let float = f32::from_str(&input).unwrap();
26+
println!("Input ({}) with 10 decimals: {} vs {})", input, dec, float);
27+
28+
let bd_square = dec.square();
29+
println!("square {}", bd_square);
30+
31+
let bd_from_prim = BigDecimal::from_f64(3.3);
32+
println!("From Prim: {}", bd_from_prim.unwrap());
33+
34+
let bd_match: BigDecimal = match BigDecimal::from_f64(33.9) {
35+
Some(bd) => bd,
36+
None => BigDecimal::zero(),
37+
};
38+
println!("match test {}", bd_match);
39+
40+
let bd_add1 = &BigDecimal::from_f64(24.0).unwrap();
41+
let bd_add2 = &BigDecimal::from_f64(34.0).unwrap();
42+
print_sum(bd_add1, bd_add2);
43+
44+
let mut bd_add3 = BigDecimal::from_f64(24.0).unwrap();
45+
let bd_add4 = BigDecimal::from_f64(24.0).unwrap();
46+
bd_add3 += bd_add4;
47+
println!("sum mut: {}", bd_add3);
48+
49+
let bd_nez = BigDecimal::from_f64(0.0).unwrap();
50+
if bd_nez != BigDecimal::zero() {
51+
println!("{} is not equal to zero", &bd_nez);
52+
} else {
53+
println!("{} IS equal to zero", &bd_nez);
54+
}
55+
56+
let bd_div1 = &BigDecimal::from_f64(24.0).unwrap();
57+
let bd_div2 = &BigDecimal::from_f64(1.0).unwrap();
58+
print_division(bd_div1, bd_div2);
59+
60+
let bd_div1 = &BigDecimal::from_str("24.0").unwrap();
61+
print_division(bd_div1, bd_div2);
62+
63+
let bd_num = &BigDecimal::from_str("24.0").unwrap();
64+
let bd_den = &BigDecimal::from_str("1.5").unwrap();
65+
print_division(bd_num, bd_den);
66+
67+
let bd_num = &BigDecimal::from_str("24.000").unwrap();
68+
let bd_den = &BigDecimal::from_str("1.50").unwrap();
69+
print_division(bd_num, bd_den);
70+
}
71+
72+
fn print_sum(a: &BigDecimal, b: &BigDecimal) {
73+
let sum = a + b;
74+
println!("{} + {} = {}", a, b, sum);
75+
}
76+
77+
fn print_division(num: &BigDecimal, den: &BigDecimal) {
78+
let quotient = num / den;
79+
println!("{} / {} = {}", num, den, quotient);
80+
}

0 commit comments

Comments
 (0)