Sign of a number
Rust Branching
if as an expression
Flowchart (ISO 5807)
Source code
fn sign(x: i32) -> i32 {
if x > 0 {
1
} else if x < 0 {
-1
} else {
0
}
} if as an expression
fn sign(x: i32) -> i32 {
if x > 0 {
1
} else if x < 0 {
-1
} else {
0
}
}