Write float arrays to a text file: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added syntax colouring the hard way) |
(Updated to work with Nim 1.4: changed "t.a" to "t[0]" and "t.b" to "t[1]". Replaced tabulation with spaces. Other minor changes.) |
||
Line 1,039: | Line 1,039: | ||
<lang nim>import strutils, math, sequtils |
<lang nim>import strutils, math, sequtils |
||
⚫ | |||
const |
|||
⚫ | |||
const |
const |
||
XPrecision = 3 |
|||
Yprecision = 5 |
|||
let a = [1.0, 2.0, 3.0, 100_000_000_000.0] |
|||
let b = [sqrt(a[0]), sqrt(a[1]), sqrt(a[2]), sqrt(a[3])] |
|||
var |
var res = "" |
||
⚫ | |||
var res: string = "" |
|||
res.add formatFloat(t[0], ffDefault, Xprecision) & " " & |
|||
⚫ | |||
formatFloat(t[1], ffDefault, Yprecision) & "\n" |
|||
writeFile |
OutFileName.writeFile res |
||
var res2 = readFile( |
var res2 = OutFileName.readFile() |
||
echo |
echo res2</lang> |
||
{{out}} |
{{out}} |
||
<pre>1.00 |
<pre>1.00 1.0000 |
||
2.00 |
2.00 1.4142 |
||
3.00 |
3.00 1.7321 |
||
1.00e+11 |
1.00e+11 3.1623e+05</pre> |
||
=={{header|OCaml}}== |
=={{header|OCaml}}== |