snippetrustCritical
How do I get an absolute value in Rust?
Viewed 0 times
howabsoluterustvalueget
Problem
The docs are unhelpful: http://web.mit.edu/rust-lang_v0.9/doc/std/num/fn.abs.html
Obviously, I can see the function right there, but I haven't got the faintest idea how to call it.
Edit:
The problem is that it doesn't work. :)
"Unresolved name: num::abs"
Edit 2: running the nightly from yesterday (11/26/2014); I don't know what version. I didn't realize those docs were so outdated. oO
Current docs seem to indicate there is no such function?
Obviously, I can see the function right there, but I haven't got the faintest idea how to call it.
Edit:
The problem is that it doesn't work. :)
use std::num;
let x = num::abs(value);"Unresolved name: num::abs"
Edit 2: running the nightly from yesterday (11/26/2014); I don't know what version. I didn't realize those docs were so outdated. oO
Current docs seem to indicate there is no such function?
Solution
Nowadays,
abs is a method on most number types.let value = -42i32;
let x = value.abs();Code Snippets
let value = -42i32;
let x = value.abs();Context
Stack Overflow Q#27182808, score: 171
Revisions (0)
No revisions yet.