-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathad.rs
42 lines (35 loc) · 784 Bytes
/
ad.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
extern crate peroxide;
use peroxide::fuga::*;
fn main() {
let a = AD1(2f64, 1f64);
a.print();
let a2 = a.to_order(2);
let b = AD2(4f64, 4f64, 2f64);
b.print();
(a + b).print();
(a - b).print();
(a * b).print();
(a / b).print();
(a2 / b).print();
a.exp().print();
a.ln().print();
b.exp().print();
b.ln().print();
a.powi(2).print();
b.sqrt().print();
b.cos().print();
b.sin().print();
b.cosh().print();
b.sinh().print();
f(a, b).print();
(b + 1f64).print();
(b - 1f64).print();
(b * 2f64).print();
(b / 2f64).print();
assert_eq!(-(1f64 - b), b - 1f64);
assert_eq!(2f64 * b, b * 2f64);
assert_eq!(1f64 / (2f64 / b), b / 2f64);
}
fn f(a: AD, b: AD) -> AD {
a + b
}