Doubts with Scientific Notation

0

There is another way than with% E in c, why did I do this and uri gave 10% error. Issue Link

My code.

#include <stdio.h>

int main(int argc, char** argv)
{
  double teste;
  scanf("%lf", &teste);
  if(teste == -0)
  {
    printf("+0.0000E+00\n");
  }
  else
  {
    printf("%+.4E\n", teste);
  }
  return 0;
}
    
asked by anonymous 07.02.2018 / 15:26

1 answer

1

The problem is that you print the value "+ 0.0000E + 00 \ n" for -0 entries.

Due to the limitation of the range of values that double can take in cases of very small negative numbers the value can be truncated to -0.0000E + 00, so your if makes it "+ 0.0000E + 00" which it is not a valid output.

Take a look at the IEEE 754 standard for the range question and on that other link the +0 and -0 .

    
07.02.2018 / 22:50