Doubt with Scientific Notation

Asked

Viewed 419 times

0

There is another way but with %E in c, why I did so and Uri gave 10 % error. Question 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;
}
  • Had posted the wrong code, now it’s fixed

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 assume in cases of very small negative numbers the value can be truncated to -0.0000E+00, with this your if makes it "+0.0000E+00" which is not a valid output.

Take a look at the pattern IEEE 754 to the question of the range and on that other link the question of +0 and -0.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.