diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/eval.rs | 7 | ||||
| -rw-r--r-- | src/op.rs | 2 | ||||
| -rw-r--r-- | src/parser.rs | 4 |
3 files changed, 13 insertions, 0 deletions
diff --git a/src/eval.rs b/src/eval.rs index a72f271..e40743b 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -179,6 +179,13 @@ impl Num { } } + pub fn trunc(self) -> Num { + match self { + Int(i) => Int(i), + Float(f) => Int(f as i128), + } + } + pub fn abs(self) -> Num { match self { Int(i) => Int(i.abs()), @@ -16,6 +16,7 @@ pub enum UnOp { Floor, Ceil, Round, + Trunc, Abs, } @@ -36,6 +37,7 @@ impl UnOp { UnOp::Floor => x.floor(), UnOp::Ceil => x.ceil(), UnOp::Round => x.round(), + UnOp::Trunc => x.trunc(), UnOp::Abs => x.abs(), } } diff --git a/src/parser.rs b/src/parser.rs index a31b4f9..1e271a4 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -130,6 +130,10 @@ impl<'a> Parser<'a> { self.stack.push(Pending::Un(UnOp::Round)); return true; } + if self.symbol("trunc") { + self.stack.push(Pending::Un(UnOp::Trunc)); + return true; + } if self.symbol("abs") { self.stack.push(Pending::Un(UnOp::Abs)); return true; |
