Returns (is_negative(binary_num), abs(binary_num)).
(binary_num: Node, is_signed: bool)
| 356 | |
| 357 | // Returns (is_negative(binary_num), abs(binary_num)). |
| 358 | fn abs(binary_num: Node, is_signed: bool) -> Result<(Node, Node)> { |
| 359 | let g = binary_num.get_graph(); |
| 360 | if is_signed { |
| 361 | let num_is_negative = is_negative(binary_num.clone())?; |
| 362 | let abs = g.custom_op( |
| 363 | CustomOperation::new(Mux {}), |
| 364 | vec![ |
| 365 | num_is_negative.clone(), |
| 366 | negative(binary_num.clone())?, |
| 367 | binary_num, |
| 368 | ], |
| 369 | )?; |
| 370 | Ok((num_is_negative, abs)) |
| 371 | } else { |
| 372 | Ok((g.zeros(scalar_type(BIT))?, binary_num)) |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | #[cfg(test)] |
| 377 | mod tests { |
no test coverage detected