Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum possible value for f64?

Tags:

max

rust

min

How can I initialize a variable of type f64 with the maximum possible value? I already tried things like:

std::f64::MAX
f64::MAX_VALUE
f64::consts::MAX_VALUE
core::f64::MAX_VALUE

and some other variants but the compiler always complains about an unresolved name. I'm using no namespaces (like no use xx::yyy) and I'm trying to initialize the variable like this:

let mut min = f64::consts::MAX_VALUE;

Did I miss something or is there no way to get the largest possible value for a f64?

If there is a way for f64, what are the ways for the other data types?

like image 881
BafDyce Avatar asked Oct 20 '14 20:10

BafDyce


1 Answers

According to the std::f64 module documentation, the following should be what you want:

std::f64::MAX

which is declared as:

pub const MAX: f64 = 1.7976931348623157e+308_f64

It can be used like:

fn main() {
    let mut min = std::f64::MAX;
}

I found this by searching Google for "f64 maximum value rust".

like image 130
Greg Hewgill Avatar answered Nov 19 '22 21:11

Greg Hewgill