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


dpb
Posts:
8,589
Registered:
6/7/07


Re: fprintf output: What does 0 mean?
Posted:
Jan 24, 2014 3:23 PM


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.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?
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.



