polars_plan/dsl/
arithmetic.rs1use std::ops::{Add, Div, Mul, Neg, Rem, Sub};
2
3use super::*;
4
5impl Add for Expr {
7 type Output = Expr;
8
9 fn add(self, rhs: Self) -> Self::Output {
10 binary_expr(self, Operator::Plus, rhs)
11 }
12}
13
14impl Sub for Expr {
15 type Output = Expr;
16
17 fn sub(self, rhs: Self) -> Self::Output {
18 binary_expr(self, Operator::Minus, rhs)
19 }
20}
21
22impl Div for Expr {
23 type Output = Expr;
24
25 fn div(self, rhs: Self) -> Self::Output {
26 binary_expr(self, Operator::Divide, rhs)
27 }
28}
29
30impl Mul for Expr {
31 type Output = Expr;
32
33 fn mul(self, rhs: Self) -> Self::Output {
34 binary_expr(self, Operator::Multiply, rhs)
35 }
36}
37
38impl Rem for Expr {
39 type Output = Expr;
40
41 fn rem(self, rhs: Self) -> Self::Output {
42 binary_expr(self, Operator::Modulus, rhs)
43 }
44}
45
46impl Neg for Expr {
47 type Output = Expr;
48
49 fn neg(self) -> Self::Output {
50 self.map_unary(FunctionExpr::Negate)
51 }
52}
53
54impl Expr {
55 pub fn floor_div(self, rhs: Self) -> Self {
57 binary_expr(self, Operator::FloorDivide, rhs)
58 }
59
60 pub fn pow<E: Into<Expr>>(self, exponent: E) -> Self {
62 self.map_binary(PowFunction::Generic, exponent.into())
63 }
64
65 pub fn sqrt(self) -> Self {
67 self.map_unary(PowFunction::Sqrt)
68 }
69
70 pub fn cbrt(self) -> Self {
72 self.map_unary(PowFunction::Cbrt)
73 }
74
75 #[cfg(feature = "trigonometry")]
77 pub fn cos(self) -> Self {
78 self.map_unary(TrigonometricFunction::Cos)
79 }
80
81 #[cfg(feature = "trigonometry")]
83 pub fn cot(self) -> Self {
84 self.map_unary(TrigonometricFunction::Cot)
85 }
86
87 #[cfg(feature = "trigonometry")]
89 pub fn sin(self) -> Self {
90 self.map_unary(TrigonometricFunction::Sin)
91 }
92
93 #[cfg(feature = "trigonometry")]
95 pub fn tan(self) -> Self {
96 self.map_unary(TrigonometricFunction::Tan)
97 }
98
99 #[cfg(feature = "trigonometry")]
101 pub fn arccos(self) -> Self {
102 self.map_unary(TrigonometricFunction::ArcCos)
103 }
104
105 #[cfg(feature = "trigonometry")]
107 pub fn arcsin(self) -> Self {
108 self.map_unary(TrigonometricFunction::ArcSin)
109 }
110
111 #[cfg(feature = "trigonometry")]
113 pub fn arctan(self) -> Self {
114 self.map_unary(TrigonometricFunction::ArcTan)
115 }
116
117 #[cfg(feature = "trigonometry")]
119 pub fn arctan2(self, x: Self) -> Self {
120 self.map_binary(FunctionExpr::Atan2, x)
121 }
122
123 #[cfg(feature = "trigonometry")]
125 pub fn cosh(self) -> Self {
126 self.map_unary(TrigonometricFunction::Cosh)
127 }
128
129 #[cfg(feature = "trigonometry")]
131 pub fn sinh(self) -> Self {
132 self.map_unary(TrigonometricFunction::Sinh)
133 }
134
135 #[cfg(feature = "trigonometry")]
137 pub fn tanh(self) -> Self {
138 self.map_unary(TrigonometricFunction::Tanh)
139 }
140
141 #[cfg(feature = "trigonometry")]
143 pub fn arccosh(self) -> Self {
144 self.map_unary(TrigonometricFunction::ArcCosh)
145 }
146
147 #[cfg(feature = "trigonometry")]
149 pub fn arcsinh(self) -> Self {
150 self.map_unary(TrigonometricFunction::ArcSinh)
151 }
152
153 #[cfg(feature = "trigonometry")]
155 pub fn arctanh(self) -> Self {
156 self.map_unary(TrigonometricFunction::ArcTanh)
157 }
158
159 #[cfg(feature = "trigonometry")]
161 pub fn degrees(self) -> Self {
162 self.map_unary(TrigonometricFunction::Degrees)
163 }
164
165 #[cfg(feature = "trigonometry")]
167 pub fn radians(self) -> Self {
168 self.map_unary(TrigonometricFunction::Radians)
169 }
170
171 #[cfg(feature = "sign")]
173 pub fn sign(self) -> Self {
174 self.map_unary(FunctionExpr::Sign)
175 }
176}