(format nil "~,1e" 99.999) ; => "10.0e+1"

Bug #876655 reported by Alexander Klimov
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Triaged
Low
Unassigned

Bug Description

on SBCL 1.0.52.1-805f1dd

 (format nil "~,1e" 99.999) ; => "10.0e+1"

but it should produce the same result as

 (format nil "~,1e" 100.001) ; => "1.0e+2"

The attached patch contains more tests.

I guess the culprit is format-exp-aux that uses scale-exponent on the non-rounded number, but applies (thru flonum-to-string) the produced exponent to the rounded number.

Revision history for this message
Alexander Klimov (alserkli) wrote :
tags: added: review
tags: removed: review
Revision history for this message
Nikodemus Siivola (nikodemus) wrote :

I'm not sure they are actually required to produce the same string.

My reasoning:

 "k is a scale factor that defaults to one (not zero)" -

So k is 1.

"If k is positive, then it must be strictly less than d+2; k significant digits are printed before the decimal point, and d-k+1 digits are printed after the decimal point."

Both "10.0e+1" and "1.0e+2" have 1 /significant/ digit before the decimal point.

d-k+1 = 1

Both have 1 digit after the decimal point, so unless there are other constraints which I missed, they both seem legal to me.

Can you lay out your reasoning as to why they should produce the same output?

Changed in sbcl:
status: New → Incomplete
Revision history for this message
Alexander Klimov (alserkli) wrote :

Since <HyperSpec/Body/26_glo_s.htm> does not contain a definition of
"significant digit", I guess we can apply the usual definition applied
to exponential (aka. scientific) notation
<http://en.wikipedia.org/wiki/Significant_figures#Scientific_notation>:

  [I]n the normalized form of that notation, placeholder leading and
  trailing digits do not occur, so all digits are significant. For
  example, 0.00012 (two significant digits) becomes 1.2×10^−4, and
  0.00122300 (six significant digits) becomes 1.22300×10^−3. In
  particular, the potential ambiguity about the significance of
  trailing zeros is eliminated. For example, 1300 to four significant
  digits is written as 1.300×10^3, while 1300 to two significant digits
  is written as 1.3×10^3.

That is 10.0 has two significant digits before the point and one after
it.

Note that if "10.[...]" were understood to have 1 significant digit
because the trailing zeros are considered insignificant, then

 (format nil "~,3,,4e" 123) ; -> "1230.e-1"

would be an error since there would be only 3 significant digits
before point while k=4.

Revision history for this message
Nikodemus Siivola (nikodemus) wrote :

Fair point.

Changed in sbcl:
status: Incomplete → Triaged
importance: Undecided → Low
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.