Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: fprintf output: What does -0 mean?
Replies: 6   Last Post: Jan 27, 2014 11:17 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 7,862
Registered: 6/7/07
Re: fprintf output: What does -0 mean?
Posted: Jan 24, 2014 3:23 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 1/24/2014 10:30 AM, paul.domaskis@gmail.com wrote:
> I get a negative zero when printing a set of coefficients of lasso regression:
>

> >> format longg
> >> fprintf('%e\n',B(:,86))

> 0.000000e+00
> -0.000000e+00
> -0.000000e+00
> -1.367172e-01
> 0.000000e+00
> -6.460915e-02
> -1.078923e-10
>
> I can't provide simple code to do duplicate. A simply cut/paste of
> the above text to assign into a variable x does not yield the same
> fprintf results.
>
> What would cause the negative zero? How should it be interpretted?


In IEEE 754 binary floating point numbers, zero values are represented
by the biased exponent and significand both being zero. Negative zero
has the sign bit set to one. One may obtain negative zero as the result
of certain computations, for instance as the result of arithmetic
underflow on a negative number, or ?1.0*0.0, or simply as ?0.0.

I'm not positive (so to speak :) ) on how TMW has implemented IEEE-754
precisely; the above is from a simplified description of the Standard,
not from Matlab doc's.

In the simple case of command line assignment -1.0*0.0 --> 0.0, however.

A search found nothing useful in the doc's on the subject.

You can take the value and look at the bit pattern, however, to see if
it is indeed -0.0 or a presentation issue of the format string. I
_thought_ any representable exponent (even underflow subnormal) would be
displayed rather than the observed e+00 so I don't _think_ it's just
small value.




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.