From
tsmaster@gmail.com@21:1/5 to
All on Thu May 26 09:20:00 2022
This is one of the lines i am trying for format correctly in Orca/C. printf("0\t\t%.9f\t\t%.9f\n",output[0],zero);
Number formatting in C (and its offspring) has a lot going on. One thing to note is that %.9f means to print 9 digits of precision (i.e. digits after the decimal place) - if you're trying to make things line up in a table, you probably want to indicate
the field width, which you could do by just %9f (no period), and if you wanted to combine them: %9.2f for a field with two digits after the decimal, taking up (at least) 9 spaces.
Perhaps you're already familiar with all of that - if so, please forgive the review.
The 9 point float is not aligning when i replace the \t\t with 8 spaces.
If you remove the tabs and it's still not working, my guess is that something else (probably the float layout) is the problem. Can you show us the expected output and the output you're getting?
I have also looked through my APW/C manuals and don't see \t defined there as well.
That's curious - I would expect that \t would be implemented somehow in any C implementation, though possibly inconsistently.
Another thought I have is that maybe the console is ignoring the tab character, and using spaces is what you're expected to do. It's been a long time since I've done any IIgs programming.
-Dave LeCompte
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
From
James Hall@21:1/5 to
All on Thu May 26 23:17:29 2022
Thank you Stephen Heumann, That statement jogs a memory.
Here's the VanillaC source.
printf("\ntype 16 point input vector\n");
scanf("%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",&data[0],&data[1],&data[2],&data[3],&data[4],&data[5],&data[6],&data[7],&data[8],&data[9],&data[10],&data[11],&data[12],&data[13],&data[14],&data[15]);
R16SRFFT(data,output);
printf("\nresult is:\n");
printf("k,\t\tReal Part\t\tImaginary Part\n"); printf("0\t\t%.9f\t\t%.9f\n",output[0],zero); printf("1\t\t%.9f\t\t%.9f\n",output[1],output[9]); printf("2\t\t%.9f\t\t%.9f\n",output[2],output[10]); printf("3\t\t%.9f\t\t%.9f\n",output[3],output[11]); printf("4\t\t%.9f\t\t%.9f\n",output[4],output[12]); printf("5\t\t%.9f\t\t%.9f\n",output[5],output[13]); printf("6\t\t%.9f\t\t%.9f\n",output[6],output[14]); printf("7\t\t%.9f\t\t%.9f\n",output[7],output[15]); printf("8\t\t%.9f\t\t%.9f\n",output[8],zero); printf("9\t\t%.9f\t\t%.9f\n",output[7],-output[15]); printf("10\t\t%.9f\t\t%.9f\n",output[6],-output[14]); printf("11\t\t%.9f\t\t%.9f\n",output[5],-output[13]); printf("12\t\t%.9f\t\t%.9f\n",output[4],-output[12]); printf("13\t\t%.9f\t\t%.9f\n",output[3],-output[11]); printf("14\t\t%.9f\t\t%.9f\n",output[2],-output[9]); printf("15\t\t%.9f\t\t%.9f\n",output[1],-output[8]);
}
Here is what i am expecting for output.
result is:
k, Real Part Imaginary Part
0 -2.749192238 0.000000000
1 1.549032927 1.325549364
2 -0.874582291 1.874609947
3 4.200131416 1.325549364
4 1.000027657 0.000000000
5 4.200131416 -1.325549364
6 -0.874582291 -1.874609947
7 1.549032927 -1.325549364
8 -2.749192238 0.000000000
9 1.549032927 1.325549364
10 -0.874582291 1.874609947
11 4.200131416 1.325549364
12 1.000027657 -0.000000000
13 4.200131416 -1.325549364
14 -0.874582291 -1.325549364
15 1.549032927 2.749192238
Here is what Orca/C gives you.
result is:
k,Real PartImaginary Part
08.00000000000000000000.0000000000000000000 11.0000000000000000000-5.0273394584655761719 20.0000000000000000000-0.0000000000000000000 31.0000000000000000000-1.4966056346893310547 40.00000000000000000000.0000000000000000000 51.0000000000000000000-0.6681787967681884766 60.00000000000000000000.0000000000000000000 70.9999999403953552246-0.1989121437072753906 80.00000000000000000000.0000000000000000000 90.99999994039535522460.1989121437072753906 100.0000000000000000000-0.0000000000000000000 111.00000000000000000000.6681787967681884766 120.0000000000000000000-0.0000000000000000000 131.00000000000000000001.4966056346893310547 140.00000000000000000005.0273394584655761719 151.0000000000000000000-0.0000000000000000000
When you replace the \t with 4 spaces for each occurrence of TAB, the - symbol on negative numbers do not line up.
When you add extra space to line the values up, any change to the input values change the output values and again things do not line up again.
My change, is to the float output from 9 to 19 decimal places. You can see in the Orca/C output the Positive Value Whole Number is where the Negative Symbol shows up when Negative Numbers are the output result. Also you can see that the decimal points do
not line up.
Question: How do i line up the positive and negative first digits as well as the decimal points.
thank you all for the input.
James
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
From
Stephen Heumann@21:1/5 to
James Hall on Fri May 27 21:54:34 2022
On 2022-05-27 19:53:32 +0000, James Hall said:
What keeps coming to mind is; to me it seems the alignment issue is
being generated anytime there is a -Negative number! Is it possible to
force orca/c to generate a +Positive sign in-front of all Positive
Values. Would this resolve it ?
You can force it to generate a + sign for positive numbers by including
the "+" flag in the format specification, e.g. "%+.9f". That should
cause numbers with a magnitude less than 10 to line up when printed.
If you will be dealing with a wider range of magnitudes, you will need
to figure out what part(s) of the numbers you want lined up, since they
would have different numbers of digits before the decimal point. One possibility is to specify that the numbers should be padded with zeros
up to a certain field width, which you can do by including the "0" flag
and an explicit field width in the format specification, e.g.
"%+015.9f". (Very large numbers still won't line up if they have too
many digits before the decimal point, so you will need to pick a field
width that accommodates numbers within the range you intend to use.)
--
Stephen Heumann
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)