Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Paul
Posts:
487
Registered:
2/23/10


Re: fprintf output: What does 0 mean?
Posted:
Jan 24, 2014 6:35 PM


paul.domaskisATgmail.com wrote in message <88ea480202a142c8a2d3616cd7bba2e7@googlegroups.com>... > 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.367172e01 > 0.000000e+00 > 6.460915e02 > 1.078923e10 > > 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 UTC5, 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 UTC5, 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 IEEE754 > 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.2204e16 and that I can add 2.2204e35+2.2204e35=4.4408e35. Also, if I bypass the format command, it comes out as a zero:
>> B(:,86) ans = 0.064609 0 0 0 0.13672 0 1.0789e10
Matlab thinks it's a zero:
>> isequal(B(3,86),0) ans = 1
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!)



