FORMAT: float formatter ~e inconsistent handling of digits before decimal place
CLHS 22.3.3.2 (http://www.lispworks.com/documentation/lw51/CLHS/Body/22_ccb.htm) says that the scale factor k determines the handling of digits before the decimal place.
Case 1: I expect to see 1 non-zero digit before the decimal place.
> (dotimes (i 9) (format t "~{~e ~}~%" (mapcar #'(lambda (x) (* x (expt 10.0 (- (1+ i))))) '(1 2 3 4 5 6 7 8 9))))
1.0000000149011611938e-1 2.0000000298023223877e-1 3.0000001192092895508e-1 4.0000000596046447754e-1 5.e-1 6.0000002384185791016e-1 6.999999880790710449e-1 8.000000119209289551e-1 9.0000003576278686523e-1
0.99999997764825820923e-2 1.9999999552965164185e-2 2.9999999329447746277e-2 0.3999999910593032837e-1 0.4999999701976776123e-1 0.59999998658895492554e-1 0.70000000298023223877e-1 0.7999999821186065674e-1 0.899999961256980896e-1
1.0000000474974513054e-3 0.20000000949949026108e-2 0.30000000260770320892e-2 0.40000001899898052216e-2 0.5000000353902578354e-2 0.60000000521540641785e-2 0.7000000216066837311e-2 0.8000000379979610443e-2 0.90000005438923835754e-2
0.99999997473787516356e-4 1.9999999494757503271e-4 0.29999998514540493488e-3 0.39999998989515006542e-3 0.49999996554106473923e-3 0.59999997029080986977e-3 0.6999999750405550003e-3 0.79999997979030013084e-3 0.8999999845400452614e-3
0.99999997473787516356e-5 1.9999999494757503271e-5 2.9999999242136254907e-5 0.39999998989515006542e-4 0.49999998736893758178e-4 0.59999998484272509813e-4 0.69999994593672454357e-4 0.79999997979030013084e-4 0.9000000136438757181e-4
0.9999999974752427079e-6 0.19999999949504854158e-5 0.30000001061125658453e-5 0.39999999899009708315e-5 0.49999998736893758178e-5 0.60000002122251316905e-5 0.7000000096013536677e-5 0.7999999979801941663e-5 0.9000000318337697536e-5
1.0000000116860974231e-7 2.0000000233721948462e-7 0.30000001061125658453e-6 0.40000000467443896923e-6 0.49999999873762135394e-6 0.60000002122251316905e-6 0.69999998686398612335e-6 0.80000000934887793846e-6 0.9000000318337697536e-6
0.9999999939225290291e-8 1.9999999878450580582e-8 0.29999998929497451172e-7 0.39999999756901161163e-7 0.50000000584304871154e-7 0.59999997858994902344e-7 0.69999998686398612335e-7 0.79999999513802322326e-7 0.90000000341206032317e-7
0.9999999717180685366e-9 0.19999999434361370731e-8 0.29999998041319031472e-8 0.39999998868722741463e-8 0.49999999696126451454e-8 0.59999996082638062944e-8 0.69999996910041772935e-8 0.79999997737445482926e-8 0.89999998564849192917e-8
NIL
Case 2: I expect to see 1 non-zero digit before the decimal place.
> (dotimes (i 9) (format t "~{~,4e ~}~%" (mapcar #'(lambda (x) (* x (expt 10.0 (- (1+ i))))) '(1 2 3 4 5 6 7 8 9))))
1.0000e-1 2.0000e-1 3.0000e-1 4.0000e-1 5.0000e-1 6.0000e-1 7.0000e-1 8.0000e-1 9.0000e-1
1.0000e-2 2.0000e-2 3.0000e-2 0.4000e-1 0.5000e-1 0.6000e-1 0.7000e-1 0.8000e-1 0.9000e-1
1.0000e-3 0.2000e-2 0.3000e-2 0.4000e-2 0.5000e-2 0.6000e-2 0.7000e-2 0.8000e-2 0.9000e-2
1.0000e-4 2.0000e-4 0.3000e-3 0.4000e-3 0.5000e-3 0.6000e-3 0.7000e-3 0.8000e-3 0.9000e-3
1.0000e-5 2.0000e-5 3.0000e-5 0.4000e-4 0.5000e-4 0.6000e-4 0.7000e-4 0.8000e-4 0.9000e-4
1.0000e-6 0.2000e-5 0.3000e-5 0.4000e-5 0.5000e-5 0.6000e-5 0.7000e-5 0.8000e-5 0.9000e-5
1.0000e-7 2.0000e-7 0.3000e-6 0.4000e-6 0.5000e-6 0.6000e-6 0.7000e-6 0.8000e-6 0.9000e-6
1.0000e-8 2.0000e-8 0.3000e-7 0.4000e-7 0.5000e-7 0.6000e-7 0.7000e-7 0.8000e-7 0.9000e-7
1.0000e-9 0.2000e-8 0.3000e-8 0.4000e-8 0.5000e-8 0.6000e-8 0.7000e-8 0.8000e-8 0.9000e-8
NIL
Case 3: I expect to see a zero before the decimal place, and no zeros after the decimal and before the first non-zero digit.
> (dotimes (i 9) (format t "~{~,,,0e ~}~%" (mapcar #'(lambda (x) (* x (expt 10.0 (- (1+ i))))) '(1 2 3 4 5 6 7 8 9))))
0.10000000149011611938e+0 0.20000000298023223877e+0 0.30000001192092895508e+0 0.40000000596046447754e+0 0.5e+0 0.60000002384185791016e+0 0.6999999880790710449e+0 0.8000000119209289551e+0 0.90000003576278686523e+0
0.099999997764825820923e-1 0.19999999552965164185e-1 0.29999999329447746277e-1 0.03999999910593032837e+0 0.04999999701976776123e+0 0.059999998658895492554e+0 0.070000000298023223877e+0 0.07999999821186065674e+0 0.0899999961256980896e+0
0.10000000474974513054e-2 0.020000000949949026108e-1 0.030000000260770320892e-1 0.040000001899898052216e-1 0.05000000353902578354e-1 0.060000000521540641785e-1 0.07000000216066837311e-1 0.08000000379979610443e-1 0.090000005438923835754e-1
0.099999997473787516356e-3 0.19999999494757503271e-3 0.029999998514540493488e-2 0.039999998989515006542e-2 0.049999996554106473923e-2 0.059999997029080986977e-2 0.06999999750405550003e-2 0.079999997979030013084e-2 0.08999999845400452614e-2
0.099999997473787516356e-4 0.19999999494757503271e-4 0.29999999242136254907e-4 0.039999998989515006542e-3 0.049999998736893758178e-3 0.059999998484272509813e-3 0.069999994593672454357e-3 0.079999997979030013084e-3 0.09000000136438757181e-3
0.09999999974752427079e-5 0.019999999949504854158e-4 0.030000001061125658453e-4 0.039999999899009708315e-4 0.049999998736893758178e-4 0.060000002122251316905e-4 0.07000000096013536677e-4 0.07999999979801941663e-4 0.09000000318337697536e-4
0.10000000116860974231e-6 0.20000000233721948462e-6 0.030000001061125658453e-5 0.040000000467443896923e-5 0.049999999873762135394e-5 0.060000002122251316905e-5 0.069999998686398612335e-5 0.080000000934887793846e-5 0.09000000318337697536e-5
0.09999999939225290291e-7 0.19999999878450580582e-7 0.029999998929497451172e-6 0.039999999756901161163e-6 0.050000000584304871154e-6 0.059999997858994902344e-6 0.069999998686398612335e-6 0.079999999513802322326e-6 0.090000000341206032317e-6
0.09999999717180685366e-8 0.019999999434361370731e-7 0.029999998041319031472e-7 0.039999998868722741463e-7 0.049999999696126451454e-7 0.059999996082638062944e-7 0.069999996910041772935e-7 0.079999997737445482926e-7 0.089999998564849192917e-7
NIL
Case 4: I expect to see 1 non-zero digit before the decimal place.
> (dotimes (i 9) (format t "~{~,,,1e ~}~%" (mapcar #'(lambda (x) (* x (expt 10.0 (- (1+ i))))) '(1 2 3 4 5 6 7 8 9))))
1.0000000149011611938e-1 2.0000000298023223877e-1 3.0000001192092895508e-1 4.0000000596046447754e-1 5.e-1 6.0000002384185791016e-1 6.999999880790710449e-1 8.000000119209289551e-1 9.0000003576278686523e-1
0.99999997764825820923e-2 1.9999999552965164185e-2 2.9999999329447746277e-2 0.3999999910593032837e-1 0.4999999701976776123e-1 0.59999998658895492554e-1 0.70000000298023223877e-1 0.7999999821186065674e-1 0.899999961256980896e-1
1.0000000474974513054e-3 0.20000000949949026108e-2 0.30000000260770320892e-2 0.40000001899898052216e-2 0.5000000353902578354e-2 0.60000000521540641785e-2 0.7000000216066837311e-2 0.8000000379979610443e-2 0.90000005438923835754e-2
0.99999997473787516356e-4 1.9999999494757503271e-4 0.29999998514540493488e-3 0.39999998989515006542e-3 0.49999996554106473923e-3 0.59999997029080986977e-3 0.6999999750405550003e-3 0.79999997979030013084e-3 0.8999999845400452614e-3
0.99999997473787516356e-5 1.9999999494757503271e-5 2.9999999242136254907e-5 0.39999998989515006542e-4 0.49999998736893758178e-4 0.59999998484272509813e-4 0.69999994593672454357e-4 0.79999997979030013084e-4 0.9000000136438757181e-4
0.9999999974752427079e-6 0.19999999949504854158e-5 0.30000001061125658453e-5 0.39999999899009708315e-5 0.49999998736893758178e-5 0.60000002122251316905e-5 0.7000000096013536677e-5 0.7999999979801941663e-5 0.9000000318337697536e-5
1.0000000116860974231e-7 2.0000000233721948462e-7 0.30000001061125658453e-6 0.40000000467443896923e-6 0.49999999873762135394e-6 0.60000002122251316905e-6 0.69999998686398612335e-6 0.80000000934887793846e-6 0.9000000318337697536e-6
0.9999999939225290291e-8 1.9999999878450580582e-8 0.29999998929497451172e-7 0.39999999756901161163e-7 0.50000000584304871154e-7 0.59999997858994902344e-7 0.69999998686398612335e-7 0.79999999513802322326e-7 0.90000000341206032317e-7
0.9999999717180685366e-9 0.19999999434361370731e-8 0.29999998041319031472e-8 0.39999998868722741463e-8 0.49999999696126451454e-8 0.59999996082638062944e-8 0.69999996910041772935e-8 0.79999997737445482926e-8 0.89999998564849192917e-8
NIL
Case 5: I expect to see 2 non-zero digits before the decimal place.
> (dotimes (i 9) (format t "~{~,,,2e ~}~%" (mapcar #'(lambda (x) (* x (expt 10.0 (- (1+ i))))) '(1 2 3 4 5 6 7 8 9))))
10.000000149011611938e-2 20.000000298023223877e-2 30.000001192092895508e-2 40.000000596046447754e-2 50.e-2 60.000002384185791016e-2 69.99999880790710449e-2 80.00000119209289551e-2 90.000003576278686523e-2
9.9999997764825820923e-3 19.999999552965164185e-3 29.999999329447746277e-3 3.999999910593032837e-2 4.999999701976776123e-2 5.9999998658895492554e-2 7.0000000298023223877e-2 7.999999821186065674e-2 8.99999961256980896e-2
10.000000474974513054e-4 2.0000000949949026108e-3 3.0000000260770320892e-3 4.0000001899898052216e-3 5.000000353902578354e-3 6.0000000521540641785e-3 7.000000216066837311e-3 8.000000379979610443e-3 9.0000005438923835754e-3
9.9999997473787516356e-5 19.999999494757503271e-5 2.9999998514540493488e-4 3.9999998989515006542e-4 4.9999996554106473923e-4 5.9999997029080986977e-4 6.999999750405550003e-4 7.9999997979030013084e-4 8.999999845400452614e-4
9.9999997473787516356e-6 19.999999494757503271e-6 29.999999242136254907e-6 3.9999998989515006542e-5 4.9999998736893758178e-5 5.9999998484272509813e-5 6.9999994593672454357e-5 7.9999997979030013084e-5 9.000000136438757181e-5
9.999999974752427079e-7 1.9999999949504854158e-6 3.0000001061125658453e-6 3.9999999899009708315e-6 4.9999998736893758178e-6 6.0000002122251316905e-6 7.000000096013536677e-6 7.999999979801941663e-6 9.000000318337697536e-6
10.000000116860974231e-8 20.000000233721948462e-8 3.0000001061125658453e-7 4.0000000467443896923e-7 4.9999999873762135394e-7 6.0000002122251316905e-7 6.9999998686398612335e-7 8.0000000934887793846e-7 9.000000318337697536e-7
9.999999939225290291e-9 19.999999878450580582e-9 2.9999998929497451172e-8 3.9999999756901161163e-8 5.0000000584304871154e-8 5.9999997858994902344e-8 6.9999998686398612335e-8 7.9999999513802322326e-8 9.0000000341206032317e-8
9.999999717180685366e-10 1.9999999434361370731e-9 2.9999998041319031472e-9 3.9999998868722741463e-9 4.9999999696126451454e-9 5.9999996082638062944e-9 6.9999996910041772935e-9 7.9999997737445482926e-9 8.9999998564849192917e-9
NIL
Incidentally, CMUCL output conforms to expectations. I see that ./configure --help
says --with-cmuformat use CMUCL's FORMAT routine (default=YES)
so if that's the case, I wonder why the output is different.
I am working on Linux. uname -a
reports: Linux freekbox 3.13.0-44-generic #73-Ubuntu SMP Tue Dec 16 00:23:46 UTC 2014 i686 i686 i686 GNU/Linux
Ubuntu version is 14.04.
I built ECL from current Git. No options given to configure
. git describe
reports: ECL.8.12.0-4814-g825c8d2
(lisp-implementation-version)
"16.1.3"
(ext:lisp-implementation-vcs-id)`
"UNKNOWN"
(software-type)
(SOFTWARE-TYPE)
(software-version)
"3.13.0-44-generic"
(machine-type)
"i686"
> *features*
(:ECL-BYTECMP :WALKER :CDR-1 :CDR-5 :LINUX :FORMATTER :CDR-7 :ECL-WEAK-HASH
:LITTLE-ENDIAN :ECL-READ-WRITE-LOCK :LONG-LONG :UINT64-T :UINT32-T :UINT16-T
:RELATIVE-PACKAGE-NAMES :LONG-FLOAT :UNICODE :DFFI :CLOS-STREAMS :CMU-FORMAT
:UNIX :ECL-PDE :DLOPEN :CLOS :THREADS :BOEHM-GC :ANSI-CL :COMMON-LISP
:IEEE-FLOATING-POINT :CDR-14 :PREFIXED-API :FFI :I686 :COMMON :ECL)