MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / abs

Function abs

ciphercore-base/src/ops/long_division.rs:358–374  ·  view source on GitHub ↗

Returns (is_negative(binary_num), abs(binary_num)).

(binary_num: Node, is_signed: bool)

Source from the content-addressed store, hash-verified

356
357// Returns (is_negative(binary_num), abs(binary_num)).
358fn 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)]
377mod tests {

Callers 1

instantiateMethod · 0.85

Calls 6

is_negativeFunction · 0.85
cloneMethod · 0.80
zerosMethod · 0.80
scalar_typeFunction · 0.50
get_graphMethod · 0.45
custom_opMethod · 0.45

Tested by

no test coverage detected