Pregunta

I want to divide to variable like below. I found that when I divide c which is double and the value for example is 0.0137777887700191 to 10 the diff becomes 6.9533479143199673e-310.

double diff = c /  static_cast<double>(10);

Why the results is like this. Can you help me please.

a part of code is like this:

double c = uniform(0,(nextac0PktExpir->getArrivalTime() - simTime()).dbl());
double diff = c / 10.0;
¿Fue útil?

Solución

#include <iostream>

int main()
{
  double c(0.0134);
  double diff;
  std::cout << diff << std::endl;
  diff = c /10.0;
  std::cout << diff;

  return 0;
}

With g++ it will print:

6.95322e-310    (or something similar...)
0.00134

You're probably checking the value of diff in the debugger before the assignment is performed.

Otros consejos

This works For me. Its giving expected result.

#include <iostream>
using namespace std;

int main() 
{
 double c = 0.0134 ;
 double diff = c /10;
 cout << diff;
 return 0;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top