Thread Links Date Links
Thread Prev Thread Next Thread Index Date Prev Date Next Date Index

Re: Ned's thoughts on P1788 input/output



Ned, P1788

On 2013 Jun 28, at 15:21, Ned Nedialkov wrote:
> ...Here are some thoughts. You may find them a bit  off, but still, wanted to share them.
> 
> (1) interval2text(x, cs)
> 
> What about 
> 
> interval2text(x, formatstring, string1, string2)
            in ^,  in ^ ,        out ^,   out ^
> ...So, if x=[1.12345678e2, 2.12345678e2]
> 
> interval2text(x, "%.4e", string1, string2)
> 
> would return string1 = 1.1234e2, string2 = 2.1235e2
> 
> (2) Thinking further in terms of format strings, what about this idea. 
> 
> In C we have printf, sprintf, scanf, etc. They are all very well established. 
> When reading or writing numbers, they are rounded to the nearest.
> 
> What if we have say printf_i, sprintf_i, scanf_i, etc. 
> Then we can have a modifier in the string format that says round down or round up.
> For example, if [a,b] is an interval, I may write
> 
> printf_i("%fD  %fU", a,b);
> 
> so a is rounded down and b is rounded up.
> ...

I find myself less than enthusiastic for this form of interval2text. Your printf_i, etc., which are at a slightly lower level, look useful.

The key thing of course is to output the bounds rounded in the correct direction. Why I don't like your string1, string2 arguments is that the bounds of x=[a,b] are normally printed together: first a, then b. So separating them is unnatural.

However I agree on the need for a facility to print just the numbers a & b without punctuation, e.g. when writing to a file for later use. 

Hopefully a special form of the conversion specifier cs could do that. In fprintf style, could one use "%[stuff]" as the specifier for intervals? E.g.

  interval2text(x, "%[]")
might give the vanilla output whatever we decide that is.

  interval2text(x, "%[%.4e]")
might output "[1.1234e2, 2.1235e2]" in Ned's example above. (%.4e is used for both bounds.)

  interval2text(x, "%[%.4e, %8.2f]")
might output "[1.1234e2,   212.35]" in Ned's example. (Separate specifiers for the two bounds.)

  interval2text(x, "%#[%.4e]")
with the "alternative form" flag # meaning that the default punctuation is suppressed, so it outputs
   "1.1234e2 2.1235e2"

The "stuff" would consist of a normal fprintf format having 0, 1 or 2 specifiers in it of the A, E, F or G conversion type; other characters in it are user-specified punctuation if cs has "#" before the "["; and would be an error otherwise.

Just a thought of what might be done. 

I do not think 1788 should specify such a scheme at present, UNLESS one of our "reference implementers" wants to write such a scheme quickly, to test it out and offer it for assessment by the group.

Regards

John Pryce