Why does Gnu Octave have negative zeroes?

后端 未结 3 1494
孤城傲影
孤城傲影 2020-12-15 17:23

This is an odd one I\'m puzzled about. I recently noticed at the Gnu Octave prompt, it\'s possible to enter in negative zeroes, like so:

octave:2> abomin         


        
3条回答
  •  没有蜡笔的小新
    2020-12-15 17:45

    Signed zero are part of the IEEE-754 formats, and their semantics are completely specified by those formats. They turn out to be quite useful, especially when dealing with complex branch cuts and transformations of the complex plane (see many of W. Kahan's writings on the subject for more details, such as the classic "Branch Cuts for Complex Elementary Functions, or Much Ado about Nothing's Sign Bit").

    Short version: negative zero is often a good thing to have in numerical calculations, and programs that try to protect users from encountering it are often doing them a disservice. FWIW, MATLAB does seem to use negative zero as well, but since it prints numbers using the host's printf routine, they display the same as positive zero on Windows.

    See this discussion on the MATLAB forums for more details on signed zero in MATLAB.

提交回复
热议问题