1use std::{cmp::Ordering, fmt::Debug};
2mod impls;
3
4pub trait Ring: Copy + Sized + PartialEq + PartialOrd + Debug {
5 const ZERO: Self;
6 const ONE: Self;
7 const TWO: Self;
8 fn add(self, other: Self) -> Self;
9 fn add_assign(&mut self, other: Self);
10 fn mul(self, other: Self) -> Self;
11 fn mul_assign(&mut self, other: Self);
12 fn sub(self, other: Self) -> Self;
13 fn sub_assign(&mut self, other: Self);
14 fn div(self, other: Self) -> Self;
15 fn div_assign(&mut self, other: Self);
16 fn pow(self, other: u32) -> Self;
17 fn neg(self) -> Self;
18 fn abs(self) -> Self;
19 fn sign(self) -> Self;
20 fn cmp(&self, other: &Self) -> Ordering;
21 fn is_zero(self) -> bool;
22 fn is_nan(self) -> bool;
23 fn is_finite(self) -> bool;
24 fn rem_euclid(self, other: Self) -> Self;
25
26 fn clamp(self, min: Self, max: Self) -> Self {
27 if self.cmp(&min).is_lt() {
28 min
29 } else if self.cmp(&max).is_gt() {
30 max
31 } else {
32 self
33 }
34 }
35
36 fn min(self, other: Self) -> Self {
37 if self.cmp(&other).is_le() {
38 self
39 } else {
40 other
41 }
42 }
43
44 fn max(self, other: Self) -> Self {
45 if self.cmp(&other).is_ge() {
46 self
47 } else {
48 other
49 }
50 }
51}
52
53pub trait Field: Ring {
54 const HALF: Self;
55 const PI: Self;
56 const SQRT_2: Self;
57 const INFINITY: Self;
58
59 fn sqrt(self) -> Self;
60
61 fn exp(self) -> Self;
62
63 fn sin(self) -> Self;
64 fn cos(self) -> Self;
65 fn tan(self) -> Self;
66
67 fn sin_cos(self) -> (Self, Self);
68
69 fn ln(self) -> Self;
70
71 fn asin(self) -> Self;
72 fn acos(self) -> Self;
73 fn atan(self) -> Self;
74
75 fn atan2(y: Self, x: Self) -> Self;
76}