Click here to Skip to main content
15,890,438 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: What is Sign of 0? Pin
Marc Clifton2-May-16 5:29
mvaMarc Clifton2-May-16 5:29 
GeneralRe: What is Sign of 0? Pin
k50542-May-16 6:50
mvek50542-May-16 6:50 
GeneralRe: What is Sign of 0? Pin
Member 102679033-May-16 8:17
professionalMember 102679033-May-16 8:17 
GeneralRe: What is Sign of 0? Pin
Bassam Abdul-Baki2-May-16 5:09
professionalBassam Abdul-Baki2-May-16 5:09 
GeneralRe: What is Sign of 0? Pin
Kirk 103898213-May-16 7:20
Kirk 103898213-May-16 7:20 
GeneralRe: What is Sign of 0? Pin
OriginalGriff2-May-16 5:11
mveOriginalGriff2-May-16 5:11 
GeneralRe: What is Sign of 0? Pin
Marc Clifton2-May-16 5:33
mvaMarc Clifton2-May-16 5:33 
QuestionRe: What is Sign of 0? Pin
Matt T Heffron2-May-16 7:44
professionalMatt T Heffron2-May-16 7:44 
But for which reason?
Is it the parser in the compiler?
Is it the output routine you used? (The VS debugger?)
So I tried the following:
C#
double a = -0.0;
Console.WriteLine("a = {0}, 1.0/a = {1}", a, 1.0 / a);
double b = double.Parse("-0.0");
Console.WriteLine("b = {0}, 1.0/b = {1}", b, 1.0 / b);
byte[] abytes = BitConverter.GetBytes(a);
Console.WriteLine("a bytes=" + string.Join(",", abytes.Select(z => z.ToString("X2"))));
byte[] bbytes = BitConverter.GetBytes(b);
Console.WriteLine("b bytes=" + string.Join(",", bbytes.Select(z => z.ToString("X2"))));

The output was surprising:
a = 0, 1.0/a = -Infinity
b = 0, 1.0/b = Infinity
a bytes=00,00,00,00,00,00,00,80
b bytes=00,00,00,00,00,00,00,00

So the compiler handles the -0.0 correctly, but double.Parse doesn't and the output is converting the negative 0.0 to "0.0" with no sign.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton

AnswerRe: What is Sign of 0? Pin
Chris @ SAS7-May-16 13:13
Chris @ SAS7-May-16 13:13 
GeneralRe: What is Sign of 0? Pin
Matt T Heffron7-May-16 20:26
professionalMatt T Heffron7-May-16 20:26 
GeneralRe: What is Sign of 0? Pin
Jochen Arndt2-May-16 5:17
professionalJochen Arndt2-May-16 5:17 
GeneralRe: What is Sign of 0? Pin
Marc Clifton2-May-16 5:34
mvaMarc Clifton2-May-16 5:34 
GeneralRe: What is Sign of 0? Pin
R. Giskard Reventlov2-May-16 5:27
R. Giskard Reventlov2-May-16 5:27 
GeneralRe: What is Sign of 0? Pin
90823652-May-16 5:35
90823652-May-16 5:35 
GeneralRe: What is Sign of 0? Pin
Sander Rossel2-May-16 5:50
professionalSander Rossel2-May-16 5:50 
GeneralRe: What is Sign of 0? Pin
Marc Clifton2-May-16 10:40
mvaMarc Clifton2-May-16 10:40 
GeneralRe: What is Sign of 0? Pin
Sander Rossel2-May-16 11:25
professionalSander Rossel2-May-16 11:25 
GeneralRe: What is Sign of 0? Pin
Mark_Wallace2-May-16 7:01
Mark_Wallace2-May-16 7:01 
GeneralRe: What is Sign of 0? Pin
Kornfeld Eliyahu Peter2-May-16 7:19
professionalKornfeld Eliyahu Peter2-May-16 7:19 
GeneralRe: What is Sign of 0? Pin
patbob2-May-16 7:59
patbob2-May-16 7:59 
GeneralRe: What is Sign of 0? Pin
Daniel Pfeffer2-May-16 22:35
professionalDaniel Pfeffer2-May-16 22:35 
GeneralRe: What is Sign of 0? Pin
benf23-May-16 1:32
benf23-May-16 1:32 
GeneralRe: What is Sign of 0? Pin
Kiriander2-May-16 21:36
Kiriander2-May-16 21:36 
GeneralRe: What is Sign of 0? Pin
Ygnaiih3-May-16 7:24
professionalYgnaiih3-May-16 7:24 
GeneralRe: What is Sign of 0? Pin
ormonds3-May-16 12:03
ormonds3-May-16 12:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.