Enjolras
Enjolras

Reputation: 391

How to write a floating point constant

I'm not aware and cannot quicly find the right way to enter floating point constant in C++.

If i want 2^-52, what should i write ? And, what does << with float ? Is that correct ?

const double pres = 1>>52

Upvotes: 1

Views: 871

Answers (3)

Henrik
Henrik

Reputation: 23324

Looks like you really want the precision of double representation. In this case, don't use magic constants. Instead you can use this:

const double pres = std::numeric_limits<double>::epsilon();

Upvotes: 5

rosjo
rosjo

Reputation: 33

#include<math.h>
double pres = 1/pow(2,52);

Upvotes: 0

Paul R
Paul R

Reputation: 212959

You can use hex float representation for this:

const double pres = 0x1p-52;

Upvotes: 3

Related Questions