Roger Hui wrote:
>> 1. There is no way to request exponential formatting with no fractional
>> digits. In previous releases __ ": 10 would format to 1e1, but in 6.02
>> it is a domain error. (__j.0) doesn't work either.
>
> In x ": y, the complex number x is interpreted as w j. d where
> the real part is w and |w is the width and the imaginary part is d
> and |d is the number of decimal places. When x is __,
> the width is |__ or _, surely an error?
It's an error until you say it's not. It's not meaningful, and it could
be viewed as analogous to _ {. y where _ means 'enough'. It used to
work. And it lets me produce e-format fields with no fractional digits
and just the necessary number of digits used. No fixed number will
work, so can't you put it back the way it was, and let __ mean 'no
fractional digits, but use e-format and use as many digits as needed'?
Unfortunately there is no other way to say this when w and d are both
zero, because we don't have -0.
I think this is an important problem. When I think about how I would
work around the current implementation, I don't see a good way. I could
format with one fractional digit, but then what do I do? I can't round
the fraction off, because I don't know whether .5 should be rounded up
or down (it could have been .49 or .51 before conversion to one decimal
place). And if I try to round before ":, I have to count decimal digits
etc... what a pain when all I want to do is format without a fraction!
>
> I note that (for example),
> _5 ": 12345
> 1e4
> an exponent format with 0 decimal places ("no fractional digits").
>
> Regarding point 0, the dictionary also says that "if w is zero",
> enough space is allocated." And that is what it does:
>
> 0j_5 ": 123 56789
> 1.23000e2 5.67890e4
Surely you're not suggesting that the current implementation conforms to
the DoJ?? "if w is zero, enough space is allocated." OK, but that
"enough" must be sufficient to accommodate the "two fixed spaces on the
left (including one for a possible negative sign)" that we are promised
"if w<0 or d<0". Conforming behavior would be
0j_5 ": 123
1.23000e2
If w is not zero, we get one space, not the two promised:
10j_5 ": 123
1.23000e2
If the DoJ is wrong, OK, but please replace the current clear spec with
one that describes what ": will do.
And please have pity on thy user with __ ": n . Or come up with a
clever replacement.
Henry Rich
>
>
>
> ----- Original Message -----
> From: Henry Rich <[email protected]>
> Date: Wednesday, January 20, 2010 15:41
> Subject: [Jprogramming] ": does not conform to DoJ WAS: problem with e and g
> fields in printf
> To: Programming forum <[email protected]>
>
>> I checked this out to fix it but there are two issues:
>>
>> 0. The 'bug fix' Roger made for 6.01 means that now the
>> code does not
>> conform to the Dictionary, which says (for ":):
>>
>> Otherwise (if w<0 or d<0), the result is put in
>> exponential form (with
>> one digit before the decimal point) and is left-justified except
>> for two
>> fixed spaces on the left (including one for a possible negative sign).
>>
>> The two fixed spaces have been removed.
>>
>> 1. There is no way to request exponential formatting with
>> no fractional
>> digits. In previous releases __ ": 10 would format to 1e1,
>> but in 6.02
>> it is a domain error. (__j.0) doesn't work either.
>>
>> Can this be put back the way it used to work (and
>> documented in DoJ)?
>> Otherwise there is no way to format exponentials with no
>> fraction.
>>
>>
>> I am going leave printf unchanged until this is resolved.
>>
>> Henry Rich
>>
>>
>> Tom Arneson wrote:
>>> Something happened to break the e field specification in
>> sprintf from
>>> printf.ijs
>>>
>>>
>>>
>>> '%0.2e'sprintf 1e_4
>>>
>>> .00e-4
>>>
>>> '%f'sprintf 1e_4
>>>
>>> 0.000100
>>>
>>> '%g'sprintf 1e_4
>>>
>>> 0.000100
>>>
>>> '%e'sprintf 1e_4
>>>
>>> .000000e-4
>>>
>>> '%5.1e'sprintf 1e_4
>>>
>>> .0e-4
>>>
>>>
>>>
>>> The following is from the Test Lines
>>>
>>> ': 5.500000e0:' -: ':%e:' sprintf 5.5
>>>
>>> 0
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm