Dear All,
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)
formatstring is similar to how format strings are in printf, etc.
The key here, I think, is to settle on a small set of format strings.
string1 and string2 represent the left and right bounds rounded
correctly.
Then the user can do whatever wants with them.
So, if x=[1.12345678e2, 2.12345678e2]
interval2text(x, "%.4e", string1, string2)
would return string1 = 1.1234e2, string2 = 2.1235e2
Then I can read back e.g. with text2interval(string1).
(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 could also write e.g.
printf_i("%dD %dU", a,b)
but now they are printed as integers.
I think this may give the most flexibility, and it is not that
difficult to implement.
I think this approach is really useful, as if I write data into a
file, e.g.
I could do in a loop
fprintf_i(f, "%dD %dU \n", a[i], b[i])
which I can plot with say gnuplot or Matlab. If I need to produce
output for an article I could do
printf_i("[%dD, %dU] \n", a[i], b[i])
If the modifiers down "D" and up "U" are missing, printf_i just calls
the standard printf.
That is, we can have wrappers for the standard C input/output functions.
Of course, similar considerations should apply to any other language.
It could be tricky in C++. If A=[a,b]
then we may need to say what the output of
cout << A << endl;
is.
I would output
[a, b]
where a and b are rounded correctly strings in the default precision.
Ned