Write float arrays to a text file: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(One intermediate revision by one other user not shown)
Line 1,930:
 
In the final example, we need to force exponential format as numbers of this size would normally be printed in decimal format.
<syntaxhighlight lang="ecmascriptwren">import "io" for File
import "./fmt" for Fmt
 
var x = [1, 2, 3, 1e11]
Line 1,952:
3 1.7321
1e11 3.1623e05
</pre>
 
=={{header|XPL0}}==
Output is redirected to the file like this: writefloat > filename
 
Precision here refers to the size of the numeric field. A precision of 5
means a total of five digits, e.g: 1.2345. XPL0 translates this as one place
before the decimal point and four places after it.
 
<syntaxhighlight lang "XPL0">include xpllib; \for Print
real X, Y;
int N;
[X:= [1., 2., 3., 1e11];
Y:= [1., 1.4142135623730951, 1.7320508075688772, 316227.76601683791];
for N:= 0 to 3 do
Print("%1.2g\t%1.4g\n", X(N), Y(N));
]</syntaxhighlight>
{{out}}
<pre>
1 1
2 1.4142
3 1.7321
1e11 3.1623e5
</pre>
 
9,482

edits