BafDyce
BafDyce

Reputation: 177

Maximum possible value for f64?

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?

Upvotes: 8

Views: 6277

Answers (1)

Greg Hewgill
Greg Hewgill

Reputation: 994101

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".

Upvotes: 14

Related Questions