c++ - #define to double - different value? -


There are two different ways that I am defining the same value. I want it to be present as a 64-bit (double exact) float point number (aka double).

  #define THISVALUE -0.148759f double myDouble = -0.148759;   

If I do the following operation

  double try = THISVALUE;   

And when I look at the value while debugging or printing it, I can see that it's tryIt at -0.14875899255275726 < / P>.

I think a floating point is not correct, but it's just a crazy difference that actually throws my math. Specifying double in the straightforward code block gives me the value of -0.14875 9, 00000000000 in the debugger - it should be exactly the same way.

Any thoughts on what's going on?

Because -0.14875 9f a double No, this is a name . Therefore it is almost certainly different precision which is doing the difference.

Either you should give the same result in these two variations:

  #define THISVALUE -0.148759 double myDouble = - 0.148759; // Both doubled #define THISVALUE -0.148759f double myDouble = -0.148759f; // Both float IEEE 754 single precision values ​​(usually used in  float ) have only 32 bits available, so double precision value (which is 64 ) compared to limited precision values According to  

, the thick figures for range and accuracy are as follows:

  • singles , category With a ± 10 a ± 38 7 digit precision.
  • For double , the category ± 10 15-digit accuracy ± 308 .

    And, on one hand, nowadays there is more to use macros, either or < / Em> Objects can be preceded by inline suggestions and good compilers, later with const int (or const double your case Can be done without losing any information between compilation steps (things like name and type information).

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -