September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,5 +1,5 @@
xprecision = 3
yprecision = 5
x = round([1, 2, 3, 1e11],xprecision)
y = round([1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791],yprecision)
x = round.([1, 2, 3, 1e11],xprecision)
y = round.([1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791],yprecision)
writedlm("filename", [x y], '\t')

View file

@ -0,0 +1,18 @@
// version 1.1.2
import java.io.File
fun main(args: Array<String>) {
val x = doubleArrayOf(1.0, 2.0, 3.0, 1e11)
val y = doubleArrayOf(1.0, 1.4142135623730951, 1.7320508075688772, 316227.76601683791)
val xp = 3
val yp = 5
val f = "%.${xp}g\t%.${yp}g\n"
val writer = File("output.txt").writer()
writer.use {
for (i in 0 until x.size) {
val s = f.format(x[i], y[i])
writer.write(s)
}
}
}

View file

@ -1,21 +0,0 @@
import strutils, math, sequtils
const
outFileName = "floatarr2file.txt"
proc sqrt*(x: int64): float {.importc: "sqrt", header: "<math.h>".}
const
xprecision = 3
yprecision = 5
var a: seq[int64] = @[int64(1), 2, 3, 100_000_000_000]
var b: seq[float] = @[sqrt(a[0]), sqrt(a[1]), sqrt(a[2]), sqrt(a[3])]
var c = zip(a,b)
var res: string = ""
for t in c:
res.add($formatFloat(float(t.a),ffDefault,xprecision) & "\t" & $formatFloat(t.b,ffDefault,yprecision) & "\n")
writeFile(outFileName,res)
var res2 = readFile(outFileName)
echo(res2)

View file

@ -0,0 +1,9 @@
x = [1, 2, 3, 10^11]
y = [1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791]
xprecision = 3
yprecision = 5
> i, 1..4
s1 = #.str(x[i],"g"+xprecision)
s2 = #.str(y[i],"g"+yprecision)
#.writeline("file.txt",s1+#.tab+s2)
<

View file

@ -1,14 +1,14 @@
func writedat(filename, x, y, x_precision=3, y_precision=5) {
var fh = File.new(filename).open_w;
MultiArray.new(x, y).each { |x, y|
fh.printf("%.*g\t%.*g\n", x_precision, x, y_precision, y);
var fh = File(filename).open_w
 
for a,b in (x ~Z y) {
fh.printf("%.*g\t%.*g\n", x_precision, a, y_precision, b)
}
fh.close;
 
fh.close
}
var x = [1, 2, 3, 1e11];
var y = x»sqrt»();
writedat('sqrt.dat', x, y);
 
var x = [1, 2, 3, 1e11]
var y = x.map{.sqrt}
 
writedat('sqrt.dat', x, y)

View file

@ -0,0 +1,10 @@
fcn writeFloatArraysToFile(filename, xs,xprecision, ys,yprecision){
f :=File(filename,"w");
fmt:="%%.%dg\t%%.%dg".fmt(xprecision,yprecision).fmt; // "%.3g\t%.5g".fmt
foreach x,y in (xs.zip(ys)){ f.writeln(fmt(x,y)); }
f.close();
}
xs,ys := T(1.0, 2.0, 3.0, 1e11), xs.apply("sqrt");
xprecision,yprecision := 3,5;
writeFloatArraysToFile("floatArray.txt", xs,xprecision, ys,yprecision);