The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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 ]

Posts: 517
Registered: 2/23/10
Re: fprintf output: What does -0 mean?
Posted: Jan 24, 2014 6:35 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply wrote in message <>...
> 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?

On Friday, January 24, 2014 11:57:07 AM UTC-5, someone wrote:
> It's probably just a VERY small negative number that you don't have
> enough significant digits to see.

On Friday, January 24, 2014 3:23:28 PM UTC-5, dpb wrote:
> 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.

Yes, it's not clear whether it's a very small negative number, but I confirmed that eps=2.2204e-16 and that I can add 2.2204e-35+2.2204e-35=4.4408e-35. Also, if I bypass the format command, it comes out as a zero:

>> B(:,86)
ans =

Matlab thinks it's a zero:

>> isequal(B(3,86),0)
ans =

I guess I'll manually clean up these things in the report. I'm not going to delve into machine representation at this point, but I'll keep the idea of bit pattern examination for future reference.

Thanks! (for not being "positive", too!)

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.