A
A
Anonymous123443212021-11-12 17:03:16
C++ / C#
Anonymous12344321, 2021-11-12 17:03:16

Why is a negative zero not displayed when using breakpoint in the local variables window?

using System;

namespace N
{
   class Program
   {
      static void Main(string[] args)
      {
         Console.WriteLine(0.0/-1.0);

         double c = 0.0 / -1.0; // Здесь breakpoint

         Console.WriteLine(c);
      }
   }
}


The first Console.WriteLine prints a negative zero to the console. This is due to the fact that the function divides numbers of type double, which can be represented as sign, exponent, and mantissa. In this case,
the sign of the number will be negative. The same thing happens in the second output. But if you put a breakpoint on the c variable in visual studio and monitor its value while the program is running, then instead of -0 in the local variables window there will be just 0. Why is the zero sign not taken into account in the local variables window? And is there any way to fix this?
618e73a2b6309542789110.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2021-11-12
@Anonymous12344321

The sign at zero is not displayed - from the fact that the developers of the studio are so great.
If you do not like this behavior - write a bug report.
In theory, you can fix it through a custom extension for the studio

A
Alexander, 2021-11-12
@Adler_lug

IMHO, there are more questions to Console.WriteLine (c) than to breakpoint, because What 0 does not divide into will be 0.
And how can 0 have a negative value, given that it is a neutral "separator" between a positive and a negative number?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question