Skip to content

Commit 3aaae81

Browse files
committed
Add additional math methods on quantities
Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
1 parent 89f5a8e commit 3aaae81

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

src/quantity.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,50 @@ macro_rules! qty_ctor {
189189

190190
impl $typename {
191191
qty_ctor!(@impl $($rest)*);
192+
193+
pub fn abs(&self) -> Self {
194+
Self {
195+
value: self.value.abs(),
196+
}
197+
}
198+
199+
pub fn floor(&self) -> Self {
200+
Self {
201+
value: self.value.floor(),
202+
}
203+
}
204+
205+
pub fn ceil(&self) -> Self {
206+
Self {
207+
value: self.value.ceil(),
208+
}
209+
}
210+
211+
pub fn round(&self) -> Self {
212+
Self {
213+
value: self.value.round(),
214+
}
215+
}
216+
217+
pub fn trunc(&self) -> Self {
218+
Self {
219+
value: self.value.trunc(),
220+
}
221+
}
222+
223+
pub fn fract(&self) -> Self {
224+
Self {
225+
value: self.value.fract(),
226+
}
227+
}
228+
229+
pub fn is_nan(&self) -> bool {
230+
self.value.is_nan()
231+
}
232+
233+
pub fn is_infinite(&self) -> bool {
234+
self.value.is_infinite()
235+
}
192236
}
193237

194238
qty_ctor!{@impl_arith_ops $typename}

0 commit comments

Comments
 (0)