Skip to content

Commit

Permalink
feat(code): reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Mte90 committed Sep 19, 2024
1 parent 59ab59a commit 350f621
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/translate/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ pub fn translate_computation(meta: &TranslateMetadata, operation: ArithOp, left:
match meta.arith_module {
ArithType::BcSed => {
let (left, right) = (left.unwrap_or_default(), right.unwrap_or_default());
let mut math_lib_flag = true;
// Removes trailing zeros from the expression
let sed_regex = "/\\./ s/\\.\\{0,1\\}0\\{1,\\}$//";
let mut scale = "";
let op = match operation {
ArithOp::Add => "+",
ArithOp::Sub => "-",
ArithOp::Mul => "*",
ArithOp::Div => "/",
ArithOp::Div => {
scale = "scale=0;";
"/"
},
ArithOp::Modulo => {
math_lib_flag = false;
scale = "scale=0;";
"%"
},
ArithOp::Neg => "-",
Expand All @@ -50,7 +51,7 @@ pub fn translate_computation(meta: &TranslateMetadata, operation: ArithOp, left:
ArithOp::Or => "||"
};
let math_lib_flag = if math_lib_flag { "-l" } else { "" };
meta.gen_subprocess(&format!("echo {left} '{op}' {right} | bc {math_lib_flag} | sed '{sed_regex}'"))
meta.gen_subprocess(&format!("echo \"{scale}{left}{op}{right}\" | bc -l"))
}
}
}
Expand Down

0 comments on commit 350f621

Please sign in to comment.